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

issue with basic usage example #36

Open
Alok589 opened this issue Jan 24, 2021 · 3 comments
Open

issue with basic usage example #36

Alok589 opened this issue Jan 24, 2021 · 3 comments

Comments

@Alok589
Copy link

Alok589 commented Jan 24, 2021

Hi,

I am not able to run the example script. Could you please let me know what is missing?

basic usage script :

import pytorch_ssim
import torch
from torch.autograd import Variable

img1 = Variable(torch.rand(1, 1, 256, 256))
img2 = Variable(torch.rand(1, 1, 256, 256))

if torch.cuda.is_available():
img1 = img1.cuda()
img2 = img2.cuda()

print(pytorch_ssim.ssim(img1, img2))

ssim_loss = pytorch_ssim.SSIM(window_size=4)

print(ssim_loss(img1, img2))

here is the traceback of the code:

Traceback (most recent call last):
File "/home/thesis_2/ssim_test.py", line 12, in
print(pytorch_ssim.ssim(img1, img2))
File "/opt/conda/envs/venv/lib/python3.6/site-packages/pytorch_ssim/init.py", line 62, in ssim
return _ssim(img1, img2, window, window_size, channel, size_average)
File "/opt/conda/envs/venv/lib/python3.6/site-packages/pytorch_ssim/init.py", line 18, in _ssim
mu1 = F.conv2d(img1, window, padding = window_size/2, groups = channel)
TypeError: conv2d(): argument 'padding' must be tuple of ints, not float

@neeek2303
Copy link

neeek2303 commented Jan 29, 2021

@Alok589 I had the same problem because I used pip to install this repo as a package. I just have to clone this repo, then copy pytorch_ssim folder from this repo (repo and folder have the same name - maybe it is a reason why we misunderstood) to your directory as follow:
YOU_FOLDER
........pytorch_ssim
................init.py
........file.py (the file where you are supposed to use ssim )

@zakajd
Copy link

zakajd commented Mar 8, 2021

For anyone having same issue in the future.
Replace window_size/2 with window_size // 2 to get correct dtype after division.

@ucalyptus2
Copy link

@Alok589 to make it work on COLAB:


!git clone https://github.com/Po-Hsun-Su/pytorch-ssim.git


import sys;sys.path.append("/content/pytorch-ssim")
import pytorch_ssim
import torch
from torch.autograd import Variable

img1 = Variable(torch.rand(1, 1, 256, 256))
img2 = Variable(torch.rand(1, 1, 256, 256))

if torch.cuda.is_available():
    img1 = img1.cuda()
    img2 = img2.cuda()

print(pytorch_ssim.ssim(img1, img2))

ssim_loss = pytorch_ssim.SSIM(window_size = 11)

print(ssim_loss(img1, img2))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants