-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,43 @@ | ||
""" Test the TBEvaluator class.""" | ||
import pytest | ||
|
||
import torch | ||
from topobenchmark.evaluator import TBEvaluator | ||
|
||
class TestTBEvaluator: | ||
""" Test the TBXEvaluator class.""" | ||
|
||
def setup_method(self): | ||
""" Setup the test.""" | ||
self.evaluator_multilable = TBEvaluator(task="multilabel classification") | ||
self.evaluator_regression = TBEvaluator(task="regression") | ||
self.classification_metrics = ["accuracy", "precision", "recall", "auroc"] | ||
self.evaluator_classification = TBEvaluator(task="classification", num_classes=3, metrics=self.classification_metrics) | ||
self.evaluator_multilabel = TBEvaluator(task="multilabel classification", num_classes=2, metrics=self.classification_metrics) | ||
self.regression_metrics = ["example", "mae"] | ||
self.evaluator_regression = TBEvaluator(task="regression", num_classes=1, metrics=self.regression_metrics) | ||
with pytest.raises(ValueError): | ||
TBEvaluator(task="wrong") | ||
repr = self.evaluator_multilable.__repr__() | ||
TBEvaluator(task="wrong", num_classes=2, metrics=self.classification_metrics) | ||
|
||
def test_repr(self): | ||
"""Test the __repr__ method.""" | ||
assert "TBEvaluator" in self.evaluator_classification.__repr__() | ||
assert "TBEvaluator" in self.evaluator_multilabel.__repr__() | ||
assert "TBEvaluator" in self.evaluator_regression.__repr__() | ||
|
||
def test_update_and_compute(self): | ||
"""Test the update and compute methods.""" | ||
self.evaluator_classification.update({"logits": torch.randn(10, 3), "labels": torch.randint(0, 3, (10,))}) | ||
out = self.evaluator_classification.compute() | ||
for metric in self.classification_metrics: | ||
assert metric in out | ||
self.evaluator_multilabel.update({"logits": torch.randn(10, 2), "labels": torch.randint(0, 2, (10, 2))}) | ||
out = self.evaluator_multilabel.compute() | ||
for metric in self.classification_metrics: | ||
assert metric in out | ||
self.evaluator_regression.update({"logits": torch.randn(10, 1), "labels": torch.randn(10,)}) | ||
out = self.evaluator_regression.compute() | ||
for metric in self.regression_metrics: | ||
assert metric in out | ||
|
||
def test_reset(self): | ||
"""Test the reset method.""" | ||
self.evaluator_multilabel.reset() | ||
self.evaluator_regression.reset() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters