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

# gsam2

> Segment objects in image using text prompt

Segment objects in image using text prompt.

> [!NOTE]
>
> Input images up to **1280 x 720** (width x height). Larger images are rejected with HTTP 413, not downscaled — resize first.

## Parameters

**image\_input** `ImageInput` *required*

RGB image as file path, URL, PIL Image, or numpy array.

**prompt** `str` *required*

Text description of objects to segment.

**box\_threshold** `float | None`

Optional confidence threshold (0.0-1.0) for filtering detections.

**text\_threshold** `float | None`

Optional text confidence threshold (0.0-1.0).

**nms\_threshold** `float | None`

Optional Non-Maximum-Suppression threshold (0.0-1.0).

**timeout** `float | None`

Optional timeout in seconds for the HTTP request.

## Returns

np.ndarray: Binary segmentation mask as numpy array (H, W) with dtype uint8.
Foreground pixels are 255, background pixels are 0.

## 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"))
mask = client.run(ModelType.GSAM2, image_input=image, prompt="a cat")
print(mask.shape)  # (480, 640)
```

Combines Grounding DINO with SAM 2.

## Example Output

![GSAM2 text-prompted segmentation output](https://mintcdn.com/scaledfoundations/lgZgGQWKvUIw0C7n/assets/images/cortex/gsam2-output.jpg?fit=max\&auto=format\&n=lgZgGQWKvUIw0C7n\&q=85\&s=99dcf4265e0428fcfedc420540a52dd8)

```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
mask = client.run(model_id="gsam2", image_input=img, prompt="street")

print(mask.shape, mask.dtype)
# (480, 640) uint8

foreground = np.count_nonzero(mask)
print(f"foreground pixels: {foreground} ({foreground / mask.size * 100:.1f}%)")
# foreground pixels: 138737 (45.2%)
```


## Related topics

- [GRID Cortex Client](https://docs.generalrobotics.dev/models/cortex.md)
- [AsyncCortexClient](https://docs.generalrobotics.dev/python-api/grid-cortex-client/asynccortexclient.md)
- [CortexClient](https://docs.generalrobotics.dev/python-api/grid-cortex-client/cortexclient.md)
- [CortexHubClient](https://docs.generalrobotics.dev/python-api/grid-cortex-client/cortexhubclient.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.