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 dtype incorrectly being reset #243

Merged
merged 8 commits into from
May 13, 2021
Merged

Fix dtype incorrectly being reset #243

merged 8 commits into from
May 13, 2021

Conversation

SkafteNicki
Copy link
Member

@SkafteNicki SkafteNicki commented May 12, 2021

Before submitting

  • Was this discussed/approved 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?

What does this PR do?

Fixes #187
Currently, if a module is casted to another dtype, say double

c = ConfusionMatrix(num_classes=3).double()

the initial metric states are correctly moved to double dtype. However, since currently is not applied to the _defaults (which contains the values we reset metric states to) after calling reset once the states will be back to whatever dtype they where original initialized with in self.add_state.
This PR fixes this and a bug in relation to this inside ConfusionMatrix that always forces the input to be float (even if asking for double).

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@SkafteNicki SkafteNicki added the bug / fix Something isn't working label May 12, 2021
@SkafteNicki SkafteNicki added this to the v0.4 milestone May 12, 2021
CHANGELOG.md Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 12, 2021

Codecov Report

Merging #243 (47c6fa3) into master (a21eec5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #243   +/-   ##
=======================================
  Coverage   96.82%   96.82%           
=======================================
  Files         184      184           
  Lines        6014     6024   +10     
=======================================
+ Hits         5823     5833   +10     
  Misses        191      191           
Flag Coverage Δ
Linux 78.95% <14.28%> (-0.14%) ⬇️
Windows 78.95% <14.28%> (-0.14%) ⬇️
cpu 96.81% <100.00%> (+<0.01%) ⬆️
gpu 96.84% <ø> (+<0.01%) ⬆️
macOS 96.81% <100.00%> (+<0.01%) ⬆️
pytest 96.82% <100.00%> (+<0.01%) ⬆️
python3.6 95.75% <100.00%> (+<0.01%) ⬆️
python3.8 96.81% <100.00%> (+<0.01%) ⬆️
python3.9 96.71% <100.00%> (+<0.01%) ⬆️
torch1.3.1 95.75% <100.00%> (+<0.01%) ⬆️
torch1.4.0 95.88% <100.00%> (+<0.01%) ⬆️
torch1.8.1 96.71% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...chmetrics/functional/classification/cohen_kappa.py 100.00% <100.00%> (ø)
...rics/functional/classification/confusion_matrix.py 100.00% <100.00%> (ø)
torchmetrics/metric.py 95.56% <100.00%> (+0.06%) ⬆️
...chmetrics/functional/classification/specificity.py
...cs/functional/regression/mean_squared_log_error.py
__w/1/s/torchmetrics/classification/specificity.py
...1/s/torchmetrics/retrieval/mean_reciprocal_rank.py
...rchmetrics/functional/retrieval/reciprocal_rank.py
...trics/functional/regression/mean_relative_error.py
__w/1/s/torchmetrics/classification/cohen_kappa.py
... and 177 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a21eec5...47c6fa3. Read the comment docs.

@Borda Borda enabled auto-merge (squash) May 12, 2021 11:30
@Borda Borda added the ready label May 12, 2021
@Borda Borda merged commit cda5dbd into master May 13, 2021
@Borda Borda deleted the dtype_reset branch May 13, 2021 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Precision Loss in ConfusionMatrix
3 participants