Mask2Former模型基于COCO全景分割(小尺寸版本,Swin骨干网络)进行训练。该模型在论文中介绍,并在 this repository 中首次发布。
声明:发布Mask2Former模型的团队没有为该模型编写模型卡片,因此该模型卡片是由Hugging Face团队编写的。
Mask2Former使用相同的方法处理实例、语义和全景分割:通过预测一组掩码和相应的标签。因此,将这3个任务都视为实例分割。Mask2Former通过以下方式优于以前的SOTA模型 MaskFormer ,既提高了性能和效率:(i)用更先进的多尺度可变形注意力Transformer替换像素解码器,(ii)采用具有掩蔽注意力的Transformer解码器以提高性能,而不引入额外的计算,(iii)通过在子采样点上计算损失而不是整个掩码来提高训练效率。
您可以将此特定检查点用于全景分割。查看 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-small-coco-panoptic") model = Mask2FormerForUniversalSegmentation.from_pretrained("facebook/mask2former-swin-small-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 。