Skip to content

Commit

Permalink
[LatencyPredictor] Add some ops for ocr and tinypose. (PaddlePaddle#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzjjay authored Feb 16, 2022
1 parent f89fc93 commit 0706349
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 86 deletions.
8 changes: 4 additions & 4 deletions docs/zh_cn/tutorials/analysis/dygraph/latency_predictor.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ tar -xf mobilenetv1.tar
### 2.2 预估推理延时
构造 TableLatencyPredictor 类实例,并调用 predict 函数预估推理模型的延时。
```
import paddleslim
from paddleslim.analysis import TableLatencyPredictor
predictor = paddleslim.TableLatencyPredictor(table_file='SD710')
predictor = TableLatencyPredictor(table_file='SD710')
latency = predictor.predict(model_file='mobilenetv1_fp32.pdmodel', param_file='mobilenetv1_fp32.pdiparams, data_type='fp32')
print('predicted latency = {}ms'.format(latency))
```
Expand All @@ -58,9 +58,9 @@ print('predicted latency = {}ms'.format(latency))
### 3.2 支持预估 INT8 模型
延时预估器支持对 INT8 量化模型进行延时预估,仅需提供 INT8 量化保存的推理模型文件,并将在调用 predict 函数时,设置 data_type='int8',如下所示:
```
import paddleslim
from paddleslim.analysis import TableLatencyPredictor
predictor = paddleslim.TableLatencyPredictor(table_file='SD710')
predictor = TableLatencyPredictor(table_file='SD710')
predictor.predict(model_file='mobilenetv1_int8.pdmodel', param_file='mobilenetv1_int8.pdiparams, data_type='int8')
```

Expand Down
10 changes: 5 additions & 5 deletions paddleslim/analysis/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def opt_model(opt="paddle_lite_opt",
optimize_out_type='protobuf',
valid_targets='arm'):
assert os.path.exists(model_file) and os.path.exists(
param_file), f'{model_file} or {param_file} is not existed.'
param_file), f'{model_file} or {param_file} does not exist.'
save_dir = f'./opt_models_tmp/{os.getpid()}'
if not os.path.exists(save_dir):
os.makedirs(save_dir)
Expand Down Expand Up @@ -225,11 +225,11 @@ def distance(x, y):
return latency[idx]


def dowload_predictor(op_dir, op):
"""Dowload op predictors' model file
def download_predictor(op_dir, op):
"""Download op predictors' model file
Args:
op_dir(str): the dowload path of op predictor. Actually, it's the hardware information.
op_dir(str): the path to op predictor. Actually, it's the hardware information.
op(str): the op type.
Returns:
op_path: The path of the file.
Expand All @@ -252,7 +252,7 @@ def load_predictor(op_type, op_dir, data_type='fp32'):
elif 'matmul' in op_type:
op = 'matmul'

op_path = dowload_predictor(op_dir, op)
op_path = download_predictor(op_dir, op)
with open(op_path, 'rb') as f:
model = pickle.load(f)

Expand Down
Loading

0 comments on commit 0706349

Please sign in to comment.