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

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

Open
outfielder opened this issue May 2, 2022 · 6 comments
Open

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

outfielder opened this issue May 2, 2022 · 6 comments

Comments

@outfielder
Copy link

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.

@arks22
Copy link

arks22 commented Aug 5, 2022

I have same problem.

@arks22
Copy link

arks22 commented Aug 5, 2022

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.

@Asteriska001
Copy link

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?

@NeverGiveU
Copy link

Check & Rename the existing lpips.py files.

@Xiaobaishushu25
Copy link

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

@NeverGiveU
Copy link

NeverGiveU commented May 2, 2023 via email

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

5 participants