PerceptualSimilarity icon indicating copy to clipboard operation
PerceptualSimilarity copied to clipboard

AttributeError: module 'lpips' has no attribute 'LPIPS'

Open outfielder opened this issue 2 years ago • 6 comments

I have done a pip install lpips as instructed in the repo's README and copied an pasted the example code given:

import lpips
loss_fn_alex = lpips.LPIPS(net='alex') # best forward scores
loss_fn_vgg = lpips.LPIPS(net='vgg') # closer to "traditional" perceptual loss, when used for optimization

import torch
img0 = torch.zeros(1,3,64,64) # image should be RGB, IMPORTANT: normalized to [-1,1]
img1 = torch.zeros(1,3,64,64)
d = loss_fn_alex(img0, img1)

but I keep getting the following error:

Traceback (most recent call last):
  File "home/xyz.py", line 2, in <module>
    loss_fn_alex = lpips.LPIPS(net='alex') # best forward scores
AttributeError: module 'lpips' has no attribute 'LPIPS'

I know that it is installed, because I can right click on LPIPS in my IDE and it takes me to the source code, so I am confused as to why I am getting that attribute error.

I can see someone else had the same issue before me, but the issue is closed without any explanation as to how it may have been solved.

outfielder avatar May 02 '22 03:05 outfielder

I have same problem.

arks22 avatar Aug 05 '22 20:08 arks22

I don't know if you have the same cause, but my problem is solved. I had named the file lpips.py to test lpips, so import lpips imported lpips.py itself, causing a circular reference. After changing the file name to lpips_test.py, it worked.

arks22 avatar Aug 05 '22 20:08 arks22

I don't know if you have the same cause, but my problem is solved. I had named the file lpips.py to test lpips, so import lpips imported lpips.py itself, causing a circular reference. After changing the file name to lpips_test.py, it worked.

Genius! :) I had a same problem and this helped. Thank you. @outfielder May be you can check the current folder whether a 'lpips.py' file exists here?

Asteriska001 avatar Sep 02 '22 05:09 Asteriska001

Check & Rename the existing lpips.py files.

NeverGiveU avatar Jan 19 '23 12:01 NeverGiveU

I don't know if you have the same cause, but my problem is solved. I had named the file lpips.py to test lpips, so import lpips imported lpips.py itself, causing a circular reference. After changing the file name to lpips_test.py, it worked.

That's why,Thank you

Xiaobaishushu25 avatar May 02 '23 13:05 Xiaobaishushu25

这是来自QQ邮箱的假期自动回复邮件。您好!您的来信我已收到,我将认真阅读邮件并及时予以您答复!谢谢!

NeverGiveU avatar May 02 '23 13:05 NeverGiveU