模型:
facebook/maskformer-swin-base-coco
MaskFormer模型是在COCO千兆分割数据集上训练的(基础尺寸版本,使用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 # load MaskFormer fine-tuned on COCO panoptic segmentation feature_extractor = MaskFormerFeatureExtractor.from_pretrained("facebook/maskformer-swin-base-coco") model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-base-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 。