From c6c28785b183cb4c57be30c3d0214a2d6b87910d Mon Sep 17 00:00:00 2001 From: tink2123 Date: Fri, 16 Oct 2020 14:09:32 +0800 Subject: [PATCH] fix max_wh_ratio for predict --- tools/infer/predict_rec.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index 7c942255..77dc82aa 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -60,12 +60,12 @@ class TextRecognizer(object): self.loss_type = 'srn' self.char_ops = CharacterOps(char_ops_params) - def resize_norm_img(self, img, wh_ratio): + def resize_norm_img(self, img, max_wh_ratio): imgC, imgH, imgW = self.rec_image_shape assert imgC == img.shape[2] - max_wh_ration = max(wh_ratio, imgW * 1.0 / imgH) + wh_ratio = max(max_wh_ratio, imgW * 1.0 / imgH) if self.character_type == "ch": - imgW = int((32 * max_wh_ratio)) + imgW = int((32 * wh_ratio)) h, w = img.shape[:2] ratio = w / float(h) if math.ceil(imgH * ratio) > imgW: @@ -174,14 +174,16 @@ class TextRecognizer(object): for beg_img_no in range(0, img_num, batch_num): end_img_no = min(img_num, beg_img_no + batch_num) norm_img_batch = [] + max_wh_ratio = 0 for ino in range(beg_img_no, end_img_no): # h, w = img_list[ino].shape[0:2] h, w = img_list[indices[ino]].shape[0:2] wh_ratio = w * 1.0 / h + max_wh_ratio = max(max_wh_ratio, wh_ratio) for ino in range(beg_img_no, end_img_no): if self.loss_type != "srn": norm_img = self.resize_norm_img(img_list[indices[ino]], - wh_ratio) + max_wh_ratio) norm_img = norm_img[np.newaxis, :] norm_img_batch.append(norm_img) else: -- GitLab