From cd2fb63edc340f903e268143e12ba0b5d5e2d9b8 Mon Sep 17 00:00:00 2001 From: KevinNuNu Date: Mon, 27 Feb 2023 23:06:36 +0800 Subject: [PATCH 1/3] [Fix] fix np.arange() output not stable error --- docs/en/basic_concepts/evaluation.md | 4 ++-- docs/zh_cn/basic_concepts/evaluation.md | 4 ++-- mmocr/evaluation/metrics/hmean_iou_metric.py | 12 +++++++++--- .../ABCNet/abcnet/metric/e2e_hmean_iou_metric.py | 12 +++++++++--- projects/SPTS/spts/metric/e2e_point_metric.py | 8 +++++++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/docs/en/basic_concepts/evaluation.md b/docs/en/basic_concepts/evaluation.md index ef477e967..e78750b2d 100644 --- a/docs/en/basic_concepts/evaluation.md +++ b/docs/en/basic_concepts/evaluation.md @@ -60,8 +60,8 @@ In MMOCR, the calculation of `HmeanIOUMetric` can be summarized as the following It is worth noting that `pred_score_thrs` will **automatically search** for the **best threshold** within a certain range by default, and users can also customize the search range by manually modifying the configuration file: ```python - # By default, HmeanIOUMetric searches the best threshold within the range [0.3, 0.9] with a step size of 0.1 - val_evaluator = dict(type='HmeanIOUMetric', pred_score_thrs=dict(start=0.3, stop=0.9, step=0.1)) + # By default, HmeanIOUMetric searches the best threshold within the range [0.3, 1) with a step size of 0.1 + val_evaluator = dict(type='HmeanIOUMetric', pred_score_thrs=dict(start=0.3, stop=1, step=0.1)) ``` 2. Calculate the IoU matrix diff --git a/docs/zh_cn/basic_concepts/evaluation.md b/docs/zh_cn/basic_concepts/evaluation.md index 15eab4dae..ab6848b4c 100644 --- a/docs/zh_cn/basic_concepts/evaluation.md +++ b/docs/zh_cn/basic_concepts/evaluation.md @@ -60,8 +60,8 @@ F_1=(1+\beta^2)\cdot\frac{PR}{\beta^2\cdot P+R} = \frac{2PR}{P+R} 值得注意的是,`pred_score_thrs` 默认将**自动搜索**一定范围内的**最佳阈值**,用户也可以通过手动修改配置文件来自定义搜索范围: ```python - # HmeanIOUMetric 默认以 0.1 为步长搜索 [0.3, 0.9] 范围内的最佳得分阈值 - val_evaluator = dict(type='HmeanIOUMetric', pred_score_thrs=dict(start=0.3, stop=0.9, step=0.1)) + # HmeanIOUMetric 默认以 0.1 为步长搜索 [0.3, 1) 范围内的最佳得分阈值 + val_evaluator = dict(type='HmeanIOUMetric', pred_score_thrs=dict(start=0.3, stop=1, step=0.1)) ``` 2. 计算 IoU 矩阵 diff --git a/mmocr/evaluation/metrics/hmean_iou_metric.py b/mmocr/evaluation/metrics/hmean_iou_metric.py index c5d40971c..eed013bde 100644 --- a/mmocr/evaluation/metrics/hmean_iou_metric.py +++ b/mmocr/evaluation/metrics/hmean_iou_metric.py @@ -44,7 +44,7 @@ class HmeanIOUMetric(BaseMetric): ignore_precision_thr (float): Precision threshold when prediction and\ gt ignored polygons are matched. Defaults to 0.5. pred_score_thrs (dict): Best prediction score threshold searching - space. Defaults to dict(start=0.3, stop=0.9, step=0.1). + space. Defaults to dict(start=0.3, stop=1 step=0.1). strategy (str): Polygon matching strategy. Options are 'max_matching' and 'vanilla'. 'max_matching' refers to the optimum strategy that maximizes the number of matches. Vanilla strategy matches gt and @@ -63,14 +63,20 @@ class HmeanIOUMetric(BaseMetric): def __init__(self, match_iou_thr: float = 0.5, ignore_precision_thr: float = 0.5, - pred_score_thrs: Dict = dict(start=0.3, stop=0.9, step=0.1), + pred_score_thrs: Dict = dict(start=0.3, stop=1, step=0.1), strategy: str = 'vanilla', collect_device: str = 'cpu', prefix: Optional[str] = None) -> None: super().__init__(collect_device=collect_device, prefix=prefix) self.match_iou_thr = match_iou_thr self.ignore_precision_thr = ignore_precision_thr - self.pred_score_thrs = np.arange(**pred_score_thrs) + self.pred_score_thrs = np.linspace( + pred_score_thrs['start'], + pred_score_thrs['stop'], + int( + np.round((pred_score_thrs['stop'] - pred_score_thrs['start']) / + pred_score_thrs['step'])), + endpoint=False) assert strategy in ['max_matching', 'vanilla'] self.strategy = strategy diff --git a/projects/ABCNet/abcnet/metric/e2e_hmean_iou_metric.py b/projects/ABCNet/abcnet/metric/e2e_hmean_iou_metric.py index bdab4375e..8f75b34b6 100644 --- a/projects/ABCNet/abcnet/metric/e2e_hmean_iou_metric.py +++ b/projects/ABCNet/abcnet/metric/e2e_hmean_iou_metric.py @@ -45,7 +45,7 @@ class E2EHmeanIOUMetric(BaseMetric): ignore_precision_thr (float): Precision threshold when prediction and\ gt ignored polygons are matched. Defaults to 0.5. pred_score_thrs (dict): Best prediction score threshold searching - space. Defaults to dict(start=0.3, stop=0.9, step=0.1). + space. Defaults to dict(start=0.3, stop=1, step=0.1). strategy (str): Polygon matching strategy. Options are 'max_matching' and 'vanilla'. 'max_matching' refers to the optimum strategy that maximizes the number of matches. Vanilla strategy matches gt and @@ -64,7 +64,7 @@ class E2EHmeanIOUMetric(BaseMetric): def __init__(self, match_iou_thr: float = 0.5, ignore_precision_thr: float = 0.5, - pred_score_thrs: Dict = dict(start=0.3, stop=0.9, step=0.1), + pred_score_thrs: Dict = dict(start=0.3, stop=1, step=0.1), lexicon_path: Optional[str] = None, word_spotting: bool = False, min_length_case_word: int = 3, @@ -75,7 +75,13 @@ def __init__(self, super().__init__(collect_device=collect_device, prefix=prefix) self.match_iou_thr = match_iou_thr self.ignore_precision_thr = ignore_precision_thr - self.pred_score_thrs = np.arange(**pred_score_thrs) + self.pred_score_thrs = np.linspace( + pred_score_thrs['start'], + pred_score_thrs['stop'], + int( + np.round((pred_score_thrs['stop'] - pred_score_thrs['start']) / + pred_score_thrs['step'])), + endpoint=False) self.word_spotting = word_spotting self.min_length_case_word = min_length_case_word self.special_characters = special_characters diff --git a/projects/SPTS/spts/metric/e2e_point_metric.py b/projects/SPTS/spts/metric/e2e_point_metric.py index 7a44bbf85..c0159285d 100644 --- a/projects/SPTS/spts/metric/e2e_point_metric.py +++ b/projects/SPTS/spts/metric/e2e_point_metric.py @@ -34,7 +34,13 @@ def __init__(self, collect_device: str = 'cpu', prefix: Optional[str] = None) -> None: super().__init__(collect_device=collect_device, prefix=prefix) - self.text_score_thrs = np.arange(**text_score_thrs) + self.text_score_thrs = np.linspace( + text_score_thrs['start'], + text_score_thrs['stop'], + int( + np.round((text_score_thrs['stop'] - text_score_thrs['start']) / + text_score_thrs['step'])), + endpoint=False) self.word_spotting = word_spotting def poly_center(self, poly_pts): From 7eeb94d2daa1926d02035842ca3ebdd09ba33648 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Mon, 10 Apr 2023 13:18:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BD=BF=E7=94=A8np.aran?= =?UTF-8?q?ge=E5=87=BD=E6=95=B0=E5=8F=AF=E8=83=BD=E4=BC=9A=E4=B8=8D?= =?UTF-8?q?=E5=8C=85=E5=90=ABstop=E5=80=BC=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/basic_concepts/evaluation.md | 4 ++-- docs/zh_cn/basic_concepts/evaluation.md | 4 ++-- mmocr/evaluation/metrics/hmean_iou_metric.py | 8 ++++---- projects/ABCNet/abcnet/metric/e2e_hmean_iou_metric.py | 8 ++++---- projects/SPTS/spts/metric/e2e_point_metric.py | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/en/basic_concepts/evaluation.md b/docs/en/basic_concepts/evaluation.md index e78750b2d..ef477e967 100644 --- a/docs/en/basic_concepts/evaluation.md +++ b/docs/en/basic_concepts/evaluation.md @@ -60,8 +60,8 @@ In MMOCR, the calculation of `HmeanIOUMetric` can be summarized as the following It is worth noting that `pred_score_thrs` will **automatically search** for the **best threshold** within a certain range by default, and users can also customize the search range by manually modifying the configuration file: ```python - # By default, HmeanIOUMetric searches the best threshold within the range [0.3, 1) with a step size of 0.1 - val_evaluator = dict(type='HmeanIOUMetric', pred_score_thrs=dict(start=0.3, stop=1, step=0.1)) + # By default, HmeanIOUMetric searches the best threshold within the range [0.3, 0.9] with a step size of 0.1 + val_evaluator = dict(type='HmeanIOUMetric', pred_score_thrs=dict(start=0.3, stop=0.9, step=0.1)) ``` 2. Calculate the IoU matrix diff --git a/docs/zh_cn/basic_concepts/evaluation.md b/docs/zh_cn/basic_concepts/evaluation.md index ab6848b4c..15eab4dae 100644 --- a/docs/zh_cn/basic_concepts/evaluation.md +++ b/docs/zh_cn/basic_concepts/evaluation.md @@ -60,8 +60,8 @@ F_1=(1+\beta^2)\cdot\frac{PR}{\beta^2\cdot P+R} = \frac{2PR}{P+R} 值得注意的是,`pred_score_thrs` 默认将**自动搜索**一定范围内的**最佳阈值**,用户也可以通过手动修改配置文件来自定义搜索范围: ```python - # HmeanIOUMetric 默认以 0.1 为步长搜索 [0.3, 1) 范围内的最佳得分阈值 - val_evaluator = dict(type='HmeanIOUMetric', pred_score_thrs=dict(start=0.3, stop=1, step=0.1)) + # HmeanIOUMetric 默认以 0.1 为步长搜索 [0.3, 0.9] 范围内的最佳得分阈值 + val_evaluator = dict(type='HmeanIOUMetric', pred_score_thrs=dict(start=0.3, stop=0.9, step=0.1)) ``` 2. 计算 IoU 矩阵 diff --git a/mmocr/evaluation/metrics/hmean_iou_metric.py b/mmocr/evaluation/metrics/hmean_iou_metric.py index eed013bde..64fee2b73 100644 --- a/mmocr/evaluation/metrics/hmean_iou_metric.py +++ b/mmocr/evaluation/metrics/hmean_iou_metric.py @@ -44,7 +44,7 @@ class HmeanIOUMetric(BaseMetric): ignore_precision_thr (float): Precision threshold when prediction and\ gt ignored polygons are matched. Defaults to 0.5. pred_score_thrs (dict): Best prediction score threshold searching - space. Defaults to dict(start=0.3, stop=1 step=0.1). + space. Defaults to dict(start=0.3, stop=0.9 step=0.1). strategy (str): Polygon matching strategy. Options are 'max_matching' and 'vanilla'. 'max_matching' refers to the optimum strategy that maximizes the number of matches. Vanilla strategy matches gt and @@ -63,7 +63,7 @@ class HmeanIOUMetric(BaseMetric): def __init__(self, match_iou_thr: float = 0.5, ignore_precision_thr: float = 0.5, - pred_score_thrs: Dict = dict(start=0.3, stop=1, step=0.1), + pred_score_thrs: Dict = dict(start=0.3, stop=0.9, step=0.1), strategy: str = 'vanilla', collect_device: str = 'cpu', prefix: Optional[str] = None) -> None: @@ -75,8 +75,8 @@ def __init__(self, pred_score_thrs['stop'], int( np.round((pred_score_thrs['stop'] - pred_score_thrs['start']) / - pred_score_thrs['step'])), - endpoint=False) + pred_score_thrs['step'])) + 1, + endpoint=True) assert strategy in ['max_matching', 'vanilla'] self.strategy = strategy diff --git a/projects/ABCNet/abcnet/metric/e2e_hmean_iou_metric.py b/projects/ABCNet/abcnet/metric/e2e_hmean_iou_metric.py index 8f75b34b6..22e00eac8 100644 --- a/projects/ABCNet/abcnet/metric/e2e_hmean_iou_metric.py +++ b/projects/ABCNet/abcnet/metric/e2e_hmean_iou_metric.py @@ -45,7 +45,7 @@ class E2EHmeanIOUMetric(BaseMetric): ignore_precision_thr (float): Precision threshold when prediction and\ gt ignored polygons are matched. Defaults to 0.5. pred_score_thrs (dict): Best prediction score threshold searching - space. Defaults to dict(start=0.3, stop=1, step=0.1). + space. Defaults to dict(start=0.3, stop=0.9, step=0.1). strategy (str): Polygon matching strategy. Options are 'max_matching' and 'vanilla'. 'max_matching' refers to the optimum strategy that maximizes the number of matches. Vanilla strategy matches gt and @@ -64,7 +64,7 @@ class E2EHmeanIOUMetric(BaseMetric): def __init__(self, match_iou_thr: float = 0.5, ignore_precision_thr: float = 0.5, - pred_score_thrs: Dict = dict(start=0.3, stop=1, step=0.1), + pred_score_thrs: Dict = dict(start=0.3, stop=0.9, step=0.1), lexicon_path: Optional[str] = None, word_spotting: bool = False, min_length_case_word: int = 3, @@ -80,8 +80,8 @@ def __init__(self, pred_score_thrs['stop'], int( np.round((pred_score_thrs['stop'] - pred_score_thrs['start']) / - pred_score_thrs['step'])), - endpoint=False) + pred_score_thrs['step'])) + 1, + endpoint=True) self.word_spotting = word_spotting self.min_length_case_word = min_length_case_word self.special_characters = special_characters diff --git a/projects/SPTS/spts/metric/e2e_point_metric.py b/projects/SPTS/spts/metric/e2e_point_metric.py index 977ca7fa3..6aaa6fc8c 100644 --- a/projects/SPTS/spts/metric/e2e_point_metric.py +++ b/projects/SPTS/spts/metric/e2e_point_metric.py @@ -63,8 +63,8 @@ def __init__(self, text_score_thrs['stop'], int( np.round((text_score_thrs['stop'] - text_score_thrs['start']) / - text_score_thrs['step'])), - endpoint=False) + text_score_thrs['step'])) + 1, + endpoint=True) self.word_spotting = word_spotting self.match_dist_thr = match_dist_thr if lexicon_path: From b30ff88fdb0fcf38bd2af6798070b82f022dd0fb Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Fri, 7 Jul 2023 15:30:19 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E6=BC=8F=E4=BA=86=E4=B8=AA,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mmocr/evaluation/metrics/hmean_iou_metric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmocr/evaluation/metrics/hmean_iou_metric.py b/mmocr/evaluation/metrics/hmean_iou_metric.py index 64fee2b73..d389992e1 100644 --- a/mmocr/evaluation/metrics/hmean_iou_metric.py +++ b/mmocr/evaluation/metrics/hmean_iou_metric.py @@ -44,7 +44,7 @@ class HmeanIOUMetric(BaseMetric): ignore_precision_thr (float): Precision threshold when prediction and\ gt ignored polygons are matched. Defaults to 0.5. pred_score_thrs (dict): Best prediction score threshold searching - space. Defaults to dict(start=0.3, stop=0.9 step=0.1). + space. Defaults to dict(start=0.3, stop=0.9, step=0.1). strategy (str): Polygon matching strategy. Options are 'max_matching' and 'vanilla'. 'max_matching' refers to the optimum strategy that maximizes the number of matches. Vanilla strategy matches gt and