模型:
facebook/maskformer-swin-base-ade
在ADE20k语义分割数据集上训练的MaskFormer模型(基本尺寸版本,使用Swin骨干)。该模型首次发布于 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-base-ade") inputs = feature_extractor(images=image, return_tensors="pt") model = MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-base-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 。