运行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')
最后结果如下