标签:
- 剪辑
库名称: open_clip
管道标签: 零样本图像分类
许可证: apache-2.0
数据集:
- laion/laion2b-en
ViT-H-14-CLIPA-laion2B 模型卡片
一个 CLIPA-v2 模型...
模型详情
- 模型类型: 对比图像-文本,零样本图像分类。
- 原始来源: https://github.com/UCSC-VLAA/CLIPA
- 数据集: laion/laion2B-en
- 论文:
- CLIPA-v2: 以10,000美元预算扩展CLIP训练,实现81.1%的零样本ImageNet准确率;额外4,000美元解锁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-H-14-CLIPA')
tokenizer = get_tokenizer('hf-hub:ViT-H-14-CLIPA')
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) # 输出: [[0., 0., 0., 1.0]]
引用
@article{li2023clipav2,
title={CLIPA-v2: 以10,000美元预算扩展CLIP训练,实现81.1%的零样本ImageNet准确率;额外4,000美元解锁81.8%准确率},
author={李贤航 and 王泽宇 and 谢慈航},
journal={arXiv预印本 arXiv:2306.15658},
year={2023},
}
@inproceedings{li2023clipa,
title={CLIP训练的逆缩放定律},
author={李贤航 and 王泽宇 and 谢慈航},
booktitle={NeurIPS},
year={2023},
}