Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Segment objects in image using text prompt
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)
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%)
Was this page helpful?