Merge pull request #4332 from YaoFANGUK/release/2.3

修复多线程调用下IndexError报错
pull/4917/head
Double_V 2021-12-10 10:20:26 +08:00 committed by GitHub
commit 8b656a3e13
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