Skip to content

Commit 2baff66

Browse files
committed
Add overall accuracy and kappa.
1 parent b228260 commit 2baff66

File tree

4 files changed

+330
-180
lines changed

4 files changed

+330
-180
lines changed

examples/metric_recorder.py

Lines changed: 43 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -104,72 +104,53 @@ def get_results(self, num_bits: int = 3, return_ndarray: bool = False) -> dict:
104104
return {"sequential": sequential_results, "numerical": numerical_results}
105105

106106

107+
sample_gray = dict(with_adaptive=True, with_dynamic=True)
108+
sample_bin = dict(with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True)
109+
overall_bin = dict(with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=False)
107110
BINARY_CLASSIFICATION_METRIC_MAPPING = {
108111
# 灰度数据指标
109-
"fm": py_sod_metrics.FmeasureHandler(with_adaptive=True, with_dynamic=True, beta=0.3),
110-
"f1": py_sod_metrics.FmeasureHandler(with_adaptive=True, with_dynamic=True, beta=0.1),
111-
"pre": py_sod_metrics.PrecisionHandler(with_adaptive=True, with_dynamic=True),
112-
"rec": py_sod_metrics.RecallHandler(with_adaptive=True, with_dynamic=True),
113-
"iou": py_sod_metrics.IOUHandler(with_adaptive=True, with_dynamic=True),
114-
"dice": py_sod_metrics.DICEHandler(with_adaptive=True, with_dynamic=True),
115-
"spec": py_sod_metrics.SpecificityHandler(with_adaptive=True, with_dynamic=True),
116-
"ber": py_sod_metrics.BERHandler(with_adaptive=True, with_dynamic=True),
112+
"fm": py_sod_metrics.FmeasureHandler(**sample_gray, beta=0.3),
113+
"f1": py_sod_metrics.FmeasureHandler(**sample_gray, beta=0.1),
114+
"pre": py_sod_metrics.PrecisionHandler(**sample_gray),
115+
"rec": py_sod_metrics.RecallHandler(**sample_gray),
116+
"iou": py_sod_metrics.IOUHandler(**sample_gray),
117+
"dice": py_sod_metrics.DICEHandler(**sample_gray),
118+
"spec": py_sod_metrics.SpecificityHandler(**sample_gray),
119+
"ber": py_sod_metrics.BERHandler(**sample_gray),
120+
"oa": py_sod_metrics.OverallAccuracyHandler(**sample_gray),
121+
"kappa": py_sod_metrics.KappaHandler(**sample_gray),
117122
# 二值化数据指标的特殊情况一:各个样本独立计算指标后取平均
118-
"sample_bifm": py_sod_metrics.FmeasureHandler(
119-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True, beta=0.3
120-
),
121-
"sample_bif1": py_sod_metrics.FmeasureHandler(
122-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True, beta=1
123-
),
124-
"sample_bipre": py_sod_metrics.PrecisionHandler(
125-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
126-
),
127-
"sample_birec": py_sod_metrics.RecallHandler(
128-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
129-
),
130-
"sample_biiou": py_sod_metrics.IOUHandler(
131-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
132-
),
133-
"sample_bidice": py_sod_metrics.DICEHandler(
134-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
135-
),
136-
"sample_bispec": py_sod_metrics.SpecificityHandler(
137-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
138-
),
139-
"sample_biber": py_sod_metrics.BERHandler(
140-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
141-
),
123+
"sample_bifm": py_sod_metrics.FmeasureHandler(**sample_bin, beta=0.3),
124+
"sample_bif1": py_sod_metrics.FmeasureHandler(**sample_bin, beta=1),
125+
"sample_bipre": py_sod_metrics.PrecisionHandler(**sample_bin),
126+
"sample_birec": py_sod_metrics.RecallHandler(**sample_bin),
127+
"sample_biiou": py_sod_metrics.IOUHandler(**sample_bin),
128+
"sample_bidice": py_sod_metrics.DICEHandler(**sample_bin),
129+
"sample_bispec": py_sod_metrics.SpecificityHandler(**sample_bin),
130+
"sample_biber": py_sod_metrics.BERHandler(**sample_bin),
131+
"sample_bioa": py_sod_metrics.OverallAccuracyHandler(**sample_bin),
132+
"sample_bikappa": py_sod_metrics.KappaHandler(**sample_bin),
142133
# 二值化数据指标的特殊情况二:汇总所有样本的tp、fp、tn、fn后整体计算指标
143-
"overall_bifm": py_sod_metrics.FmeasureHandler(
144-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True, beta=0.3
145-
),
146-
"overall_bif1": py_sod_metrics.FmeasureHandler(
147-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True, beta=1
148-
),
149-
"overall_bipre": py_sod_metrics.PrecisionHandler(
150-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
151-
),
152-
"overall_birec": py_sod_metrics.RecallHandler(
153-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
154-
),
155-
"overall_biiou": py_sod_metrics.IOUHandler(
156-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
157-
),
158-
"overall_bidice": py_sod_metrics.DICEHandler(
159-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
160-
),
161-
"overall_bispec": py_sod_metrics.SpecificityHandler(
162-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
163-
),
164-
"overall_biber": py_sod_metrics.BERHandler(
165-
with_adaptive=False, with_dynamic=False, with_binary=True, sample_based=True
166-
),
134+
"overall_bifm": py_sod_metrics.FmeasureHandler(**overall_bin, beta=0.3),
135+
"overall_bif1": py_sod_metrics.FmeasureHandler(**overall_bin, beta=1),
136+
"overall_bipre": py_sod_metrics.PrecisionHandler(**overall_bin),
137+
"overall_birec": py_sod_metrics.RecallHandler(**overall_bin),
138+
"overall_biiou": py_sod_metrics.IOUHandler(**overall_bin),
139+
"overall_bidice": py_sod_metrics.DICEHandler(**overall_bin),
140+
"overall_bispec": py_sod_metrics.SpecificityHandler(**overall_bin),
141+
"overall_biber": py_sod_metrics.BERHandler(**overall_bin),
142+
"overall_bioa": py_sod_metrics.OverallAccuracyHandler(**overall_bin),
143+
"overall_bikappa": py_sod_metrics.KappaHandler(**overall_bin),
167144
}
168145

169146

170147
class MetricRecorderV2:
171148
suppoted_metrics = ["mae", "em", "sm", "wfm"] + sorted(
172-
[k for k in BINARY_CLASSIFICATION_METRIC_MAPPING.keys() if not k.startswith(('sample_', 'overall_'))]
149+
[
150+
k
151+
for k in BINARY_CLASSIFICATION_METRIC_MAPPING.keys()
152+
if not k.startswith(("sample_", "overall_"))
153+
]
173154
)
174155

175156
def __init__(self, metric_names=("sm", "wfm", "mae", "fmeasure", "em")):
@@ -248,7 +229,11 @@ def show(self, num_bits: int = 3, return_ndarray: bool = False) -> dict:
248229

249230
class BinaryMetricRecorder:
250231
suppoted_metrics = ["mae", "sm", "wfm"] + sorted(
251-
[k for k in BINARY_CLASSIFICATION_METRIC_MAPPING.keys() if k.startswith(('sample_', 'overall_'))]
232+
[
233+
k
234+
for k in BINARY_CLASSIFICATION_METRIC_MAPPING.keys()
235+
if k.startswith(("sample_", "overall_"))
236+
]
252237
)
253238

254239
def __init__(self, metric_names=("bif1", "biprecision", "birecall", "biiou")):

0 commit comments

Comments
 (0)