Skip to main content
Public Preview
The following content is a read-only preview of an executable Jupyter notebook.To run this notebook interactively:
  1. Go to Models in Wherobots Cloud.
  2. Select the model whose notebook you wish to run.
  3. Click Try it, select the Solution notebook tab, then click Open the solution notebook.
sam3 banner This notebook will guide you through detecting objects in aerial imagery using text prompts, powered by Wherobots RasterFlow and Meta’s Segment Anything Model 3 (SAM3). You will gain a hands-on understanding of how to run geometry inference on your selected area of interest, work with the detected geometries, and visualize the results in WherobotsDB.

SAM3

SAM3 is a text-prompted geometry inference model that detects objects in imagery based on natural language descriptions. Given a text prompt like "building" or "roofs", the model produces georeferenced vector geometries (bounding boxes or polygons) for each detected object, along with a confidence score. Unlike segmentation models that produce raster outputs, SAM3 directly outputs vector geometries, making it straightforward to integrate results into geospatial workflows. We will demonstrate results using 30cm resolution data from the National Agriculture Imagery Program (NAIP).

Preview: model inputs and outputs

The interactive map linked below is an example run over Marion County, Oregon, showing the input imagery and model output at county scale. This notebook runs over a smaller AOI, College Park, Maryland, so your own output will cover a different area. Toggle layers in the sidebar to compare the input imagery with the model’s PMTiles output side-by-side. Layers (top layer first, as in the map’s layer list):
  • SAM3 PM Tiles: Polygons output directly by the text-prompted model, delivered as PMTiles for fast rendering at scale (SAM3 is a geometry inference model, so there is no intermediate raster output)
  • SAM3 input mosaic: RGB NAIP aerial imagery the model runs on
View the interactive map here.

Selecting an Area of Interest (AOI)

To start, we will choose an Area of Interest (AOI) for our analysis where 30cm resolution NAIP data is available: College Park, Maryland.

Selecting a time range and verifying NAIP coverage

Because NAIP collects state-level imagery at mixed resolutions, SAM3’s required 30cm data may not exist for your selected AOI or timeframe. The USDA’s NAIP coverage map (PDF, 2002-2025) shows what is available where.

Using the Wherobots Tasks API

Each RasterFlow workflow runs as a task through the Wherobots Python SDK. run_task below starts a task run, waits for it to finish, and returns its output value. Recipes return an object with input_mosaic and result; standalone tasks return a URI. Call wb.tasks.get("<task name>").input_schema to see every input a task accepts.

Running geometry inference

RasterFlow has pre-defined recipes that simplify orchestration of the processing steps for geometry inference. These steps include:
  • Ingesting imagery for the specified Area of Interest (AOI)
  • Generating a seamless mosaic from multiple image tiles
  • Running text-prompted geometry inference with the SAM3 model
The recipe returns input_mosaic for the source imagery and result for the detections. input_mosaic contains mosaic_index_uri for the imagery index and first_row_mosaic for its first Zarr store. result is the URI of a GeoParquet dataset of detected geometries with confidence scores, or None if no geometries are detected. Note: This step will take approximately 22 minutes to complete the first time it is run.

Explore the detected geometries

The geometry inference output is GeoParquet, which we read with WherobotsDB. Each row is a detected object. The columns include:
  • geometry: the georeferenced polygon for the detection
  • label: the text prompt category (e.g. "roofs")
  • bbox_score: confidence score for the detection
  • bbox: bounding box coordinates
  • time: timestamp of the source imagery

Save the results to the catalog

We can store these geometry outputs in the catalog using WherobotsDB to persist the GeoParquet results.

Visualize the detected geometries

We can filter the detections by area to remove noise, then visualize the results.

Optional: join partitioned detections

A single object can produce touching or overlapping polygons at inference patch boundaries. If you need one geometry per connected object, run this downstream WherobotsDB step on the raw detections. RasterFlow recipes do not join polygons automatically. This extra spatial computation takes time and compute, including session startup if WherobotsDB is not already running. ST_IntersectsCC assigns a component ID to each chain of intersecting geometries. Running it on one label at a time keeps different prompt labels separate. Passing the label as the function’s partition column also separates them, but it bypasses the spatial index and compares every pair of detections with the same label. The union dissolves each component into a geometry. It does not bridge gaps, and it can also join distinct same-label objects that touch or overlap, even through a chain of detections. Inspect the result before using it as an object count. Component IDs are for grouping within this computation, not persistent object identifiers. The joined output retains the label and fragment count, but not per-detection confidence scores or timestamps. First, check the operation with touching fragments, a separate object, and an overlapping different label. The different label also spans the gap between the roof objects, so it must not connect them.
Now join the unfiltered SAM3 detections and compare the raw and joined layers. The two layers cover the same detections; toggle them to inspect the boundaries. This map uses a basemap, which may differ from the imagery used for inference.

Generate PM Tiles for visualization

To improve visualization performance of a large number of geometries, we can use the Wherobots built-in high performance PM tile generator.