From ff947d8960fef3ba8e01bb41d52fe961f1c68e91 Mon Sep 17 00:00:00 2001 From: xiaoting <31891223+tink2123@users.noreply.github.com> Date: Tue, 10 Jan 2023 10:48:42 +0800 Subject: [PATCH] fix onnx for dynamic shape (#8812) --- tools/infer/predict_det.py | 4 +++- tools/infer/predict_rec.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/infer/predict_det.py b/tools/infer/predict_det.py index 1b4446a6..6c5c36cf 100755 --- a/tools/infer/predict_det.py +++ b/tools/infer/predict_det.py @@ -143,7 +143,9 @@ class TextDetector(object): 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: + if isinstance(img_h, str) or isinstance(img_w, str): + pass + elif img_h is not None and img_w is not None and img_h > 0 and img_w > 0: pre_process_list[0] = { 'DetResizeForTest': { 'image_shape': [img_h, img_w] diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index b3ef557c..d3231545 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -173,9 +173,10 @@ class TextRecognizer(object): imgW = int((imgH * max_wh_ratio)) if self.use_onnx: w = self.input_tensor.shape[3:][0] - if w is not None and w > 0: + if isinstance(w, str): + pass + elif w is not None and w > 0: imgW = w - h, w = img.shape[:2] ratio = w / float(h) if math.ceil(imgH * ratio) > imgW: -- GitLab