提交 809a56cb 编写于 作者: qq_25193841's avatar qq_25193841

Merge remote-tracking branch 'upstream/dygraph' into dygraph

...@@ -18,8 +18,8 @@ python3.7 -m pip install paddle2onnx ...@@ -18,8 +18,8 @@ python3.7 -m pip install paddle2onnx
- 安装 ONNX - 安装 ONNX
``` ```
# 建议安装 1.4.0 版本,可根据环境更换版本号 # 建议安装 1.9.0 版本,可根据环境更换版本号
python3.7 -m pip install onnxruntime==1.4.0 python3.7 -m pip install onnxruntime==1.9.0
``` ```
## 2. 模型转换 ## 2. 模型转换
...@@ -47,13 +47,15 @@ paddle2onnx --model_dir=./inference/ch_ppocr_mobile_v2.0_det_infer/ \ ...@@ -47,13 +47,15 @@ paddle2onnx --model_dir=./inference/ch_ppocr_mobile_v2.0_det_infer/ \
--params_filename=inference.pdiparams \ --params_filename=inference.pdiparams \
--save_file=./inference/det_mobile_onnx/model.onnx \ --save_file=./inference/det_mobile_onnx/model.onnx \
--opset_version=10 \ --opset_version=10 \
--input_shape_dict="{'x': [-1, 3, -1, -1]}" \
--enable_onnx_checker=True --enable_onnx_checker=True
``` ```
执行完毕后,ONNX 模型会被保存在 `./inference/det_mobile_onnx/` 路径下 执行完毕后,ONNX 模型会被保存在 `./inference/det_mobile_onnx/` 路径下
* 注意:以下几个模型暂不支持转换为 ONNX 模型: * 注意:对于OCR模型,转化过程中必须采用动态shape的形式,即加入选项--input_shape_dict="{'x': [-1, 3, -1, -1]}",否则预测结果可能与直接使用Paddle预测有细微不同。
NRTR、SAR、RARE、SRN 另外,以下几个模型暂不支持转换为 ONNX 模型:
NRTR、SAR、RARE、SRN
## 3. onnx 预测 ## 3. onnx 预测
...@@ -72,5 +74,3 @@ root INFO: 1.jpg [[[291, 295], [334, 292], [348, 844], [305, 847]], [[344, 296] ...@@ -72,5 +74,3 @@ root INFO: 1.jpg [[[291, 295], [334, 292], [348, 844], [305, 847]], [[344, 296]
The predict time of ../../doc/imgs/1.jpg: 0.06162881851196289 The predict time of ../../doc/imgs/1.jpg: 0.06162881851196289
The visualized image saved in ./inference_results/det_res_1.jpg The visualized image saved in ./inference_results/det_res_1.jpg
``` ```
* 注意:ONNX暂时不支持变长预测,需要将输入resize到固定输入,预测结果可能与直接使用Paddle预测有细微不同。
...@@ -344,7 +344,7 @@ class KieLabelEncode(object): ...@@ -344,7 +344,7 @@ class KieLabelEncode(object):
max_num = 300 max_num = 300
temp_bboxes = np.zeros([max_num, 4]) temp_bboxes = np.zeros([max_num, 4])
h, _ = bboxes.shape h, _ = bboxes.shape
temp_bboxes[:h, :h] = bboxes temp_bboxes[:h, :] = bboxes
temp_relations = np.zeros([max_num, max_num, 5]) temp_relations = np.zeros([max_num, max_num, 5])
temp_relations[:h, :h, :] = relations temp_relations[:h, :h, :] = relations
......
...@@ -101,16 +101,21 @@ class TextDetector(object): ...@@ -101,16 +101,21 @@ class TextDetector(object):
else: else:
logger.info("unknown det_algorithm:{}".format(self.det_algorithm)) logger.info("unknown det_algorithm:{}".format(self.det_algorithm))
sys.exit(0) sys.exit(0)
self.preprocess_op = create_operators(pre_process_list)
self.postprocess_op = build_post_process(postprocess_params)
self.predictor, self.input_tensor, self.output_tensors, self.config = utility.create_predictor(
args, 'det', logger)
if self.use_onnx: if self.use_onnx:
img_h, img_w = self.input_tensor.shape[2:]
if img_h is not None and img_w is not None and img_h > 0 and img_w > 0:
pre_process_list[0] = { pre_process_list[0] = {
'DetResizeForTest': { 'DetResizeForTest': {
'image_shape': [640, 640] 'image_shape': [img_h, img_w]
} }
} }
self.preprocess_op = create_operators(pre_process_list) self.preprocess_op = create_operators(pre_process_list)
self.postprocess_op = build_post_process(postprocess_params)
self.predictor, self.input_tensor, self.output_tensors, self.config = utility.create_predictor(
args, 'det', logger)
if args.benchmark: if args.benchmark:
import auto_log import auto_log
......
...@@ -109,7 +109,10 @@ class TextRecognizer(object): ...@@ -109,7 +109,10 @@ class TextRecognizer(object):
assert imgC == img.shape[2] assert imgC == img.shape[2]
imgW = int((32 * max_wh_ratio)) imgW = int((32 * max_wh_ratio))
if self.use_onnx: if self.use_onnx:
imgW = 100 w = self.input_tensor.shape[3:][0]
if w is not None and w > 0:
imgW = w
h, w = img.shape[:2] h, w = img.shape[:2]
ratio = w / float(h) ratio = w / float(h)
if math.ceil(imgH * ratio) > imgW: if math.ceil(imgH * ratio) > imgW:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册