license: apache-2.0
tags:
- 视觉
- 图像分类
datasets:
- imagenet-1k
widget:
- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/tiger.jpg
example_title: 老虎
- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/teapot.jpg
example_title: 茶壶
- src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg
example_title: 宫殿
金字塔视觉变换器(微型尺寸模型)
金字塔视觉变换器(PVT)模型在ImageNet-1K(100万张图像,1000个类别)上以224x224分辨率进行了预训练,并在ImageNet 2012(100万张图像,1000个类别)上以224x224分辨率进行了微调。该模型由Wenhai Wang、Enze Xie、Xiang Li、Deng-Ping Fan、Kaitao Song、Ding Liang、Tong Lu、Ping Luo、Ling Shao在论文《金字塔视觉变换器:一种无需卷积的密集预测通用骨干网络》中提出,并首次发布于此代码库。
免责声明:发布PVT的团队未为此模型编写模型卡片,因此本模型卡片由Rinat S. [@Xrenya]编写。
模型描述
金字塔视觉变换器(PVT)是一种在ImageNet-1k(也称为ILSVRC2012)上预训练的变换器编码器模型(类似BERT),该数据集包含100万张图像和1000个类别,分辨率同样为224x224。
图像以可变大小的补丁序列形式输入模型,这些补丁经过线性嵌入。与ViT模型不同,PVT使用渐进式缩小金字塔来减少每个阶段对大特征图的计算。此外,在序列开头添加了一个[CLS]标记用于分类任务,并在将序列输入变换器编码器层之前添加了绝对位置嵌入。
通过预训练,模型学习到图像的内在表示,可用于提取下游任务所需的特征:例如,如果您有一个带标签的图像数据集,可以在预训练编码器顶部放置一个线性层来训练标准分类器。通常会在[CLS]标记顶部放置一个线性层,因为该标记的最后隐藏状态可以被视为整个图像的表示。
预期用途与限制
您可以将原始模型用于图像分类。请查看模型中心以寻找您感兴趣任务的微调版本。
使用方法
以下是如何使用此模型将COCO 2017数据集中的一张图像分类为1000个ImageNet类别之一:
from transformers import PvtImageProcessor, PvtForImageClassification
from PIL import Image
import requests
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)
processor = PvtImageProcessor.from_pretrained('Zetatech/pvt-tiny-224')
model = PvtForImageClassification.from_pretrained('Zetatech/pvt-tiny-224')
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
predicted_class_idx = logits.argmax(-1).item()
print("预测类别:", model.config.id2label[predicted_class_idx])
更多代码示例,请参阅文档。
训练数据
ViT模型在ImageNet-1k上进行了预训练,该数据集包含100万张图像和1000个类别。
训练过程
预处理
训练/验证期间图像预处理的具体细节可在此处找到。
图像被调整大小/缩放到相同的分辨率(224x224),并在RGB通道上以均值(0.485, 0.456, 0.406)和标准差(0.229, 0.224, 0.225)进行归一化。
BibTeX条目和引用信息
@inproceedings{wang2021pyramid,
title={Pyramid vision transformer: A versatile backbone for dense prediction without convolutions},
author={Wang, Wenhai and Xie, Enze and Li, Xiang and Fan, Deng-Ping and Song, Kaitao and Liang, Ding and Lu, Tong and Luo, Ping and Shao, Ling},
booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
pages={568--578},
year={2021}
}