-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liukuikun
committed
Sep 22, 2022
1 parent
93d883e
commit 0a19442
Showing
9 changed files
with
178 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
mmocr/models/textrecog/recognizers/encoder_decoder_recognizer_tta.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
from typing import List | ||
|
||
from mmengine.model import BaseTTAModel | ||
|
||
from mmocr.registry import MODELS | ||
from mmocr.utils.typing import RecSampleList | ||
|
||
|
||
@MODELS.register_module() | ||
class EncoderDecoderRecognizerTTAModel(BaseTTAModel): | ||
|
||
def merge_preds(self, | ||
data_samples_list: List[RecSampleList]) -> RecSampleList: | ||
"""Merge predictions of enhanced data to one prediction. | ||
Args: | ||
data_samples_list (List[RecSampleList]): List of predictions of | ||
all enhanced data. | ||
Returns: | ||
RecSampleList: Merged prediction. | ||
""" | ||
predictions = [None] * len(data_samples_list[0]) | ||
average_scores = [-1] * len(data_samples_list[0]) | ||
for data_samples in data_samples_list: | ||
for i, data_sample in enumerate(data_samples): | ||
score = data_sample.pred_text.score | ||
average_score = sum(score) / max(1, len(score)) | ||
if average_score > average_scores[i]: | ||
predictions[i] = data_sample | ||
average_scores[i] = average_score | ||
return predictions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters