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

[Refactor] Refactor single and multi label metrics #81

Merged
merged 7 commits into from
Mar 9, 2023

Conversation

yingfhu
Copy link
Collaborator

@yingfhu yingfhu commented Jan 17, 2023

Refactor of SingleLabelMetric and MultiLabelMetric

Motivation

The class name is not apparent for user to know its function.

Modification

  1. Rename those metrics to SingleLabelPrecsionRecallF1score and MultiLabelPrecsionRecallF1score
  2. Add a wrapper PrecsionRecallF1score with an extra task argument for direct usage to create different instance.

Use cases (Optional)

>>> import torch
>>> preds  = torch.tensor([2, 0, 1, 1])
>>> labels = torch.tensor([2, 1, 2, 0])
>>> metric = PrecsionRecallF1score(num_classes=3)
>>> metric(preds, labels)
{'precision': 33.3333, 'recall': 16.6667, 'f1-score': 22.2222}
>>> metric = PrecsionRecallF1score(
        task="multilabel", average='micro', num_classes=3)
>>> metric(preds, labels)
{'precision_micro': 25.0, 'recall_micro': 25.0, 'f1-score_micro': 25.0}

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Jan 17, 2023

CLA assistant check
All committers have signed the CLA.

@yingfhu yingfhu changed the title refactor single and multi label metrics [Refactor]refactor single and multi label metrics Jan 17, 2023
@yingfhu yingfhu changed the title [Refactor]refactor single and multi label metrics [Refactor] Refactor single and multi label metrics Jan 17, 2023
Copy link
Collaborator

@C1rN09 C1rN09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally good! Please also modify the api docs && support_matrix documentation.

mmeval/metrics/average_precision.py Outdated Show resolved Hide resolved
mmeval/metrics/average_precision.py Outdated Show resolved Hide resolved
mmeval/metrics/average_precision.py Show resolved Hide resolved
mmeval/metrics/precision_recall_f1score.py Outdated Show resolved Hide resolved
mmeval/metrics/utils/multi_label.py Outdated Show resolved Hide resolved
tests/test_metrics/test_precision_recall_f1score.py Outdated Show resolved Hide resolved
mmeval/metrics/average_precision.py Outdated Show resolved Hide resolved
mmeval/metrics/utils/multi_label.py Outdated Show resolved Hide resolved
@yingfhu yingfhu requested a review from C1rN09 February 17, 2023 07:43
@yingfhu yingfhu requested a review from C1rN09 February 20, 2023 03:34
Copy link
Collaborator

@C1rN09 C1rN09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with 1 comments!

mmeval/metrics/utils/multi_label.py Show resolved Hide resolved
@zhouzaida zhouzaida merged commit 2cae388 into open-mmlab:main Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants