You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
❓ ImportError: open_clip is required for VLM models #2878
I installed anomalib using a requirements.txt. First I create a venv
python3.10 -m venv venv
then I install all the packages using
pip install -r requirements.txt
Inside the requirements ther is "anomalib==2.1.0". The installed version of anomalib is checked by
pip show anomalib
Name: anomalib
Version: 2.1.0
Now, I run the training script to train a ReverseDistillation model on my custom dataset, but i receive the error
Traceback (most recent call last):
File "/home/randellini/progetto_eltek/train_test_anomalib_models/train_reversedistillation_anomalib.py", line 6, in
from anomalib.models import ReverseDistillation
File "/home/randellini/progetto_eltek/venv/lib/python3.10/site-packages/anomalib/models/init.py", line 57, in
from .image import (
File "/home/randellini/progetto_eltek/venv/lib/python3.10/site-packages/anomalib/models/image/init.py", line 67, in
from .winclip import WinClip
File "/home/randellini/progetto_eltek/venv/lib/python3.10/site-packages/anomalib/models/image/winclip/init.py", line 30, in
from .lightning_model import WinClip
File "/home/randellini/progetto_eltek/venv/lib/python3.10/site-packages/anomalib/models/image/winclip/lightning_model.py", line 48, in
from .torch_model import WinClipModel
File "/home/randellini/progetto_eltek/venv/lib/python3.10/site-packages/anomalib/models/image/winclip/torch_model.py", line 49, in
raise ImportError(msg)
ImportError: open_clip is required for VLM models. Install it with: pip install anomalib[vlm_clip]
I did "pip install anomalib[vlm_clip]", but I continue to receive the same error.
Can you help me?
Forum Check
I have searched the discussions forum for an answer to my question.
Hi @enrico310786
thanks for reaching out.
We recently updated our pyproject. Please try with pip install "anomalib[full]"
or pip install "anomalib[vlm,clip]"
The error message is outdated. I will make a PR to fix it.
Hi. The issue still exists. I have to comment this
'''
if TYPE_CHECKING or module_available("open_clip"):
import open_clip
from open_clip.tokenizer import tokenize
else:
msg = "open_clip is required for VLM models. Install it with: pip install anomalib[vlm_clip]"
raise ImportError(msg)
'''
Another issue:
When using EfficiendAD and not setting batch sizr it throws an error that for this model batch size should be 1. I think Its better to do it as a default for this model.
another issue with former version (not sure it still exists or not):
I couldnt set number of eochs at least for PaDim model. In any case it was 1. I had to change the code inside the library.
The number of epochs for PaDim has to be 1. Models like PaDim or Patchcore are memory bank-based models. They are fitted for one epoch to extract features from the images, process them and save them in a memory bank. After this one epoch, the model is done, meaning that setting epochs to more than 1, is redundant.
What you want for EfficientAD is basically what they implemented for PaDim or Patchcore.
Hi @mvanaee
As @waschsalz mentioned, some models have a set of parameters fixed based on their implementation. These can not be changed. @waschsalz Thanks for the response.
@waschsalz@rajeshgangireddy
Thank you for your answers. Yes you are right. For those models training is not like others.
I have another question.
waht is the best way for using this library for live anomaly detection. If I want to use engine.predict, first I have to add the live frame to a dataloader or write on the disk and read it immediately, which obviously is not ok. I tried to use the model itself directly, but the results were not the same. Also I wanted to use Inference, but it is mentioned that it is legacy and it is better to use engine.predict.
And I think (I am not sure) engine.predict is not optimized for fast live detection. because it has several stages which maybe are not needed every time after training (like validation for example) and also it saves images for example.
So I am wondering is there a better way to control the process of prediction to speed it up for live detection: easily pass the frame, and get just the results?
I always worked with the TorchInferencer which is best suited if you are able to use the CUDA functionality of your GPU (if the manufacturer is NVIDIA).
The other recommendable is to use the Intel-optimized OpenVINOInferencer. It is a toolkit optimised to get maximum inference speed out of Intel chips (@rajeshgangireddy Please correct me if I am wrong or missing a part - I'm not from Intel as you probably know).
Short:
If you have a CUDA-ready GPU --> TorchInferencer (Don't use it on a CPU...)
If you have a fitting Intel device (CPU, GPU) --> OpenVINOInferencer
If you have both --> Do whatever you want but for me the TorchInferencer was definitely the fastest option
For whichever case, you need to export the trained model via engine.export(export_type="torch" OR "openvino") which enables you to load the model and use it for inference in a more focused and separated way.
You comment on batch_size to be 1 by default/overwritten for efficientAD is valid. I will discuss and fix this.
This isn't straightforward as a datamodule is created independent of the model. To force the batch_size, we might have to (re)setup the datamodule in the model, which is not the best way to do it.
Activity
github-actions commentedon Aug 7, 2025
Thanks for submitting this issue! It has been added to our triage queue. A maintainer will review it shortly.
rajeshgangireddy commentedon Aug 8, 2025
Hi @enrico310786
thanks for reaching out.
We recently updated our pyproject. Please try with
pip install "anomalib[full]"or
pip install "anomalib[vlm,clip]"The error message is outdated. I will make a PR to fix it.
mvanaei commentedon Aug 8, 2025
Hi. The issue still exists. I have to comment this
'''
if TYPE_CHECKING or module_available("open_clip"):
import open_clip
from open_clip.tokenizer import tokenize
else:
msg = "open_clip is required for VLM models. Install it with: pip install anomalib[vlm_clip]"
raise ImportError(msg)
'''
mvanaei commentedon Aug 8, 2025
Another issue:
When using EfficiendAD and not setting batch sizr it throws an error that for this model batch size should be 1. I think Its better to do it as a default for this model.
another issue with former version (not sure it still exists or not):
I couldnt set number of eochs at least for PaDim model. In any case it was 1. I had to change the code inside the library.
waschsalz commentedon Aug 11, 2025
Hello @mvanaee
The number of epochs for PaDim has to be 1. Models like PaDim or Patchcore are memory bank-based models. They are fitted for one epoch to extract features from the images, process them and save them in a memory bank. After this one epoch, the model is done, meaning that setting epochs to more than 1, is redundant.
What you want for EfficientAD is basically what they implemented for PaDim or Patchcore.
rajeshgangireddy commentedon Aug 11, 2025
Hi @mvanaee
As @waschsalz mentioned, some models have a set of parameters fixed based on their implementation. These can not be changed.
@waschsalz Thanks for the response.
rajeshgangireddy commentedon Aug 11, 2025
You comment on batch_size to be 1 by default/overwritten for efficientAD is valid. I will discuss and fix this.
mvanaei commentedon Aug 12, 2025
@waschsalz @rajeshgangireddy
Thank you for your answers. Yes you are right. For those models training is not like others.
I have another question.
waht is the best way for using this library for live anomaly detection. If I want to use engine.predict, first I have to add the live frame to a dataloader or write on the disk and read it immediately, which obviously is not ok. I tried to use the model itself directly, but the results were not the same. Also I wanted to use Inference, but it is mentioned that it is legacy and it is better to use engine.predict.
And I think (I am not sure) engine.predict is not optimized for fast live detection. because it has several stages which maybe are not needed every time after training (like validation for example) and also it saves images for example.
So I am wondering is there a better way to control the process of prediction to speed it up for live detection: easily pass the frame, and get just the results?
I appreciate your time and guide.
waschsalz commentedon Aug 12, 2025
@mvanaee
I always worked with the
TorchInferencerwhich is best suited if you are able to use the CUDA functionality of your GPU (if the manufacturer is NVIDIA).The other recommendable is to use the Intel-optimized
OpenVINOInferencer. It is a toolkit optimised to get maximum inference speed out of Intel chips (@rajeshgangireddy Please correct me if I am wrong or missing a part - I'm not from Intel as you probably know).Short:
If you have a CUDA-ready GPU --> TorchInferencer (Don't use it on a CPU...)
If you have a fitting Intel device (CPU, GPU) --> OpenVINOInferencer
If you have both --> Do whatever you want but for me the TorchInferencer was definitely the fastest option
For whichever case, you need to export the trained model via
engine.export(export_type="torch" OR "openvino")which enables you to load the model and use it for inference in a more focused and separated way.Short example:
For predicting an image you can simply use:
rajeshgangireddy commentedon Aug 14, 2025
This isn't straightforward as a datamodule is created independent of the model. To force the batch_size, we might have to (re)setup the datamodule in the model, which is not the best way to do it.