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

# Grounded SAM 2

<Note>
  This page documents the `grid.model.*` local inference wrapper. For cloud-hosted inference via **GRID Cortex**, see the [Cortex GSAM2 page](/models/cortex/gsam2).
</Note>

The `GSAM2` class provides a wrapper for the GSAM2 model, which combines the power of Grounding DINO for text-based object detection with SAM2 for high-precision segmentation in RGB images.

<ResponseField name="class GSAM2()">
  <ResponseField name="use_local" type="boolean" default="False">
    If True, inference call is run on the local VM, else offloaded onto GRID-Cortex. Defaults to False.
  </ResponseField>
</ResponseField>

<ResponseField name="def run()">
  <ResponseField name="rgbimage" type="np.ndarray" required="True">
    The input RGB image of shape $(M, N, 3)$.
  </ResponseField>

  <ResponseField name="prompt" type="str" required="True">
    The text prompt to use for segmentation.
  </ResponseField>

  <ResponseField name="Returns" type="np.ndarray">
    The predicted segmentation mask of shape $(M, N)$.
  </ResponseField>
</ResponseField>

<RequestExample>
  ```python Inference Call theme={null}
  from grid.model.perception.segmentation.gsam2 import GSAM2
  car = AirGenCar()

  # We will be capturing an image from the AirGen simulator 
  # and run model inference on it.

  img =  car.getImage("front_center", "rgb").data

  model = GSAM2(use_local = False)
  result = model.run(rgbimage=img, prompt=<prompt>)
  print(result.shape)
  ```
</RequestExample>

<Tabs>
  <Tab title="License">
    This code is licensed under the Apache 2.0 and BSD-3 License.
  </Tab>

  <Tab title="Source">
    [https://github.com/IDEA-Research/GroundingDINO](https://github.com/IDEA-Research/GroundingDINO)
  </Tab>
</Tabs>
