> ## Documentation Index
> Fetch the complete documentation index at: https://docs.generalrobotics.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# OneFormer

> Universal segmentation — panoptic or semantic

Segment an image using OneFormer. Supports panoptic and semantic segmentation modes.

## Parameters

<ParamField body="image_input" type="str | PIL.Image | np.ndarray" required>
  RGB input image.
</ParamField>

<ParamField body="mode" type="str">
  Segmentation mode: `"panoptic"` (default) or `"semantic"`.
</ParamField>

<ParamField body="timeout" type="float | None">
  Optional HTTP timeout.
</ParamField>

## 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

<img src="https://mintcdn.com/scaledfoundations/lgZgGQWKvUIw0C7n/assets/images/cortex/oneformer-output.jpg?fit=max&auto=format&n=lgZgGQWKvUIw0C7n&q=85&s=b2fb4fd6b5229ed9253c3891cc4fad2c" alt="OneFormer semantic segmentation output with label map" width="1248" height="552" data-path="assets/images/cortex/oneformer-output.jpg" />

## Example

```python theme={null}
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
```
