Skip to main content
Segment an image using OneFormer. Supports panoptic, semantic, and instance segmentation modes.

Parameters

image_input
str | PIL.Image | np.ndarray
required
RGB input image.
mode
str
required
Segmentation mode: "panoptic", "semantic", or "instance".
timeout
float | None
Optional HTTP timeout.

Returns

dict with keys:
  • output — Segmentation mask of shape (H, W)
  • label_map — Mapping of label IDs to class names
  • latency_ms — Server-side processing time

Example Output

OneFormer semantic segmentation output with label map

Example

from grid_cortex_client import CortexClient
import numpy as np
from PIL import Image

client = CortexClient()
img = Image.open("scene.jpg")  # 640x480 RGB
result = client.run(
    model_id="oneformer",
    image_input=img,
    mode="semantic",
)

print(result.keys())
# dict_keys(['output', 'label_map', 'latency_ms'])

print(result["output"].shape)
# (480, 640)

print(np.unique(result["output"]))
# [ 1  2  4  6 11 17 32 36 38 43 69 86]

print(result["label_map"])
# {1: 'building', 2: 'sky', 4: 'tree', 6: 'road, route',
#  11: 'sidewalk, pavement', 17: 'plant', 32: 'fence',
#  36: 'lamp', 38: 'rail', 43: 'signboard, sign'}

print(f"latency: {result['latency_ms']:.1f} ms")
# latency: 249.6 ms