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 an image using OneFormer
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")
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
Was this page helpful?