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

ClasswiseWrapper yields different results #1128

Closed
patrickFuerst opened this issue Jul 6, 2022 · 1 comment · Fixed by #1129
Closed

ClasswiseWrapper yields different results #1128

patrickFuerst opened this issue Jul 6, 2022 · 1 comment · Fixed by #1129
Labels
bug / fix Something isn't working help wanted Extra attention is needed
Milestone

Comments

@patrickFuerst
Copy link

🐛 Bug

Using JaccardIndex with ClasswiseWrapper results in different values than without ClasswiseWrapper.

To Reproduce

Steps to reproduce the behavior...

Run the code snippet.

Code sample

from torchmetrics import ClasswiseWrapper, JaccardIndex
import torch 

target = torch.randint(0, 2, (10, 25, 25))
preds = [ torch.randint(0, 2, (10, 25, 25)) for i in range (3)]
jaccard_single = JaccardIndex(num_classes=2, average=None)
class_wrapper = ClasswiseWrapper(
        JaccardIndex(num_classes=2, average=None),
        labels=["class1", "class2"]
    )

for p in preds:
    print("Metric ",jaccard_single(p,target))    
    print("Wraped metric ",class_wrapper(p,target))

The code produces the following output:

Metric  tensor([0.3351, 0.3333])
Wraped metric  {'jaccardindex_class1': tensor(0.3351), 'jaccardindex_class2': tensor(0.3333)}
Metric  tensor([0.3293, 0.3357])
Wraped metric  {'jaccardindex_class1': tensor(0.3322), 'jaccardindex_class2': tensor(0.3345)}
Metric  tensor([0.3424, 0.3435])
Wraped metric  {'jaccardindex_class1': tensor(0.3356), 'jaccardindex_class2': tensor(0.3375)}

Expected behavior

I would expect that the wrapped metric outputs the same values as the simple JaccardIndex.

Environment

  • TorchMetrics version (and how you installed TM, e.g. conda, pip, build from source):
    Installed version 0.9.2 using pip
  • Python & PyTorch Version (e.g., 1.0):
    Tested with Python 3.8.14 and pytorch 1.3.1
  • Any other relevant information such as OS (e.g., Linux):

Additional context

@patrickFuerst patrickFuerst added bug / fix Something isn't working help wanted Extra attention is needed labels Jul 6, 2022
@github-actions
Copy link

github-actions bot commented Jul 6, 2022

Hi! thanks for your contribution!, great first issue!

@patrickFuerst patrickFuerst changed the title ClasswiseWrapper yield different results ClasswiseWrapper yields different results Jul 6, 2022
@SkafteNicki SkafteNicki added this to the v0.9 milestone Jul 7, 2022
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 help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants