richzhang / PerceptualSimilarity

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

Problems when comparing PNG to JPG #88

Open b4zz4 opened 3 years ago

b4zz4 commented 3 years ago
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

ChameleonScales commented 2 years ago

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.

richzhang commented 2 years ago

Yes, the images need to be of the same size