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

learned_perceptual_image_patch_similarity function needs to synchronize device and dtype between net and input images #2232

Closed
michael080808 opened this issue Nov 22, 2023 · 0 comments · Fixed by #2234
Labels
bug / fix Something isn't working help wanted Extra attention is needed v1.2.x

Comments

@michael080808
Copy link

michael080808 commented Nov 22, 2023

🐛 Bug

When I try to use preds and target on torch.device('cuda:0') to calculate with function learned_perceptual_image_patch_similarity from torchmetrics.functional.image, the function will throw exception.

Maybe there are some other functions with internal torch.nn.Module instances in torchmetrics.functional will proceed like this.

To Reproduce

import torch
from torchmetrics.functional.image import learned_perceptual_image_patch_similarity

result = torch.rand(1, 3, 50, 50, device='cuda:0', dtype=torch.float64)
target = torch.rand(1, 3, 50, 50, device='cuda:0', dtype=torch.float64)
learned_perceptual_image_patch_similarity(result, target, normalize=True)

Expected behavior

Change

loss, total = _lpips_update(img1, img2, net, normalize)

To

    loss, total = _lpips_update(img1, img2, net.to(device=img1.device, dtype=img1.dtype), normalize) 

Environment

Name Version Build Channel
_anaconda_depends 2023.07 py311_0 https://repo.anaconda.com/pkgs/main
conda 23.9.0 py311haa95532_0 https://repo.anaconda.com/pkgs/main
python 3.10.13 he1021f5_0 defaults
pytorch 2.1.0 py3.10_cuda12.1_cudnn8_0 pytorch
pytorch-cuda 12.1 hde6ce7c_5 pytorch
pytorch-mutex 1.0 cuda pytorch
torchaudio 2.1.0 pypi_0 pypi
torchmetrics 1.2.0 pyhd8ed1ab_0 conda-forge
torchvision 0.16.0 pypi_0 pypi
@michael080808 michael080808 added bug / fix Something isn't working help wanted Extra attention is needed labels Nov 22, 2023
@michael080808 michael080808 changed the title learned_perceptual_image_patch_similarity function needs to synchronize device and dtype between net and input img learned_perceptual_image_patch_similarity function needs to synchronize device and dtype between net and input images Nov 22, 2023
@Borda Borda added the v1.2.x label Nov 22, 2023
@Borda Borda changed the title learned_perceptual_image_patch_similarity function needs to synchronize device and dtype between net and input images learned_perceptual_image_patch_similarity function needs to synchronize device and dtype between net and input images Nov 22, 2023
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.2.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants