未验证 提交 8b656a3e 编写于 作者: D Double_V 提交者: GitHub

Merge pull request #4332 from YaoFANGUK/release/2.3

修复多线程调用下IndexError报错
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import os import os
import sys import sys
import threading
from PIL import Image from PIL import Image
__dir__ = os.path.dirname(os.path.abspath(__file__)) __dir__ = os.path.dirname(os.path.abspath(__file__))
sys.path.append(__dir__) sys.path.append(__dir__)
...@@ -37,6 +38,7 @@ logger = get_logger() ...@@ -37,6 +38,7 @@ logger = get_logger()
class TextRecognizer(object): class TextRecognizer(object):
def __init__(self, args): def __init__(self, args):
self.lock = threading.RLock()
self.rec_image_shape = [int(v) for v in args.rec_image_shape.split(",")] self.rec_image_shape = [int(v) for v in args.rec_image_shape.split(",")]
self.character_type = args.rec_char_type self.character_type = args.rec_char_type
self.rec_batch_num = args.rec_batch_num self.rec_batch_num = args.rec_batch_num
...@@ -195,6 +197,7 @@ class TextRecognizer(object): ...@@ -195,6 +197,7 @@ class TextRecognizer(object):
gsrm_slf_attn_bias2) gsrm_slf_attn_bias2)
def __call__(self, img_list): def __call__(self, img_list):
self.lock.acquire()
img_num = len(img_list) img_num = len(img_list)
# Calculate the aspect ratio of all text bars # Calculate the aspect ratio of all text bars
width_list = [] width_list = []
...@@ -284,6 +287,7 @@ class TextRecognizer(object): ...@@ -284,6 +287,7 @@ class TextRecognizer(object):
rec_res[indices[beg_img_no + rno]] = rec_result[rno] rec_res[indices[beg_img_no + rno]] = rec_result[rno]
if self.benchmark: if self.benchmark:
self.autolog.times.end(stamp=True) self.autolog.times.end(stamp=True)
self.lock.release()
return rec_res, time.time() - st return rec_res, time.time() - st
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册