未验证 提交 410d90ef 编写于 作者: Z zhouzj 提交者: GitHub

[latency predictor] Solve the bug of downloading predictors' files (#1107)

上级 157dcb21
......@@ -19,11 +19,15 @@ import paddle
import paddleslim
import subprocess
import time
import urllib.request as request
import ssl
__all__ = [
"save_cls_model", "save_det_model", "nearest_interpolate", "opt_model",
"load_predictor"
]
PREDICTOR_URL = 'https://paddlemodels.bj.bcebos.com/PaddleSlim/analysis/'
def opt_model(opt="paddle_lite_opt",
model_file='',
......@@ -200,9 +204,11 @@ def download_predictor(op_dir, op):
op_path = os.path.join(op_dir, op + '_predictor.pkl')
if not os.path.exists(op_path):
subprocess.call(
f'wget -P {op_dir} https://paddlemodels.bj.bcebos.com/PaddleSlim/analysis/{op_path}',
shell=True)
# NOTE: To solve the 'SSL: certificate verify failed' error.
ssl._create_default_https_context = ssl._create_unverified_context
url = PREDICTOR_URL + op_path
request.urlretrieve(url, op_path)
print('Successfully download {}!'.format(op_path))
return op_path
......
......@@ -24,8 +24,12 @@ from ._utils import opt_model, load_predictor, nearest_interpolate
import paddle
import paddleslim
import warnings
import urllib.request as request
import ssl
__all__ = ["LatencyPredictor", "TableLatencyPredictor"]
TABLE_URL = 'https://paddlemodels.bj.bcebos.com/PaddleSlim/analysis/'
def format_Warning(message, category, filename, lineno, line=''):
return str(filename) + ':' + str(
......@@ -86,10 +90,11 @@ class TableLatencyPredictor(LatencyPredictor):
self.table_file = f'{self.hardware}_threads_4_power_mode_0.pkl'
self.predictor_state = True
if not os.path.exists(self.table_file):
subprocess.call(
f'wget https://paddlemodels.bj.bcebos.com/PaddleSlim/analysis/{self.table_file}',
shell=True)
# NOTE: To solve the 'SSL: certificate verify failed' error.
ssl._create_default_https_context = ssl._create_unverified_context
url = TABLE_URL + self.table_file
request.urlretrieve(url, self.table_file)
print('Successfully download {}!'.format(self.table_file))
assert os.path.exists(
self.table_file
), f'{self.table_file} does not exist. If you want to use our table files, please set \'table_file\' in {TableLatencyPredictor.hardware_list}'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册