Running inference
We can use the trained segmentation models to extract site boundaries from satellite imagery.
The retrieve_shape_for_site.py script is a helper that:
- Converts the given coordinates to a square polygon, add some extra padding.
- Retrieve satellite imagery from
esriornaipand assembles a GeoTIFF. - Runs the segmentation model, extracting all site features in the image.
- Converts the mask into a GeoJSON (WGS84), ready to use in the platform.
As long as the tooling is set up correctly (Tools), it's straightforward to run the script.
- Download the model weights and place them in
models/. - Run the script, adjusting parameters as needed.
python scripts/retrieve_shape_for_site.py --model-weights models/model_final.pth --longitude "-103.73360747583735" --latitude "32.422276756574455" --provider esriParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
--provider | string | "naip" | Image provider to use. Options: "esri" or "naip". NAIP provides aerial imagery for the US, while ESRI provides global satellite imagery. |
--model-weights | string | Required | Path to the trained model weights file. Must be compatible with Detectron2 Mask R-CNN architecture. |
--padding | float | 60.0 | Buffer distance in meters around the specified coordinates. Controls the size of the area to retrieve and analyze. |
--cut-off | float | 0.7 | Confidence threshold for model predictions. Higher values result in fewer but more confident detections. |
--latitude | float | Required | Latitude coordinate (in decimal degrees) of the target location. |
--longitude | float | Required | Longitude coordinate (in decimal degrees) of the target location. |
--output-folder | string | "./output" | Directory where output files will be saved. Will be created if it doesn't exist. |
--zoom | integer | Provider-dependent | Zoom level for imagery retrieval. If not specified, defaults to 19 for ESRI and 18 for NAIP. Higher values provide more detailed imagery but cover smaller areas. |
--device | string | "cpu" | Device to run the model on. Options: "cpu" or "cuda". Use "cuda" for GPU acceleration if available. |
Outputs
| File | Location | Description |
|---|---|---|
{base_name}.geojson | Output folder | Final GeoJSON output containing detected features with confidence scores |
{base_name}.tif | _cache subfolder | Cached GeoTIFF image with geospatial information |
{base_name}.jpg | _cache subfolder | JPG version of the image used for model input |
{base_name}.geojson | _cache subfolder | Temporary GeoJSON file used for image retrieval |