Po-Hsun-Su / pytorch-ssim

pytorch structural similarity (SSIM) loss
Other
1.89k stars 367 forks source link

Not accepting input type from CUDA #19

Open ranka47 opened 5 years ago

ranka47 commented 5 years ago
Traceback (most recent call last):
  File "run_model.py", line 143, in <module>
    loss_ssim = -ssim_loss(noriginalimage, outputimage)
  File "/usr/local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pytorch_ssim/__init__.py", line 57, in forward
    return _ssim(img1, img2, window, self.window_size, channel, self.size_average)
  File "/usr/local/lib/python3.6/site-packages/pytorch_ssim/__init__.py", line 18, in _ssim
    mu1 = F.conv2d(img1, window, padding = window_size//2, groups = channel)
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

It is throwing this error. I have to convert both the variables to CPU to run which kills the speed of the computation. Can someone help out in resolving this?

t2ac32 commented 5 years ago

Can you post the code section where you sent your too inputs to cuda? Because youa re sending two thing to ssim both as tensors but only one of them is in GPU the other not.

crvogt commented 4 years ago

For future reference, the weights need to be sent to cuda device, or input needs to be on CPU