Skip to content

Commit 410d90e

Browse files
authored
[latency predictor] Solve the bug of downloading predictors' files (PaddlePaddle#1107)
1 parent 157dcb2 commit 410d90e

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

paddleslim/analysis/_utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919
import paddleslim
2020
import subprocess
2121
import time
22+
import urllib.request as request
23+
import ssl
2224
__all__ = [
2325
"save_cls_model", "save_det_model", "nearest_interpolate", "opt_model",
2426
"load_predictor"
2527
]
2628

29+
PREDICTOR_URL = 'https://paddlemodels.bj.bcebos.com/PaddleSlim/analysis/'
30+
2731

2832
def opt_model(opt="paddle_lite_opt",
2933
model_file='',
@@ -200,9 +204,11 @@ def download_predictor(op_dir, op):
200204

201205
op_path = os.path.join(op_dir, op + '_predictor.pkl')
202206
if not os.path.exists(op_path):
203-
subprocess.call(
204-
f'wget -P {op_dir} https://paddlemodels.bj.bcebos.com/PaddleSlim/analysis/{op_path}',
205-
shell=True)
207+
# NOTE: To solve the 'SSL: certificate verify failed' error.
208+
ssl._create_default_https_context = ssl._create_unverified_context
209+
url = PREDICTOR_URL + op_path
210+
request.urlretrieve(url, op_path)
211+
print('Successfully download {}!'.format(op_path))
206212
return op_path
207213

208214

paddleslim/analysis/latency_predictor.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
import paddle
2525
import paddleslim
2626
import warnings
27+
import urllib.request as request
28+
import ssl
2729
__all__ = ["LatencyPredictor", "TableLatencyPredictor"]
2830

31+
TABLE_URL = 'https://paddlemodels.bj.bcebos.com/PaddleSlim/analysis/'
32+
2933

3034
def format_Warning(message, category, filename, lineno, line=''):
3135
return str(filename) + ':' + str(
@@ -86,10 +90,11 @@ def _initial_table(self):
8690
self.table_file = f'{self.hardware}_threads_4_power_mode_0.pkl'
8791
self.predictor_state = True
8892
if not os.path.exists(self.table_file):
89-
subprocess.call(
90-
f'wget https://paddlemodels.bj.bcebos.com/PaddleSlim/analysis/{self.table_file}',
91-
shell=True)
92-
93+
# NOTE: To solve the 'SSL: certificate verify failed' error.
94+
ssl._create_default_https_context = ssl._create_unverified_context
95+
url = TABLE_URL + self.table_file
96+
request.urlretrieve(url, self.table_file)
97+
print('Successfully download {}!'.format(self.table_file))
9398
assert os.path.exists(
9499
self.table_file
95100
), f'{self.table_file} does not exist. If you want to use our table files, please set \'table_file\' in {TableLatencyPredictor.hardware_list}'

0 commit comments

Comments
 (0)