提交 ab0b4e74 编写于 作者: A andyjpaddle

fix vl infer

上级 7a706ada
...@@ -219,21 +219,18 @@ class VLRecResizeImg(object): ...@@ -219,21 +219,18 @@ class VLRecResizeImg(object):
def __call__(self, data): def __call__(self, data):
img = data['image'] img = data['image']
if self.infer_mode and self.character_dict_path is not None:
norm_img, valid_ratio = resize_norm_img_chinese(img, imgC, imgH, imgW = self.image_shape
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: else:
imgC, imgH, imgW = self.image_shape norm_img = resized_image.transpose((2, 0, 1)) / 255
resized_image = cv2.resize( valid_ratio = min(1.0, float(resized_w / imgW))
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))
data['image'] = norm_img data['image'] = norm_img
data['valid_ratio'] = valid_ratio data['valid_ratio'] = valid_ratio
......
...@@ -166,6 +166,7 @@ class TextRecognizer(object): ...@@ -166,6 +166,7 @@ class TextRecognizer(object):
def resize_norm_img_vl(self, img, image_shape): def resize_norm_img_vl(self, img, image_shape):
imgC, imgH, imgW = image_shape imgC, imgH, imgW = image_shape
img = img[:, :, ::-1] # bgr2rgb
resized_image = cv2.resize( resized_image = cv2.resize(
img, (imgW, imgH), interpolation=cv2.INTER_LINEAR) img, (imgW, imgH), interpolation=cv2.INTER_LINEAR)
resized_image = resized_image.astype('float32') resized_image = resized_image.astype('float32')
......
...@@ -131,7 +131,6 @@ def main(): ...@@ -131,7 +131,6 @@ def main():
if config['Architecture']['algorithm'] == "SAR": if config['Architecture']['algorithm'] == "SAR":
valid_ratio = np.expand_dims(batch[-1], axis=0) valid_ratio = np.expand_dims(batch[-1], axis=0)
img_metas = [paddle.to_tensor(valid_ratio)] img_metas = [paddle.to_tensor(valid_ratio)]
images = np.expand_dims(batch[0], axis=0) images = np.expand_dims(batch[0], axis=0)
images = paddle.to_tensor(images) images = paddle.to_tensor(images)
if config['Architecture']['algorithm'] == "SRN": if config['Architecture']['algorithm'] == "SRN":
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册