CLIP
CLIP copied to clipboard
AttributeError: module 'clip' has no attribute 'load'
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
:
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.
do you have a local directory named clip
or a file named clip.py
in the same directory?
I think you need to install 'clip-by-openai', not 'clip':
pip3 install clip-by-openai
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.
Use the latest stable version by installing openai-clip:
pip install openai-clip
do you have a local directory named
clip
or a file namedclip.py
in the same directory?
wow! thanks!! you figure out what I am looking for!
@davitpapikyan thx!
pip install git+https://github.com/openai/CLIP.git
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 pip
then 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.