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

Calculate text color of ConfusionMatrix plot based on luminance #2590

Merged
merged 8 commits into from
Jun 9, 2024

Conversation

relativityhd
Copy link
Contributor

@relativityhd relativityhd commented Jun 5, 2024

What does this PR do?

This will make the text-color of the ConfusionMatrix heatmap-plots white for darker-patches and white for brighter ones.
I haven't opened an Issue for this, since it is a non-intrusive and small change.

Before submitting
  • Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?
PR review

Assume the following Code:

import torchmetrics
import torch
pred = torch.tensor([0, 1, 2, 3, 4])
target = torch.tensor([0, 1, 2, 2, 2])
cnf = torchmetrics.ConfusionMatrix(task="multiclass", num_classes=5)
cnf.update(pred, target)
cnf.plot(cmap="Blues")

Results now in the following plot:

grafik

This is how it looked before:
grafik

Did you have fun?

Make sure you had fun coding 🙃


📚 Documentation preview 📚: https://torchmetrics--2590.org.readthedocs.build/en/2590/

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 11.11111% with 8 lines in your changes missing coverage. Please review.

Project coverage is 69%. Comparing base (27a301a) to head (812c932).
Report is 94 commits behind head on master.

Additional details and impacted files
@@          Coverage Diff           @@
##           master   #2590   +/-   ##
======================================
- Coverage      69%     69%   -0%     
======================================
  Files         314     314           
  Lines       17702   17709    +7     
======================================
+ Hits        12199   12200    +1     
- Misses       5503    5509    +6     

@mergify mergify bot added the ready label Jun 6, 2024
@SkafteNicki SkafteNicki enabled auto-merge (squash) June 6, 2024 11:21
auto-merge was automatically disabled June 6, 2024 13:21

Head branch was pushed to by a user without write access

@relativityhd relativityhd requested a review from lantiga as a code owner June 6, 2024 13:21
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jun 6, 2024
@Borda Borda merged commit 91b9e39 into Lightning-AI:master Jun 9, 2024
61 checks passed
Borda pushed a commit that referenced this pull request Aug 2, 2024
* Calculate text color of ConfusionMatrix plot based on luminance
* Update Changelog
* Update plot_example image for Readme

---------

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>
(cherry picked from commit 91b9e39)
Borda pushed a commit that referenced this pull request Aug 2, 2024
* Calculate text color of ConfusionMatrix plot based on luminance
* Update Changelog
* Update plot_example image for Readme

---------

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>
(cherry picked from commit 91b9e39)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants