模型:
facebook/maskformer-swin-tiny-coco
MaskFormer模型在COCO panoptic segmentation上进行训练(tiny版本,采用Swin骨干网络)。该模型首次在 this repository 中发布,并在 Per-Pixel Classification is Not All You Need for Semantic Segmentation 中进行了介绍。
免责声明:发布MaskFormer模型的团队并未为此模型编写模型卡片,因此该模型卡片由Hugging Face团队编写。
MaskFormer通过预测一组掩码和相应的标签,处理实例分割、语义分割和全景分割这三个任务。因此,这三个任务都被视为实例分割。
您可以使用此特定的检查点来进行语义分割。查看 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-tiny-coco") model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-tiny-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 。