Mask2Former模型,采用Swin骨干,在Cityscapes数据集上训练,适用于实例分割任务,通过多尺度可变形注意力Transformer提升性能与效率。【此简介由AI生成】
以下内容由 AI 翻译,如有问题请 点此提交 issue 反馈
license: other tags:
- vision
- image-segmentation datasets:
- coco widget:
- src: http://images.cocodataset.org/val2017/000000039769.jpg example_title: Cats
- src: http://images.cocodataset.org/val2017/000000039770.jpg example_title: Castle
Mask2Former
Mask2Former模型基于Cityscapes实例分割数据集训练(base-IN21k版本,Swin主干网络)。该模型由论文Masked-attention Mask Transformer for Universal Image Segmentation提出,并首次发布于此代码库。
免责声明:Mask2Former发布团队未提供本模型的模型卡,本文档由Hugging Face团队编写。
模型描述
Mask2Former采用统一范式处理实例分割、语义分割和全景分割任务:通过预测一组掩码及对应标签来实现。因此,所有三项任务均被视作实例分割处理。该模型在性能和效率上均超越前代SOTA模型MaskFormer,其创新包括:(i) 采用更先进的多尺度可变形注意力Transformer替代像素解码器;(ii) 通过引入掩码注意力机制的Transformer解码器提升性能且不增加计算量;(iii) 通过对采样点而非完整掩码计算损失来提升训练效率。

适用范围与限制
该特定检查点可用于实例分割任务。欢迎访问模型中心探索其他针对特定任务的微调版本。
使用方法
使用本模型的方式如下:
import requests
import torch
from PIL import Image
from transformers import AutoImageProcessor, Mask2FormerForUniversalSegmentation
# load Mask2Former fine-tuned on Cityscapes instance segmentation
processor = AutoImageProcessor.from_pretrained("facebook/mask2former-swin-base-IN21k-cityscapes-instance")
model = Mask2FormerForUniversalSegmentation.from_pretrained("facebook/mask2former-swin-base-IN21k-cityscapes-instance")
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
# model predicts class_queries_logits of shape `(batch_size, num_queries)`
# and masks_queries_logits of shape `(batch_size, num_queries, height, width)`
class_queries_logits = outputs.class_queries_logits
masks_queries_logits = outputs.masks_queries_logits
# you can pass them to processor for postprocessing
result = processor.post_process_instance_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
# we refer to the demo notebooks for visualization (see "Resources" section in the Mask2Former docs)
predicted_instance_map = result["segmentation"]
如需更多代码示例,请参阅文档。