Po-Hsun-Su / pytorch-ssim

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

Runtime error when trying to use your code #1

Closed anonymousAwesome closed 7 years ago

anonymousAwesome commented 7 years ago

When I try to run your code I get the following error:

Traceback (most recent call last): File "pytorch_NN4.py", line 144, in loss = loss_fn(ypred, y) File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 224, in __call_\ result = self.forward(*input, **kwargs) File "/media/brenco/Shared Partition/Neural Network/pytorch_ssim.py", line 57, in forward return _ssim(img1, img2, window, self.window_size, channel, self.size_average) File "/media/brenco/Shared Partition/Neural Network/pytorch_ssim.py", line 18, in _ssim mu1 = F.conv2d(img1, window, padding = window_size/2, groups = channel) File "/usr/local/lib/python3.5/dist-packages/torch/nn/functional.py", line 51, in conv2d _pair(0), groups, torch.backends.cudnn.benchmark, torch.backends.cudnn.enabled) RuntimeError: argument 1 (padding) must be tuple of int but got tuple of (float, float)

I downloaded the python-ssim.py file and just made a call to that instead of installing it, but I don't think that should be a problem. Any suggestions?

anonymousAwesome commented 7 years ago

Huh. So I changed the window_size to 10 and changed every "window_size/2" to "int(window_size/2)", and that seems to have done the trick, albeit rather sloppily. So at least now you know where the error is.

Po-Hsun-Su commented 7 years ago

Hi, Thank you for reporting the bug. I notice that in Python3 / is floating point division. I change window_size/2 to window_size//2 to ensure that python3 use integer division. I think this will resolve the issue.