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

> Segment an image using OneFormer

Segment an image using OneFormer.

## Parameters

<ParamField body="image_input" type="Union[str, Image.Image, np.ndarray]" required>
  RGB input image.
</ParamField>

<ParamField body="mode" type="str" default="'panoptic'">
  "panoptic", "semantic" or "instance".
</ParamField>

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

## Returns

Dict\[str, Any]: Backend-specific segmentation output.

## Example

```python theme={null}
from grid_cortex_client import CortexClient, ModelType
import numpy as np
from PIL import Image
client = CortexClient()
image = np.array(Image.open("cat.jpg"))
result = client.run(ModelType.ONEFORMER, image_input=image, mode="semantic")
```

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

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


## Related topics

- [oneformer](/models/cortex/oneformer.md)
