From ab0b4e74744eac3593d8754688c1c144fcadca57 Mon Sep 17 00:00:00 2001 From: andyjpaddle Date: Tue, 2 Aug 2022 11:39:51 +0000 Subject: [PATCH] fix vl infer --- ppocr/data/imaug/rec_img_aug.py | 25 +++++++++++-------------- tools/infer/predict_rec.py | 1 + tools/infer_rec.py | 1 - 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/ppocr/data/imaug/rec_img_aug.py b/ppocr/data/imaug/rec_img_aug.py index ed3026a5..725b4b06 100644 --- a/ppocr/data/imaug/rec_img_aug.py +++ b/ppocr/data/imaug/rec_img_aug.py @@ -219,21 +219,18 @@ class VLRecResizeImg(object): def __call__(self, data): img = data['image'] - if self.infer_mode and self.character_dict_path is not None: - norm_img, valid_ratio = resize_norm_img_chinese(img, - self.image_shape) + + imgC, imgH, imgW = self.image_shape + resized_image = cv2.resize( + img, (imgW, imgH), interpolation=cv2.INTER_LINEAR) + resized_w = imgW + resized_image = resized_image.astype('float32') + if self.image_shape[0] == 1: + resized_image = resized_image / 255 + norm_img = resized_image[np.newaxis, :] else: - imgC, imgH, imgW = self.image_shape - resized_image = cv2.resize( - img, (imgW, imgH), interpolation=cv2.INTER_LINEAR) - resized_w = imgW - resized_image = resized_image.astype('float32') - if self.image_shape[0] == 1: - resized_image = resized_image / 255 - norm_img = resized_image[np.newaxis, :] - else: - norm_img = resized_image.transpose((2, 0, 1)) / 255 - valid_ratio = min(1.0, float(resized_w / imgW)) + norm_img = resized_image.transpose((2, 0, 1)) / 255 + valid_ratio = min(1.0, float(resized_w / imgW)) data['image'] = norm_img data['valid_ratio'] = valid_ratio diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index 911f7511..e1d0d596 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -166,6 +166,7 @@ class TextRecognizer(object): def resize_norm_img_vl(self, img, image_shape): imgC, imgH, imgW = image_shape + img = img[:, :, ::-1] # bgr2rgb resized_image = cv2.resize( img, (imgW, imgH), interpolation=cv2.INTER_LINEAR) resized_image = resized_image.astype('float32') diff --git a/tools/infer_rec.py b/tools/infer_rec.py index a08fa25b..182694e6 100755 --- a/tools/infer_rec.py +++ b/tools/infer_rec.py @@ -131,7 +131,6 @@ def main(): if config['Architecture']['algorithm'] == "SAR": valid_ratio = np.expand_dims(batch[-1], axis=0) img_metas = [paddle.to_tensor(valid_ratio)] - images = np.expand_dims(batch[0], axis=0) images = paddle.to_tensor(images) if config['Architecture']['algorithm'] == "SRN": -- GitLab