BLIP 的demo运行遇到的问题

代码地址:GitHub - salesforce/BLIP: PyTorch code for BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation

运行demo.ipynb遇到的问题

1、OSError: Can't load tokenizer for 'bert-base-uncased'

OSError: Can't load tokenizer for 'bert-base-uncased'. 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 'bert-base-uncased' is the correct path to a dir

此类报错如果用http://huggingface.co上的模型的话,经常遇到,其实这类错误的背后都是代码要使用“抱抱脸”上的模型但是下载不了,因此就报找不到这个文件夹之类的错误。

需要设置环境变量

set HF_ENDPOINT=https://hf-mirror.com

python XXXX

我的建议是在代码里直接指定

调用的文件from models.blip import blip_decoder,from models.med import BertConfig, BertModel, BertLMHeadModel就在models\blip.py,models\med.py里加入这个指令就行了。

import os

os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'

2、The size of tensor a (3) must match the size of tensor b (9)

RuntimeError: The size of tensor a (3) must match the size of tensor b (9) at non-singleton dimension 0

在进行张量操作时,两个张量的形状不匹配。在这个例子中,张量a的大小为3,而张量b的大小为9。 num_beams=3改为1

in order to solve this problem you need to set num_beams=1 not 3. (for instance in blip_vqa.py line 92)

直接在demo.ipynb# Image Captioning里修改就行

3、图片、权重可以下载下来在本地加载

    #raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')  

    raw_image = Image.open(img_url).convert('RGB')

最后结果如下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值