修复多线程调用下IndexError报错

pull/4332/head
天涯古巷 2021-10-14 17:14:29 +08:00 committed by GitHub
parent e7b9822b13
commit a1cc920a36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -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