模型:
facebook/maskformer-swin-large-coco
MaskFormer模型是在COCO panoptic分割上训练的(大尺寸版本,Swin骨干)。它在论文 Per-Pixel Classification is Not All You Need for Semantic Segmentation 中进行了介绍,并于 this repository 首次发布。
免责声明:发布MaskFormer的团队未为此模型编写模型卡片,因此此模型卡片由Hugging Face团队编写。
MaskFormer用相同的范式解决了实例、语义和全景分割:通过预测一组掩码和相应的标签。因此,所有三个任务都被视为实例分割。
您可以使用此特定检查点进行语义分割。查看 model hub 可以查找您感兴趣的其他微调版本的任务。
下面是如何使用此模型的方法:
from transformers import MaskFormerImageProcessor, MaskFormerForInstanceSegmentation from PIL import Image import requests # load MaskFormer fine-tuned on COCO panoptic segmentation processor = MaskFormerImageProcessor.from_pretrained("facebook/maskformer-swin-large-coco") model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-large-coco") url = "http://images.cocodataset.org/val2017/000000039769.jpg" image = Image.open(requests.get(url, stream=True).raw) inputs = processor(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 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 MaskFormer docs) predicted_panoptic_map = result["segmentation"]
更多代码示例,请参阅 documentation 。