@@ -45,70 +45,28 @@ def round_w_zero_padding(x, bit_width):
4545 "msiou" : py_sod_metrics .MSIoU ,
4646}
4747
48+ # fmt: off
49+ gray_metric_kwargs = dict (with_dynamic = True , with_adaptive = True , with_binary = False , sample_based = True )
50+ binary_metric_kwargs = dict (with_dynamic = False , with_adaptive = False , with_binary = True , sample_based = False )
4851BINARY_METRIC_MAPPING = {
49- "fmeasure" : {
50- "handler" : py_sod_metrics .FmeasureHandler ,
51- "kwargs" : dict (with_dynamic = True , with_adaptive = True , with_binary = False , beta = 0.3 ),
52- },
53- "f1" : {
54- "handler" : py_sod_metrics .FmeasureHandler ,
55- "kwargs" : dict (with_dynamic = False , with_adaptive = True , with_binary = False , beta = 1 ),
56- },
57- "precision" : {
58- "handler" : py_sod_metrics .PrecisionHandler ,
59- "kwargs" : dict (with_dynamic = False , with_adaptive = True , with_binary = False ),
60- },
61- "recall" : {
62- "handler" : py_sod_metrics .RecallHandler ,
63- "kwargs" : dict (with_dynamic = False , with_adaptive = True , with_binary = False ),
64- },
65- "iou" : {
66- "handler" : py_sod_metrics .IOUHandler ,
67- "kwargs" : dict (with_dynamic = True , with_adaptive = True , with_binary = False ),
68- },
69- "dice" : {
70- "handler" : py_sod_metrics .DICEHandler ,
71- "kwargs" : dict (with_dynamic = True , with_adaptive = False , with_binary = False ),
72- },
73- "specificity" : {
74- "handler" : py_sod_metrics .SpecificityHandler ,
75- "kwargs" : dict (with_dynamic = True , with_adaptive = False , with_binary = False ),
76- },
77- "bif1" : {
78- "handler" : py_sod_metrics .FmeasureHandler ,
79- "kwargs" : dict (with_dynamic = False , with_adaptive = False , with_binary = True ,
80- sample_based = False , beta = 1 ),
81- },
82- "biprecision" : {
83- "handler" : py_sod_metrics .PrecisionHandler ,
84- "kwargs" : dict (with_dynamic = False , with_adaptive = False , with_binary = True ,
85- sample_based = False ),
86- },
87- "birecall" : {
88- "handler" : py_sod_metrics .RecallHandler ,
89- "kwargs" : dict (with_dynamic = False , with_adaptive = False , with_binary = True ,
90- sample_based = False ),
91- },
92- "biiou" : {
93- "handler" : py_sod_metrics .IOUHandler ,
94- "kwargs" : dict (with_dynamic = False , with_adaptive = False , with_binary = True ,
95- sample_based = False ),
96- },
97- "bioa" : {
98- "handler" : py_sod_metrics .OverallAccuracyHandler ,
99- "kwargs" : dict (with_dynamic = False , with_adaptive = False , with_binary = True ,
100- sample_based = False ),
101- },
102- "bikappa" : {
103- "handler" : py_sod_metrics .KappaHandler ,
104- "kwargs" : dict (with_dynamic = False , with_adaptive = False , with_binary = True ,
105- sample_based = False ),
106- },
52+ "fmeasure" : {"handler" : py_sod_metrics .FmeasureHandler , "kwargs" : dict (** gray_metric_kwargs , beta = 0.3 )},
53+ "f1" : {"handler" : py_sod_metrics .FmeasureHandler , "kwargs" : dict (** gray_metric_kwargs , beta = 1 )},
54+ "precision" : {"handler" : py_sod_metrics .PrecisionHandler , "kwargs" : gray_metric_kwargs },
55+ "recall" : {"handler" : py_sod_metrics .RecallHandler , "kwargs" : gray_metric_kwargs },
56+ "iou" : {"handler" : py_sod_metrics .IOUHandler , "kwargs" : gray_metric_kwargs },
57+ "dice" : {"handler" : py_sod_metrics .DICEHandler , "kwargs" : gray_metric_kwargs },
58+ "specificity" : {"handler" : py_sod_metrics .SpecificityHandler , "kwargs" : gray_metric_kwargs },
59+ #
60+ "bif1" : {"handler" : py_sod_metrics .FmeasureHandler , "kwargs" : dict (binary_metric_kwargs , beta = 1 )},
61+ "biprecision" : {"handler" : py_sod_metrics .PrecisionHandler , "kwargs" : binary_metric_kwargs },
62+ "birecall" : {"handler" : py_sod_metrics .RecallHandler , "kwargs" : binary_metric_kwargs },
63+ "biiou" : {"handler" : py_sod_metrics .IOUHandler , "kwargs" : binary_metric_kwargs },
64+ "bioa" : {"handler" : py_sod_metrics .OverallAccuracyHandler , "kwargs" : binary_metric_kwargs },
65+ "bikappa" : {"handler" : py_sod_metrics .KappaHandler , "kwargs" : binary_metric_kwargs },
10766}
108-
10967GRAYSCALE_METRICS = ["em" ] + [k for k in BINARY_METRIC_MAPPING .keys () if not k .startswith ("bi" )]
110-
11168SUPPORTED_METRICS = ["mae" , "em" , "sm" , "wfm" , "msiou" ] + sorted (BINARY_METRIC_MAPPING .keys ())
69+ # fmt: off
11270
11371
11472class GrayscaleMetricRecorder :
@@ -203,8 +161,9 @@ def __init__(self, metric_names=("bif1", "biprecision", "birecall", "biiou", "bi
203161 """
204162 if not metric_names :
205163 metric_names = self .suppoted_metrics
206- assert all ([m in self .suppoted_metrics for m in
207- metric_names ]), f"Only support: { self .suppoted_metrics } "
164+ assert all (
165+ [m in self .suppoted_metrics for m in metric_names ]
166+ ), f"Only support: { self .suppoted_metrics } "
208167
209168 self .metric_objs = {"fmeasurev2" : py_sod_metrics .FmeasureV2 ()}
210169 for metric_name in metric_names :
0 commit comments