模型:

microsoft/swin-large-patch4-window12-384-in22k

英文

Swin Transformer (大型模型)

Swin Transformer模型在ImageNet-21k(1400万张图像,21841个类别)上进行了预训练,分辨率为384x384。该模型由Liu等人在论文中引入,并于 this repository 首次发布。

免责声明:发布Swin Transformer的团队未为该模型编写模型卡片,因此这个模型卡片是由Hugging Face团队编写的。

模型描述

Swin Transformer是一种Vision Transformer类型的模型。它通过在更深层次中合并图像块(以灰色显示)来构建分层特征图,并且由于仅在每个局部窗口(以红色显示)内计算自注意力,其计算复杂度与输入图像大小呈线性关系。因此,它可以作为图像分类和密集识别任务的通用主干模型。相比之下,先前的Vision Transformers在全局范围内计算自注意力,生成单一低分辨率的特征图,并且其计算复杂度与输入图像大小呈二次关系。

Source

预期用途和限制

您可以使用原始模型进行图像分类。了解感兴趣的任务的Fine-tune版本,可以查看 model hub

如何使用

下面是如何使用该模型将COCO 2017数据集中的图像分类为其中一个1000个ImageNet类别的示例:

from transformers import AutoFeatureExtractor, SwinForImageClassification
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("microsoft/swin-large-patch4-window12-384-in22k")
model = SwinForImageClassification.from_pretrained("microsoft/swin-large-patch4-window12-384-in22k")

inputs = feature_extractor(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])

关于更多代码示例,请参阅 documentation

BibTeX条目和引用信息

@article{DBLP:journals/corr/abs-2103-14030,
  author    = {Ze Liu and
               Yutong Lin and
               Yue Cao and
               Han Hu and
               Yixuan Wei and
               Zheng Zhang and
               Stephen Lin and
               Baining Guo},
  title     = {Swin Transformer: Hierarchical Vision Transformer using Shifted Windows},
  journal   = {CoRR},
  volume    = {abs/2103.14030},
  year      = {2021},
  url       = {https://arxiv.org/abs/2103.14030},
  eprinttype = {arXiv},
  eprint    = {2103.14030},
  timestamp = {Thu, 08 Apr 2021 07:53:26 +0200},
  biburl    = {https://dblp.org/rec/journals/corr/abs-2103-14030.bib},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}