Skip to content

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:

  1. Converts the given coordinates to a square polygon, add some extra padding.
  2. Retrieve satellite imagery from esri or naip and assembles a GeoTIFF.
  3. Runs the segmentation model, extracting all site features in the image.
  4. 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.

  1. Download the model weights and place them in models/.
  2. 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 esri

Parameters

ParameterTypeDefaultDescription
--providerstring"naip"Image provider to use. Options: "esri" or "naip". NAIP provides aerial imagery for the US, while ESRI provides global satellite imagery.
--model-weightsstringRequiredPath to the trained model weights file. Must be compatible with Detectron2 Mask R-CNN architecture.
--paddingfloat60.0Buffer distance in meters around the specified coordinates. Controls the size of the area to retrieve and analyze.
--cut-offfloat0.7Confidence threshold for model predictions. Higher values result in fewer but more confident detections.
--latitudefloatRequiredLatitude coordinate (in decimal degrees) of the target location.
--longitudefloatRequiredLongitude coordinate (in decimal degrees) of the target location.
--output-folderstring"./output"Directory where output files will be saved. Will be created if it doesn't exist.
--zoomintegerProvider-dependentZoom 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.
--devicestring"cpu"Device to run the model on. Options: "cpu" or "cuda". Use "cuda" for GPU acceleration if available.

Outputs

FileLocationDescription
{base_name}.geojsonOutput folderFinal GeoJSON output containing detected features with confidence scores
{base_name}.tif_cache subfolderCached GeoTIFF image with geospatial information
{base_name}.jpg_cache subfolderJPG version of the image used for model input
{base_name}.geojson_cache subfolderTemporary GeoJSON file used for image retrieval