Skip to content

Commit

Permalink
Merge branch 'layoutlm' of https://github.com/KevinNuNu/mmocr into la…
Browse files Browse the repository at this point in the history
…youtlm
  • Loading branch information
KevinNuNu committed May 29, 2023
2 parents b6f55f8 + 551086e commit a65b34f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions projects/LayoutLMv3/models/ser_postprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,40 @@ def __call__(self, outputs: torch.Tensor,
pred_label_ids = max_idx.numpy().tolist()
pred_label_scores = max_value.numpy().tolist()

# inference process do not have item in gt_label,
# so select valid token with word_ids rather than
# with gt_label_ids like official code.
pred_words_biolabels = []
word_biolabels = []
pre_word_id = None
for idx, cur_word_id in enumerate(word_ids):
if cur_word_id is not None:
if cur_word_id != pre_word_id:
if word_biolabels:
pred_words_biolabels.append(word_biolabels)
word_biolabels = []
word_biolabels.append((self.id2biolabel[pred_label_ids[idx]],
pred_label_scores[idx]))
else:
pred_words_biolabels.append(word_biolabels)
break
pre_word_id = cur_word_id
# record pred_label
if self.only_label_first_subword:
pred_label = LabelData()
pred_label.item = [
pred_word_biolabels[0][0]
for pred_word_biolabels in pred_words_biolabels
]
pred_label.score = [
pred_word_biolabels[0][1]
for pred_word_biolabels in pred_words_biolabels
]
merged_data_sample.pred_label = pred_label
else:
raise NotImplementedError(
'The `only_label_first_subword=False` is not support yet.')

# inference process do not have item in gt_label,
# so select valid token with word_ids rather than
# with gt_label_ids like official code.
Expand Down

0 comments on commit a65b34f

Please sign in to comment.