clip_interrogator库

最近在为一个condition generation的项目准备数据集,大概就是给无label的图像数据pair文本标签。然后想着用clip_interrogator库在cifar10-64数据集先试一下。clip_interrogator的git链接如下:

pharmapsychotic/clip-interrogator: Image to prompt with BLIP and CLIP

官方给环境配置过程是:

python3 -m venv ci_env
(for linux  ) source ci_env/bin/activate
(for windows) .\ci_env\Scripts\activate

我自己的环境是miniconda,这点没啥区别。下面是pip安装过程:

# install torch with GPU support for example:
pip3 install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu117

# install clip-interrogator
pip install clip-interrogator==0.5.4

# or for very latest WIP with BLIP2 support
#pip install clip-interrogator==0.6.0

建议对于stable diffusion 1.X版本,clip model使用ViT-L-14/openai;对于stable diffusion 2.0版本,clip model使用ViT-H-14/laion2b_s32b_b79k。

测试脚本文件:

from PIL import Image
from clip_interrogator import Config, Interrogator
image = Image.open(image_path).convert('RGB')
ci = Interrogator(Config(clip_model_name="ViT-L-14/openai"))
print(ci.interrogate(image))

然后在clip-interrogator==0.5.4的环境下使用clip_model_name="ViT-H-14/laion2b_s32b_b79k"和clip_model_name="ViT-L-14/openai"都遇到如下问题:

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

在clip-interrogator==0.6.0的环境下两种clip_model均不会出现报错。

有没有也遇到类似问题的佬来讲讲,感谢。

另外,在对Config传入caption_model_name时,如果选用blip2-flan-t5-xl,会出现如下报错:

RuntimeError: shape mismatch: value tensor of shape [65536] cannot be broadcast to indexing result of shape [0]

如果使用caption_model_name="blip-large",则不会出现上述问题。

有没有佬前来答疑解惑,感谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值