采用Masked-attention Mask Transformer架构,以Swin为骨干,在Cityscapes数据集上训练,高效处理全景分割任务,性能与效率优于前代SOTA。【此简介由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
此模型为基于 Cityscapes 全景分割数据集训练的 Mask2Former(微型版本,采用 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 panoptic segmentation
processor = AutoImageProcessor.from_pretrained("facebook/mask2former-swin-tiny-cityscapes-panoptic")
model = Mask2FormerForUniversalSegmentation.from_pretrained("facebook/mask2former-swin-tiny-cityscapes-panoptic")
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_panoptic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
# we refer to the demo notebooks for visualization (see "Resources" section in the Mask2Former docs)
predicted_panoptic_map = result["segmentation"]
如需更多代码示例,请参阅文档。