richzhang / PerceptualSimilarity

LPIPS metric. pip install lpips
https://richzhang.github.io/PerceptualSimilarity
BSD 2-Clause "Simplified" License
3.71k stars 500 forks source link

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! #91

Closed Lansv-Noer closed 2 years ago

Lansv-Noer commented 2 years ago

Hi, Thank you for your work, but I have a problem when I run lpips loss on my computer with one GPU. All inputs of lpips are on device "cuda:0", but I am given an error (RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!). Details of error are shown as below. And version of lpips is 0.1.4. File "losses/Lpips_Loss.py", line 47, in forward loss = self.loss(input[:, (2, 1, 0), ...], target[:, (2, 1, 0), ...], normalize=True) File "/**/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/**/lib/python3.8/site-packages/lpips/lpips.py", line 118, in forward in0_input, in1_input = (self.scaling_layer(in0), self.scaling_layer(in1)) if self.version=='0.1' else (in0, in1) File "/**/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/**/lib/python3.8/site-packages/lpips/lpips.py", line 154, in forward return (inp - self.shift) / self.scale RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! Thanks.

Lansv-Noer commented 2 years ago

I don't transmit Lpips model to gpu, so I got this error.

szh404 commented 5 months ago

self.shift and self.scale are on the CPU