模型:

facebook/maskformer-swin-large-ade

英文

MaskFormer

在ADE20k语义分割上训练的MaskFormer模型(大型版本,使用Swin骨干)。 它在论文 Per-Pixel Classification is Not All You Need for Semantic Segmentation 中介绍,并于 this repository 首次发布。

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

模型描述

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

拟合使用和限制

您可以使用此特定检查点进行语义分割。请参阅 model hub ,以查找您感兴趣的其他微调版本的任务。

如何使用

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

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

url = "https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg"
image = Image.open(requests.get(url, stream=True).raw)

processor = MaskFormerImageProcessor.from_pretrained("facebook/maskformer-swin-large-ade")
inputs = processor(images=image, return_tensors="pt")

model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-large-ade")
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
# we refer to the demo notebooks for visualization (see "Resources" section in the MaskFormer docs)
predicted_semantic_map = processor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]

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