richzhang/PerceptualSimilarity

Problems when comparing PNG to JPG

b4zz4 opened this issue · 2 comments

b4zz4 commented
import lpips
import sys
loss_fn = lpips.LPIPS(net='alex') # vgg o squeeze
img0 = lpips.im2tensor(lpips.load_image(sys.argv[1]))
img1 = lpips.im2tensor(lpips.load_image(sys.argv[2]))
print ('Distances: %.3f'%(loss_fn.forward(img0,img1)))

RuntimeError: The size of tensor a (127) must match the size of tensor b (255) at non-singleton dimension

I can successfully compare a jpg against a png. However, I get this error when comparing 2 images that have different resolutions. I can solve this problem by a combination of resizing the image and the canvas to make them match as optimally as possible.

Yes, the images need to be of the same size