diff --git a/tools/infer/predict_cls.py b/tools/infer/predict_cls.py index 5c54224e6326e83a5d5cde11df1e3047df140953..f5e358e95e5b1c9a0134c473877f1e53047f09db 100755 --- a/tools/infer/predict_cls.py +++ b/tools/infer/predict_cls.py @@ -100,6 +100,8 @@ class TextClassifier(object): prob_out = self.output_tensors[0].copy_to_cpu() label_out = self.output_tensors[1].copy_to_cpu() + if len(label_out.shape) != 1: + prob_out, label_out = label_out, prob_out elapse = time.time() - starttime predict_time += elapse diff --git a/tools/infer_cls.py b/tools/infer_cls.py index 1f78cdf930fc506cc716d97e8f93c13b407f48d1..aebdc0761b7ec48f81143ecbb758ce0e4da2edf7 100755 --- a/tools/infer_cls.py +++ b/tools/infer_cls.py @@ -19,6 +19,7 @@ from __future__ import print_function import numpy as np import os import sys + __dir__ = os.path.dirname(__file__) sys.path.append(__dir__) sys.path.append(os.path.join(__dir__, '..')) @@ -40,6 +41,7 @@ set_paddle_flags( import tools.program as program from paddle import fluid from ppocr.utils.utility import initial_logger + logger = initial_logger() from ppocr.data.reader_main import reader_main from ppocr.utils.save_load import init_model @@ -87,6 +89,8 @@ def main(): return_numpy=False) scores = np.array(predict[0]) label = np.array(predict[1]) + if len(label.shape) != 1: + label, scores = scores, label logger.info('\t scores: {}'.format(scores)) logger.info('\t label: {}'.format(label)) # save for inference model