vit-base-patch16-224
简介
Vision Transformer (ViT) model pre-trained on ImageNet-21k (14 million images, 21,843 classes) at resolution 224x224, and fine-tuned on ImageNet 2012 (1 million images, 1,000 classes) at resolution 224x224. It was introduced in the paper An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale by Dosovitskiy et al. and first released in this repository. However, the weights were converted from the timm repository by Ross Wightman, who already converted the weights from JAX to P
模型卡片
模型配置
模型详情
已翻译Vision Transformer(基础尺寸模型)
Vision Transformer (ViT) 模型在 ImageNet-21k(1400 万张图像,21,843 个类别)上以 224x224 分辨率进行预训练,并在 ImageNet 2012(100 万张图像,1,000 个类别)上以 224x224 分辨率进行微调。该模型由 Dosovitskiy 等人在论文 An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale 中提出,并首次在 此仓库 中发布。然而,权重由 Ross Wightman 从 timm 仓库 转换而来,他此前已将权重从 JAX 转换为 PyTorch。感谢他的贡献。
免责声明:发布 ViT 的团队并未为该模型编写 model card,因此本 model card 由 Hugging Face 团队编写。
模型描述
Vision Transformer (ViT) 是一个 transformer 编码器模型(类似 BERT),以监督方式在大量图像数据集(即 ImageNet-21k)上以 224x224 像素分辨率进行预训练。随后,该模型在 ImageNet(也称为 ILSVRC2012)上以 224x224 分辨率进行微调,该数据集包含 100 万张图像和 1,000 个类别。
图像以固定大小的 patch(16x16 分辨率)序列形式输入模型,这些 patch 经过线性嵌入。同时,在序列开头添加一个 [CLS] token 用于分类任务。在将序列输入 Transformer 编码器的各层之前,还会添加绝对位置嵌入。
通过预训练,模型学习到图像的内在表示,可用于提取下游任务所需的特征:例如,如果你有一个带标签的图像数据集,可以在预训练编码器之上放置一个线性层来训练标准分类器。通常,线性层放置在 [CLS] token 之上,因为该 token 的最后一个隐藏状态可被视为整张图像的表示。
预期用途与限制
你可以使用原始模型进行图像分类。请查看 模型中心 寻找你感兴趣任务的微调版本。
使用方法
以下是如何使用此模型将 COCO 2017 数据集中的图像分类为 1,000 个 ImageNet 类别之一:
from transformers import ViTImageProcessor, ViTForImageClassification
from PIL import Image
import requests
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)
processor = ViTImageProcessor.from_pretrained('google/vit-base-patch16-224')
model = ViTForImageClassification.from_pretrained('google/vit-base-patch16-224')
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
# model predicts one of the 1000 ImageNet classes
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])
更多代码示例,请参考 文档。
训练数据
ViT 模型在 ImageNet-21k(包含 1400 万张图像和 21k 个类别)上进行预训练,并在 ImageNet(包含 100 万张图像和 1k 个类别)上进行微调。
训练过程
预处理
训练/验证期间图像预处理的具体细节可在 此处 找到。
图像被调整/缩放到相同分辨率 (224x224),并在 RGB 通道上使用均值 (0.5, 0.5, 0.5) 和标准差 (0.5, 0.5, 0.5) 进行归一化。
预训练
模型在 TPUv3 硬件(8 核)上训练。所有模型变体均使用 4096 的 batch size 和 10k 步的学习率预热进行训练。对于 ImageNet,作者发现额外应用全局范数为 1 的梯度裁剪是有益的。训练分辨率为 224。
评估结果
关于多个图像分类基准的评估结果,请参考原始论文的表 2 和表 5。请注意,对于微调,使用更高分辨率 (384x384) 可获得最佳结果。当然,增加模型大小也会带来更好的性能。
BibTeX 条目与引用信息
@misc{wu2020visual,
title={Visual Transformers: Token-based Image Representation and Processing for Computer Vision},
author={Bichen Wu and Chenfeng Xu and Xiaoliang Dai and Alvin Wan and Peizhao Zhang and Zhicheng Yan and Masayoshi Tomizuka and Joseph Gonzalez and Kurt Keutzer and Peter Vajda},
year={2020},
eprint={2006.03677},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
@inproceedings{deng2009imagenet,
title={Imagenet: A large-scale hierarchical image database},
author={Deng, Jia and Dong, Wei and Socher, Richard and Li, Li-Jia and Li, Kai and Fei-Fei, Li},
booktitle={2009 IEEE conference on computer vision and pattern recognition},
pages={248--255},
year={2009},
organization={Ieee}
}
正在翻译中,请稍候...