模型:

facebook/mask2former-swin-large-coco-panoptic

英文

Mask2Former

Mask2Former模型是在COCO全景分割(大型版本,Swin骨干)上训练的。该模型在论文 Masked-attention Mask Transformer for Universal Image Segmentation 中进行了介绍,并于 this repository 首次发布。

免责声明:发布Mask2Former的团队没有为该模型编写模型卡片,因此本模型卡片是由Hugging Face团队撰写的。

模型描述

Mask2Former使用相同的范式处理实例、语义和全景分割:通过预测一组掩模和相应的标签。因此,这三个任务都被视为实例分割。Mask2Former通过 (i) 将像素解码器替换为更先进的多尺度可变形注意力Transformer、(ii) 采用具有掩码注意力的Transformer解码器以提高性能而不引入额外计算、(iii) 通过在子采样点上计算损失而不是整个掩模来提高训练效率等方式,在性能和效率方面均优于先前的SOTA模型 MaskFormer

预期使用和限制

您可以使用此特定的检查点进行全景分割。查看 model hub 以寻找您感兴趣的其他任务的微调版本。

如何使用

以下是如何使用此模型的方法:

import requests
import torch
from PIL import Image
from transformers import AutoImageProcessor, Mask2FormerForUniversalSegmentation


# load Mask2Former fine-tuned on COCO panoptic segmentation
processor = AutoImageProcessor.from_pretrained("facebook/mask2former-swin-large-coco-panoptic")
model = Mask2FormerForUniversalSegmentation.from_pretrained("facebook/mask2former-swin-large-coco-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"]

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