mirror of
https://github.com/open-mmlab/mmocr.git
synced 2025-06-03 21:54:47 +08:00
[Enhancement] Simplify normalized edit distance calculation (#1060)
* simplify normalized edit distance calculation * update rapidfuzz minimum version
This commit is contained in:
parent
d3f65aaacf
commit
7c5c784a94
@ -2,7 +2,7 @@
|
|||||||
import re
|
import re
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
|
|
||||||
from rapidfuzz import string_metric
|
from rapidfuzz.distance import Levenshtein
|
||||||
|
|
||||||
from mmocr.utils import is_type_list
|
from mmocr.utils import is_type_list
|
||||||
|
|
||||||
@ -63,12 +63,8 @@ def count_matches(pred_texts, gt_texts):
|
|||||||
match_res['match_word_ignore_case_symbol'] += 1
|
match_res['match_word_ignore_case_symbol'] += 1
|
||||||
match_res['gt_word_num'] += 1
|
match_res['gt_word_num'] += 1
|
||||||
|
|
||||||
# normalized edit distance
|
norm_ed_sum += Levenshtein.normalized_distance(pred_text_lower_ignore,
|
||||||
edit_dist = string_metric.levenshtein(pred_text_lower_ignore,
|
gt_text_lower_ignore)
|
||||||
gt_text_lower_ignore)
|
|
||||||
norm_ed = float(edit_dist) / max(1, len(gt_text_lower_ignore),
|
|
||||||
len(pred_text_lower_ignore))
|
|
||||||
norm_ed_sum += norm_ed
|
|
||||||
|
|
||||||
# number to calculate char level recall & precision
|
# number to calculate char level recall & precision
|
||||||
match_res['gt_char_num'] += len(gt_text_lower_ignore)
|
match_res['gt_char_num'] += len(gt_text_lower_ignore)
|
||||||
|
@ -6,7 +6,7 @@ matplotlib
|
|||||||
mmcv
|
mmcv
|
||||||
mmdet
|
mmdet
|
||||||
pyclipper
|
pyclipper
|
||||||
rapidfuzz
|
rapidfuzz>=2.0.0
|
||||||
regex
|
regex
|
||||||
scikit-image
|
scikit-image
|
||||||
scipy
|
scipy
|
||||||
|
@ -6,5 +6,5 @@ numpy
|
|||||||
opencv-python != 4.5.5.*
|
opencv-python != 4.5.5.*
|
||||||
pyclipper
|
pyclipper
|
||||||
pycocotools
|
pycocotools
|
||||||
rapidfuzz
|
rapidfuzz>=2.0.0
|
||||||
scikit-image
|
scikit-image
|
||||||
|
Loading…
x
Reference in New Issue
Block a user