Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type hints #1472

Merged
merged 5 commits into from Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/torchmetrics/wrappers/tracker.py
Expand Up @@ -134,7 +134,7 @@ def compute(self) -> Any:
self._check_for_increment("compute")
return self[-1].compute()

def compute_all(self) -> Tensor:
def compute_all(self) -> Union[Tensor, Dict[str, Tensor]]:
"""Compute the metric value for all tracked metrics."""
SkafteNicki marked this conversation as resolved.
Show resolved Hide resolved
self._check_for_increment("compute_all")
# The i!=0 accounts for the self._base_metric should be ignored
Expand All @@ -158,10 +158,10 @@ def best_metric(
) -> Union[
None,
float,
Tuple[int, float],
Tuple[float, int],
Tuple[None, None],
Dict[str, Union[float, None]],
Tuple[Dict[str, Union[int, None]], Dict[str, Union[float, None]]],
Tuple[Dict[str, Union[float, None]], Dict[str, Union[int, None]]],
]:
"""Returns the highest metric out of all tracked.
SkafteNicki marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/wrappers/test_tracker.py
Expand Up @@ -170,7 +170,7 @@ def test_best_metric_for_not_well_defined_metric_collection(base_metric):
assert best is None

with pytest.warns(UserWarning, match="Encountered the following error when trying to get the best metric.*"):
idx, best = tracker.best_metric(return_step=True)
best, idx = tracker.best_metric(return_step=True)

if isinstance(best, dict):
assert best["MulticlassAccuracy"] is not None
Expand Down