CLIP icon indicating copy to clipboard operation
CLIP copied to clipboard

AttributeError: module 'clip' has no attribute 'load'

Open jennasawaf opened this issue 2 years ago • 8 comments

I've been working with CLIP for a few weeks now, but for some reason my code stopped working.

This is the code:

import torch import clip

device = "cuda" if torch.cuda.is_available() else "cpu" og_model, preprocess = clip.load('ViT-B/32', device)

then the error I get is the following Screen Shot 2021-11-15 at 3 24 24 PM :

I tried testing the same code in a sagemaker notebook on aws and it worked there so I'm starting to think it might be because I'm working on a Mac? please let me know if there's something I can do to get it to work.

jennasawaf avatar Nov 15 '21 20:11 jennasawaf

do you have a local directory named clip or a file named clip.py in the same directory?

jongwook avatar Nov 16 '21 01:11 jongwook

I think you need to install 'clip-by-openai', not 'clip': pip3 install clip-by-openai

thandal avatar Dec 17 '21 19:12 thandal

I think you need to install 'clip-by-openai', not 'clip': pip3 install clip-by-openai

Please note that clip-by-openai is not managed/endorsed by OpenAI.

I realize the OP might've installed clip from PyPI, which they shouldn't -- if that's the case, uninstall it by pip uninstall clip and follow the instructions in README.md to install CLIP properly.

jongwook avatar Dec 17 '21 23:12 jongwook

Use the latest stable version by installing openai-clip:

pip install openai-clip

davitpapikyan avatar Dec 03 '22 10:12 davitpapikyan

do you have a local directory named clip or a file named clip.py in the same directory?

wow! thanks!! you figure out what I am looking for!

hrx20000209 avatar Dec 14 '22 03:12 hrx20000209

@davitpapikyan thx!

haodong2000 avatar Sep 29 '23 11:09 haodong2000

pip install git+https://github.com/openai/CLIP.git

Bilal143260 avatar Jan 15 '24 08:01 Bilal143260

I had some problems, but they worked out.

Firstly

pip3 install git+https://github.com/openai/CLIP.git
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Collecting git+https://github.com/openai/CLIP.git
  Cloning https://github.com/openai/CLIP.git to /tmp/pip-req-build-_f2vfa36
  Running command git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /tmp/pip-req-build-_f2vfa36
  fatal: unable to access 'https://github.com/openai/CLIP.git/': Failed to connect to github.com port 443: Connection timed out
  error: subprocess-exited-with-error
  
  × git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /tmp/pip-req-build-_f2vfa36 did not run successfully.
  │ exit code: 128
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× git clone --filter=blob:none --quiet https://github.com/openai/CLIP.git /tmp/pip-req-build-_f2vfa36 did not run successfully.
│ exit code: 128
╰─> See above for output.

then i upgrade the pip,pip install --upgrade pipthen it works. pip3 install git+https://github.com/openai/CLIP.git --user

Secondly

python clip.py 
Traceback (most recent call last):
  File "clip.py", line 38, in <module>
    clip_embeding = ClipEmbeding()
  File "clip.py", line 10, in __init__
    self.model, self.processor = clip.load("/root/clip/model/ViT-B-32.pt", device=self.device)
AttributeError: module 'clip' has no attribute 'load'

so, i tried the above method, pip install openai-clip, but it does not work. then, i rename my python file name and the floder name, it works.

  • Previous file directory
/root/clip/:
code model

/root/clip/code:
clip.py  clip.ipynb  data  __pycache__  zore-shoot.py

/root/clip/code/data:
cifar-100-python  cifar-100-python.tar.gz

/root/clip/code/data/cifar-100-python:
file.txt~  meta  test  train

/root/clip/code/__pycache__:
clip.cpython-38.pyc  clip.cpython-39.pyc

/root/clip/model:
ViT-B-32.pt
  • Modified file directory
/root/clip-file/:
code  model

/root/clip-file/code:
clip-code.py  clip.ipynb  data  __pycache__  zore-shoot.py

/root/clip-file/code/data:
cifar-100-python  cifar-100-python.tar.gz

/root/clip-file/code/data/cifar-100-python:
file.txt~  meta  test  train

/root/clip-file/code/__pycache__:
clip.cpython-38.pyc  clip.cpython-39.pyc

/root/clip-file/model:
ViT-B-32.pt

Ending

hope these details can help you.

Riyue120 avatar Jan 15 '24 10:01 Riyue120