[Python] Can't load the model for 'openai/clip-vit-base-patch32'

Discussão em 'Python' iniciado por Stack, Dezembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    Environments


    Windows 11 x86_64

    Python 3.12.6

    Cuda 12.6

    Details


    I follow huggingface offical guide guide to run the code

    from PIL import Image
    import requests

    from transformers import CLIPProcessor, CLIPModel

    model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
    processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")

    url = "http://images.cocodataset.org/val2017/000000039769.jpg"
    image = Image.open(requests.get(url, stream=True).raw)

    inputs = processor(text=["a photo of a cat", "a photo of a dog"], images=image, return_tensors="pt", padding=True)

    outputs = model(**inputs)
    logits_per_image = outputs.logits_per_image # this is the image-text similarity score
    probs = logits_per_image.softmax(dim=1) # we can take the softmax to get the label probabilities


    However, when I type 'python main.py'. It always shows


    OSError: Can't load the model for 'openai/clip-vit-base-patch32'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'openai/clip-vit-base-patch32' is the correct path to a directory containing a file named pytorch_model.bin, tf_model.h5, model.ckpt or flax_model.msgpack.
    ​
    Solutions I tried


    I tried different version of python and environment(venv and normal).

    I tried delete the hugging face cache at ~/.cache/huggingface.

    I believed that my network can access huggingface.

    I tried the code in my WSL2, it goes well, but when I do the same step in Windows, it goes bad.

    Thanks a lot!

    Continue reading...

Compartilhe esta Página