From 902fffcc7ea7b18479c1ad3e3ac23cb90ef09cbc Mon Sep 17 00:00:00 2001 From: andyjpaddle Date: Wed, 22 Sep 2021 02:46:02 +0000 Subject: [PATCH] fix slice in sar head --- ppocr/modeling/heads/rec_sar_head.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ppocr/modeling/heads/rec_sar_head.py b/ppocr/modeling/heads/rec_sar_head.py index 647f5820..7107788d 100644 --- a/ppocr/modeling/heads/rec_sar_head.py +++ b/ppocr/modeling/heads/rec_sar_head.py @@ -235,7 +235,8 @@ class ParallelSARDecoder(BaseDecoder): # cal mask of attention weight for i, valid_ratio in enumerate(valid_ratios): valid_width = min(w, math.ceil(w * valid_ratio)) - attn_weight[i, :, :, valid_width:, :] = float('-inf') + if valid_width < w: + attn_weight[i, :, :, valid_width:, :] = float('-inf') attn_weight = paddle.reshape(attn_weight, [bsz, T, -1]) attn_weight = F.softmax(attn_weight, axis=-1) -- GitLab