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

Incorrect PSNR for uint8 images #2787

Closed
ymtoo opened this issue Oct 18, 2024 · 1 comment · Fixed by #2788
Closed

Incorrect PSNR for uint8 images #2787

ymtoo opened this issue Oct 18, 2024 · 1 comment · Fixed by #2788
Labels
bug / fix Something isn't working help wanted Extra attention is needed v1.4.x

Comments

@ymtoo
Copy link

ymtoo commented Oct 18, 2024

🐛 Bug

PeakSignalNoiseRatio silently produces incorrect results when applied to two randomly generated uint8 images, likely due to an overflow error. However, converting the images to float32 resolves the issue and yields a reasonable PSNR value.

import torch
from torchmetrics.image import PeakSignalNoiseRatio

img1 = (torch.rand(3, 20, 30) * 255).to(torch.uint8)
img2 = (torch.rand(3, 20, 30) * 255).to(torch.uint8)
psnr = PeakSignalNoiseRatio(data_range=255.0)

psnr(img1, img2)
# tensor(27.8814)
psnr(img1.to(torch.float), img2.to(torch.float))
# tensor(7.8037)

Expected behavior

Shouldn't the function raise an error when provided with uint8 inputs?

Environment

python                    3.10.14
torchmetrics              1.4.1
torchvision               0.19.0
@ymtoo ymtoo added bug / fix Something isn't working help wanted Extra attention is needed labels Oct 18, 2024
Copy link

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

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 v1.4.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants