You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境下加载openai/clip-vit-base-patch32模型失败求助

Windows环境下加载openai/clip-vit-base-patch32模型失败求助

大家好,我在Windows环境下尝试运行CLIP模型时遇到了加载失败的问题,想向各位大佬求助!

环境

  • Windows 11 x86_64
  • Python 3.12.6
  • Cuda 12.6

问题详情

我是跟着HuggingFace官方的CLIP指南来写代码的,代码如下:

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

但是当我执行python main.py时,一直弹出以下错误:

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.

我已经尝试过的解决方法

  • 更换过不同版本的Python,也分别在虚拟环境(venv)和系统默认环境中测试过,都没解决
  • 删除了HuggingFace的缓存目录~/.cache/huggingface,重新下载模型还是报错
  • 确认过网络可以正常访问HuggingFace,浏览器能打开模型页面
  • 在WSL2环境中完全复刻相同步骤运行代码,一切正常,但在Windows原生环境里就出现这个加载错误

实在找不到问题所在了,恳请各位帮忙分析一下,谢谢大家!

备注:内容来源于stack exchange,提问作者Watcher Night

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 18:29:33