模型:
shi-labs/oneformer_ade20k_swin_tiny
OneFormer模型是在ADE20k数据集上训练的(tiny-sized版本,Swin骨干)。该模型在Jain等人的论文 OneFormer: One Transformer to Rule Universal Image Segmentation 中首次提出,并在 this repository 中首次发布。
OneFormer是第一个多任务通用图像分割框架。它只需要使用单个通用架构、单个模型和单个数据集进行训练,就能在语义、实例和全景分割任务上胜过现有的专用模型。OneFormer使用任务标记来使模型针对特定任务进行训练,从而使架构在训练过程中具有任务引导的特性,在推理过程中能够根据任务的变化而动态调整,而这一切都只需要一个模型。
您可以使用该特定检查点进行语义、实例和全景分割。请参阅 model hub 以查找在不同数据集上进行微调的其他版本。
这是如何使用该模型的方法:
from transformers import OneFormerProcessor, OneFormerForUniversalSegmentation from PIL import Image import requests url = "https://huggingface.co/datasets/shi-labs/oneformer_demo/blob/main/ade20k.jpeg" image = Image.open(requests.get(url, stream=True).raw) # Loading a single model for all three tasks processor = OneFormerProcessor.from_pretrained("shi-labs/oneformer_ade20k_swin_tiny") model = OneFormerForUniversalSegmentation.from_pretrained("shi-labs/oneformer_ade20k_swin_tiny") # Semantic Segmentation semantic_inputs = processor(images=image, task_inputs=["semantic"], return_tensors="pt") semantic_outputs = model(**semantic_inputs) # pass through image_processor for postprocessing predicted_semantic_map = processor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0] # Instance Segmentation instance_inputs = processor(images=image, task_inputs=["instance"], return_tensors="pt") instance_outputs = model(**instance_inputs) # pass through image_processor for postprocessing predicted_instance_map = processor.post_process_instance_segmentation(outputs, target_sizes=[image.size[::-1]])[0]["segmentation"] # Panoptic Segmentation panoptic_inputs = processor(images=image, task_inputs=["panoptic"], return_tensors="pt") panoptic_outputs = model(**panoptic_inputs) # pass through image_processor for postprocessing predicted_semantic_map = processor.post_process_panoptic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]["segmentation"]
更多示例,请参阅 documentation 。
@article{jain2022oneformer, title={{OneFormer: One Transformer to Rule Universal Image Segmentation}}, author={Jitesh Jain and Jiachen Li and MangTik Chiu and Ali Hassani and Nikita Orlov and Humphrey Shi}, journal={arXiv}, year={2022} }