许可协议:MIT
标签:
- 视觉
- 图像分割
数据集:
- huggan/cityscapes
示例展示:
- 图片链接:https://huggingface.co/datasets/shi-labs/oneformer_demo/blob/main/cityscapes.png
示例标题:城市景观
OneFormer
基于Cityscapes数据集训练(大尺寸版本,Swin骨干网络)的OneFormer模型。该模型由Jain等人在论文《OneFormer:统一图像分割的单一Transformer》中提出,并首次发布于此代码库。

模型描述
OneFormer是首个多任务通用图像分割框架。仅需通过单一通用架构、单一模型和单一数据集训练一次,即可在语义分割、实例分割和全景分割任务上超越现有专用模型。OneFormer利用任务令牌(task token)引导模型聚焦当前任务,使架构在训练时具备任务导向性,在推理时实现任务动态切换,仅需单一模型即可完成。

适用范围与限制
此特定检查点可用于语义分割、实例分割和全景分割任务。访问模型中心可查看基于其他数据集微调的版本。
使用方法
使用方式如下:
from transformers import OneFormerProcessor, OneFormerForUniversalSegmentation
from PIL import Image
import requests
url = "https://huggingface.co/datasets/shi-labs/oneformer_demo/blob/main/cityscapes.png"
image = Image.open(requests.get(url, stream=True).raw)
processor = OneFormerProcessor.from_pretrained("shi-labs/oneformer_cityscapes_swin_large")
model = OneFormerForUniversalSegmentation.from_pretrained("shi-labs/oneformer_cityscapes_swin_large")
semantic_inputs = processor(images=image, task_inputs=["semantic"], return_tensors="pt")
semantic_outputs = model(**semantic_inputs)
predicted_semantic_map = processor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
instance_inputs = processor(images=image, task_inputs=["instance"], return_tensors="pt")
instance_outputs = model(**instance_inputs)
predicted_instance_map = processor.post_process_instance_segmentation(outputs, target_sizes=[image.size[::-1]])[0]["segmentation"]
panoptic_inputs = processor(images=image, task_inputs=["panoptic"], return_tensors="pt")
panoptic_outputs = model(**panoptic_inputs)
predicted_semantic_map = processor.post_process_panoptic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]["segmentation"]
更多示例请参阅文档。
引用
@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}
}