模型:
microsoft/swin-large-patch4-window7-224
Swin Transformer模型在分辨率为224x224的ImageNet-1k数据集上进行了训练。该模型在刘等人的论文中首次提出,并在 this repository 中首次发布。
免责声明:发布Swin Transformer的团队并没有为这个模型撰写模型说明卡片,因此本模型说明卡片是由Hugging Face团队撰写的。
Swin Transformer是一种视觉Transformer模型。它通过将图像块(显示为灰色)在更深层次的网络中进行合并来构建分层特征图,并且由于只在每个局部窗口内计算自注意力(显示为红色),所以其对输入图像大小具有线性计算复杂度。因此,它可以作为图像分类和密集识别任务的通用骨干模型。相反,先前的视觉Transformer模型生成单一低分辨率的特征图,并且由于在全局范围内计算自注意力,其对输入图像大小具有二次计算复杂度。
您可以使用原始模型进行图像分类。请参考 model hub 以寻找您感兴趣的任务的微调版本。
下面是如何使用此模型将COCO 2017数据集中的图像分类为1,000个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-window7-224") model = SwinForImageClassification.from_pretrained("microsoft/swin-large-patch4-window7-224") 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 。
@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} }