模型:

facebook/vit-msn-large-7

英文

Vision Transformer (large sized model) pre-trained with MSN (patch size of 7)

使用MSN方法进行预训练的 Vision Transformer (ViT) 模型。该模型在论文 Masked Siamese Networks for Label-Efficient Learning 中由Mahmoud Assran、Mathilde Caron、Ishan Misra、Piotr Bojanowski、Florian Bordes、Pascal Vincent、Armand Joulin、Michael Rabbat、Nicolas Ballas首次介绍,并于 this repository 首次发布。

免责声明:发布MSN的团队没有为该模型编写模型卡片,所以该模型卡片是由Hugging Face团队编写的。

模型描述

Vision Transformer (ViT) 是一个Transformer编码器模型(类似于BERT)。图像以固定大小的补丁序列的形式呈现给模型。

MSN采用了联合嵌入架构,将遮罩补丁的原型与未遮罩补丁的原型匹配。在这种设置下,他们的方法在低样本和极低样本情况下都能取得出色的性能。

通过预训练模型,它可以学习图像的内部表示,然后可以用于提取对下游任务有用的特征:例如,如果你有一个带有标签的图像数据集,可以在预训练编码器之上放置一个线性层来训练一个标准分类器。

目标用途和限制

您可以使用原始模型进行图像分类等下游任务。查看 model hub 寻找您感兴趣的不同版本的MSN预训练模型。当您的训练集中有一些标记样本时,该模型尤为有益。

如何使用

以下是如何使用此基础编码器的方法:

from transformers import AutoFeatureExtractor, ViTMSNModel
import torch
from PIL import Image
import requests

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)

feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/vit-msn-large-7")
model = ViTMSNModel.from_pretrained("facebook/vit-msn-large-7")
inputs = feature_extractor(images=image, return_tensors="pt")
with torch.no_grad():
    outputs = model(**inputs)
last_hidden_states = outputs.last_hidden_state

对于图像分类的微调,请使用 ViTMSNForImageClassification 类:

from transformers import AutoFeatureExtractor, ViTMSNForImageClassification
import torch
from PIL import Image
import requests

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)

feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/vit-msn-large-7")
model = ViTMSNForImageClassification.from_pretrained("facebook/vit-msn-large-7")

...

引用

@article{assran2022masked,
  title={Masked Siamese Networks for Label-Efficient Learning}, 
  author={Assran, Mahmoud, and Caron, Mathilde, and Misra, Ishan, and Bojanowski, Piotr, and Bordes, Florian and Vincent, Pascal, and Joulin, Armand, and Rabbat, Michael, and Ballas, Nicolas},
  journal={arXiv preprint arXiv:2204.07141},
  year={2022}
}