项目介绍:vit_large_patch14_clip_224.openai_ft_in12k_in1k
vit_large_patch14_clip_224.openai_ft_in12k_in1k
是一个图像分类模型,使用 Vision Transformer (ViT) 架构进行开发。它是由OpenAI预训练在WIT-400M的图像-文本数据集上,并在ImageNet-12k和ImageNet-1k上进行微调,使用的是timm
库。
模型详情
- 模型类型: 图像分类/特征骨干
- 模型统计:
- 参数数量 (百万): 304.2
- GMACs: 77.8
- 激活数量 (百万): 57.1
- 图像大小: 224 x 224
- 相关论文:
- 数据集: ImageNet-1k
- 预训练数据集:
- WIT-400M
- ImageNet-12k
模型使用
图像分类
用户可以加载该模型,并对图像进行分类。以下是一个简单的代码示例:
from urllib.request import urlopen
from PIL import Image
import timm
img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
model = timm.create_model('vit_large_patch14_clip_224.openai_ft_in12k_in1k', pretrained=True)
model = model.eval()
# 获取模型特定的变换 (规范化, 调整大小)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
output = model(transforms(img).unsqueeze(0))
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
图像嵌入
该模型还能够生成图像嵌入,这对于某些需要提取图像特征的任务非常有用。以下展示了如何获取图像嵌入的示例代码:
from urllib.request import urlopen
from PIL import Image
import timm
img = Image.open(urlopen(
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
))
model = timm.create_model(
'vit_large_patch14_clip_224.openai_ft_in12k_in1k',
pretrained=True,
num_classes=0, # 移除分类器 nn.Linear
)
model = model.eval()
# 获取模型特定的变换 (规范化, 调整大小)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)
output = model(transforms(img).unsqueeze(0))
# 或者等价地 (无需设置 num_classes=0)
output = model.forward_features(transforms(img).unsqueeze(0))
output = model.forward_head(output, pre_logits=True)
模型比较
用户可以在timm
的模型结果中探索该模型的数据集和运行时指标,以进行更详细的比较。
引用文献
如果您在研究中使用此模型,请引用以下相关文献:
@inproceedings{Radford2021LearningTV,
title={Learning Transferable Visual Models From Natural Language Supervision},
author={Alec Radford and Jong Wook Kim and others},
booktitle={ICML},
year={2021}
}
@article{cherti2022reproducible,
title={Reproducible scaling laws for contrastive language-image learning},
author={Cherti, Mehdi and others},
journal={arXiv preprint arXiv:2212.07143},
year={2022}
}
@article{dosovitskiy2020vit,
title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
author={Dosovitskiy, Alexey and others},
journal={ICLR},
year={2021}
}
@misc{rw2019timm,
author = {Ross Wightman},
title = {PyTorch Image Models},
year = {2019},
publisher = {GitHub},
journal = {GitHub repository},
doi = {10.5281/zenodo.4414861},
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
}
通过这些信息,用户可以全面了解vit_large_patch14_clip_224.openai_ft_in12k_in1k
模型以及如何在实际应用中加以利用。