-
Notifications
You must be signed in to change notification settings - Fork 465
[Draft] add class-wise metrics #2800
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
base: main
Are you sure you want to change the base?
[Draft] add class-wise metrics #2800
Conversation
@@ -180,33 +196,159 @@ def configure_losses(self) -> None: | |||
def configure_metrics(self) -> None: | |||
"""Initialize the performance metrics. | |||
|
|||
* :class:`~torchmetrics.Accuracy`: Overall accuracy | |||
(OA) using 'micro' averaging. The number of true positives divided by the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to be indented for Sphinx to parse the bulleted list correctly
dataset size. Higher values are better. | ||
* :class:`~torchmetrics.JaccardIndex`: Intersection | ||
over union (IoU). Uses 'micro' averaging. Higher valuers are better. | ||
* :class:`~torchmetrics.classification.MulticlassAccuracy`: Overall accuracy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems like going in the wrong direction, shouldn't we keep the generic class links?
expected_classes = 2 if task == 'binary' else num_classes | ||
if len(labels) != expected_classes: | ||
raise ValueError( | ||
f"Length of labels ({len(labels)}) must equal number of classes " | ||
f"({expected_classes}). Either provide {expected_classes} labels or " | ||
f"set labels=None to use default integer names." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently missing test coverage
|
||
# Validate labels length if provided | ||
if labels is not None and task in ['binary', 'multiclass']: | ||
expected_classes = 2 if task == 'binary' else num_classes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the above docs, we say that "labels" is only used for task=multiclass, this disagrees with that
self.test_metrics = metrics.clone(prefix='test_') | ||
|
||
# For binary and multilabel tasks, we only need micro averaging | ||
if task in ['binary', 'multilabel']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole if branch can be replaced with:
for average in ['micro', 'macro']:
# For binary and multilabel tasks, we only need micro averaging
if task in ['binary', 'multilabel'] and average == 'macro':
continue
...
Then we don't have to duplicate.
) | ||
|
||
# Add classwise metrics for binary and multiclass (not multilabel) | ||
if task in ['binary', 'multiclass'] and labels is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we combine this too, something like:
for average in ['micro', 'macro', 'global']:
metric = ...
if average == 'global':
metric = ClasswiseWrapper(metric)
...
Replaces #2130
Adds support for
labels
to be used inClasswiseWrapper