Skip to content

Commit

Permalink
Add unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
harimkang committed Sep 4, 2024
1 parent ed18cbe commit f1e395a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/unit/core/metrics/test_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
HlabelAccuracy,
MixedHLabelAccuracy,
MulticlassAccuracywithLabelGroup,
MultiClassClsMetricCallable,
MultilabelAccuracywithLabelGroup,
)
from otx.core.types.label import HLabelInfo, LabelInfo
from torchmetrics.classification.accuracy import BinaryAccuracy, MulticlassAccuracy


class TestAccuracy:
Expand Down Expand Up @@ -45,6 +47,16 @@ def test_multiclass_accuracy(self, fxt_multiclass_labelinfo: LabelInfo) -> None:
acc = result["accuracy"]
assert round(acc.item(), 3) == 0.792

def test_default_multi_class_cls_metric_callable(self, fxt_multiclass_labelinfo: LabelInfo) -> None:
assert fxt_multiclass_labelinfo.num_classes > 1
metric = MultiClassClsMetricCallable(fxt_multiclass_labelinfo)
assert isinstance(metric.accuracy, MulticlassAccuracy)

one_class_label_info = LabelInfo(label_names=["class1"], label_groups=[["class1"]])
assert one_class_label_info.num_classes == 1
binary_metric = MultiClassClsMetricCallable(one_class_label_info)
assert isinstance(binary_metric.accuracy, BinaryAccuracy)

def test_multilabel_accuracy(self, fxt_multilabel_labelinfo: LabelInfo) -> None:
"""Check whether accuracy is same with OTX1.x version."""
preds = [
Expand Down

0 comments on commit f1e395a

Please sign in to comment.