模型:

facebook/maskformer-swin-small-coco

英文

MaskFormer

MaskFormer模型基于COCO全景分割进行训练(小型版本,Swin骨干结构)。它在 Per-Pixel Classification is Not All You Need for Semantic Segmentation 论文中被提出,并于 this repository 首次发布。

免责声明:发布MaskFormer的团队未针对该模型撰写模型卡片,因此此模型卡片由Hugging Face团队编写。

模型描述

MaskFormer使用相同的范式来处理实例、语义和全景分割:通过预测一组掩膜和相应的标签来处理这3个任务。因此,所有这3个任务都被视为实例分割。

预期使用和限制

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

使用方法

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

from transformers import MaskFormerFeatureExtractor, MaskFormerForInstanceSegmentation
from PIL import Image
import requests

# load MaskFormer fine-tuned on COCO panoptic segmentation
feature_extractor = MaskFormerFeatureExtractor.from_pretrained("facebook/maskformer-swin-small-coco")
model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco")

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
inputs = feature_extractor(images=image, return_tensors="pt")

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 feature_extractor for postprocessing
result = feature_extractor.post_process_panoptic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
# we refer to the demo notebooks for visualization (see "Resources" section in the MaskFormer docs)
predicted_panoptic_map = result["segmentation"]

更多代码示例,请参阅 documentation