From a1cc920a36c713b3bf411752f16fd738dc545269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E6=B6=AF=E5=8F=A4=E5=B7=B7?= Date: Thu, 14 Oct 2021 17:14:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E4=B8=8BIndexError=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/infer/predict_rec.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index 332cffd5..6c6e5bf5 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -13,6 +13,7 @@ # limitations under the License. import os import sys +import threading from PIL import Image __dir__ = os.path.dirname(os.path.abspath(__file__)) sys.path.append(__dir__) @@ -37,6 +38,7 @@ logger = get_logger() class TextRecognizer(object): def __init__(self, args): + self.lock = threading.RLock() self.rec_image_shape = [int(v) for v in args.rec_image_shape.split(",")] self.character_type = args.rec_char_type self.rec_batch_num = args.rec_batch_num @@ -195,6 +197,7 @@ class TextRecognizer(object): gsrm_slf_attn_bias2) def __call__(self, img_list): + self.lock.acquire() img_num = len(img_list) # Calculate the aspect ratio of all text bars width_list = [] @@ -284,6 +287,7 @@ class TextRecognizer(object): rec_res[indices[beg_img_no + rno]] = rec_result[rno] if self.benchmark: self.autolog.times.end(stamp=True) + self.lock.release() return rec_res, time.time() - st -- GitLab