标签:
- clip
库名称: open_clip
管道标签: 零样本图像分类
许可证: apache-2.0
数据集:
- mlfoundations/datacomp_1b
ViT-bigG-14-CLIPA-336-datacomp1B 模型卡片
一个 CLIPA-v2 模型...
模型详情
- 模型类型: 对比式图文模型,零样本图像分类。
- 原始来源: https://github.com/UCSC-VLAA/CLIPA
- 数据集: mlfoundations/datacomp_1b
- 相关论文:
- CLIPA-v2: 以1万美元预算实现81.1%的零样本ImageNet准确率;额外4千美元解锁81.8%准确率: https://arxiv.org/abs/2306.15658
- CLIP训练的逆缩放定律: https://arxiv.org/abs/2305.07017
模型使用
使用OpenCLIP
import torch
import torch.nn.functional as F
from urllib.request import urlopen
from PIL import Image
from open_clip import create_model_from_pretrained, get_tokenizer
model, preprocess = create_model_from_pretrained('hf-hub:ViT-bigG-14-CLIPA-336')
tokenizer = get_tokenizer('hf-hub:ViT-bigG-14-CLIPA-336')
image = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
image = preprocess(image).unsqueeze(0)
text = tokenizer(["一张图表", "一只狗", "一只猫", "一个贝涅饼"], context_length=model.context_length)
with torch.no_grad(), torch.cuda.amp.autocast():
image_features = model.encode_image(image)
text_features = model.encode_text(text)
image_features = F.normalize(image_features, dim=-1)
text_features = F.normalize(text_features, dim=-1)
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
print("标签概率:", text_probs)
引用
@article{li2023clipav2,
title={CLIPA-v2: Scaling CLIP Training with 81.1% Zero-shot ImageNet Accuracy within a $10,000 Budget; An Extra $4,000 Unlocks 81.8% Accuracy},
author={Xianhang Li and Zeyu Wang and Cihang Xie},
journal={arXiv preprint arXiv:2306.15658},
year={2023},
}
@inproceedings{li2023clipa,
title={An Inverse Scaling Law for CLIP Training},
author={Xianhang Li and Zeyu Wang and Cihang Xie},
booktitle={NeurIPS},
year={2023},
}