Skip to content

❓ ImportError: open_clip is required for VLM models #2878

Closed

Description

@enrico310786

Your Question

Hi,

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.

Activity

  1. github-actions commented on Aug 7, 2025

    @github-actions

    Thanks for submitting this issue! It has been added to our triage queue. A maintainer will review it shortly.

  2. rajeshgangireddy commented on Aug 8, 2025

    @rajeshgangireddy
    Contributor

    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.

  3. mvanaei commented on Aug 8, 2025

    @mvanaei

    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)
    '''

  4. mvanaei commented on Aug 8, 2025

    @mvanaei

    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.

  5. waschsalz commented on Aug 11, 2025

    @waschsalz
    Contributor

    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.

  6. rajeshgangireddy commented on Aug 11, 2025

    @rajeshgangireddy
    Contributor

    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.

  7. rajeshgangireddy commented on Aug 11, 2025

    @rajeshgangireddy
    Contributor

    You comment on batch_size to be 1 by default/overwritten for efficientAD is valid. I will discuss and fix this.

  8. mvanaei commented on Aug 12, 2025

    @mvanaei

    @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.

  9. waschsalz commented on Aug 12, 2025

    @waschsalz
    Contributor

    @mvanaee

    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.

    Short example:

    from anomalib.deploy import TorchInferencer, OpenVINOInferencer
    
    
    inferencer_torch = TorchInferencer(path="YOUR_MODEL.pt")
    
    inferencer_openvino = OpenVINOInferencer(path="YOUR_MODEL.xml")
    
    

    For predicting an image you can simply use:

    predictions = inferencer.predict(image_path="YOUR_IMAGE.jpg")
    
  10. rajeshgangireddy commented on Aug 14, 2025

    @rajeshgangireddy
    Contributor

    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.

  11. locked and limited conversation to collaborators on Aug 18, 2025
  12. converted this issue into a discussion #2891 on Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions