模型:

facebook/maskformer-swin-tiny-ade

英文

MaskFormer

MaskFormer模型是在ADE20k语义分割数据集上训练得到的(小型版本,使用Swin骨干网络)。该模型在论文 Per-Pixel Classification is Not All You Need for Semantic Segmentation 中进行了介绍,并在 this repository 中首次发布。

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

模型描述

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

预期用途和限制

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

如何使用

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

from transformers import MaskFormerFeatureExtractor, 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)
feature_extractor = MaskFormerFeatureExtractor.from_pretrained("facebook/maskformer-swin-tiny-ade")
inputs = feature_extractor(images=image, return_tensors="pt")

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

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