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 Wherobots Cloud.
  2. Start a runtime.
  3. Open the notebook.
  4. In the Jupyter Launcher:
    1. Click File > Open Path.
    2. Paste the following path to access this notebook: examples/Analyzing_Data/RasterFlow_ChangeDetection.ipynb
    3. Click Enter.
This notebook demonstrates RasterFlow’s change detection inference workflow using the Fields of the World (FTW)1 model as an example. Related notebooks:

Why Fields of the World (FTW)?

FTW predicts 3 classes (non_field_background, field, field_boundaries). While FTW is a field boundary segmentation model (not a true change detection model), it takes bi-temporal input (two seasons), making it useful for demonstrating change detection.

Model signature

Change detection models receive multi-temporal imagery stacked along the channel dimension:
We’ll use a particular Actor to run change detection inference using Rasterflow: semantic_segmentation_change_detection_pytorch.

Selecting an Area of Interest (AOI)

To start, we will choose an Area of Interest (AOI) for our analysis. The area around Haskell County, Kansas has some interesting crop field patterns so we will try out the model there.

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 the URI of its output. Call wb.tasks.get("<task name>").input_schema to see every input a task accepts.

Building two annual median composites

Use s2_median with median_compositing_interval="annual" to create the two input time steps needed by this model. The UTC request [2023-01-01, 2025-01-01) produces medians for [2023-01-01, 2024-01-01) and [2024-01-01, 2025-01-01), labelled 2023-01-01 and 2024-01-01. Without explicit annual grouping, s2_median produces one median over the entire request window. That output would have only one time step and would not meet this example’s two-time-step input contract. RasterFlow applies quality filtering and cloud masking before computing per-pixel medians and writing the Zarr store. Reflectance bands use the s2_median prefix.
Inspect the Zarr store with xarray. The annual grouping creates two time steps, labelled 2023-01-01 and 2024-01-01, for this change-detection example.
We can also see what bands are included in the mosaic.

Mosaic Inference

Now that we have built the mosaic and understand the features that were included, we can run the run_mosaic_inference task. We’ll pass in the band names we want to predict, as well as other inference configs that specify how to run inference.
  • mosaic_uri is the mosaic we just created for sentinel-2
  • model_path can be a path to a Pytorch 2 Archive file on s3 or Huggingface. In this case we’ll use the Fields of the World model from the Wherobots’ Huggingface Collection.
  • patch_size controls the XY size of the array input to the model
  • clip_size in conjunction with merge_mode, controls how to run overlapping windowed inference to reduce edge effects relative to non-overlapping inference
  • device specifies what device to use for running inference. Our runtimes are GPU only at this time, but you could run on the CPU device if you wanted to!
  • features selects what bands and in what order to run inference on
  • labels sets the labels on the models output. Order matters here based on what your model returns!
  • actor determines the kind of inference handler to use. The correct actor to select depends on the task your model is solving and the kind of input it expects. For change detection, we support models that take in an input where time and channels dimensions are stacked together. So the channel dimension is ordered like so in in this example:
  • max_batch_size: Maximum number of patches fed through the model in a single forward pass.
    • Higher values = better GPU utilization but more GPU memory required
    • Lower values = less memory but potentially slower inference

(Optional) Build an optimized Zarr for visualization

RasterFlow writes its outputs as Zarr stores at native resolution. To explore them interactively on cloud.wherobots.com/map, you can build an optimized multiscale Zarr. build_zarr_multiscales adds downsampled overview levels (image pyramids) to the store so the map can stream coarse tiles when zoomed out and full-resolution pixels when zoomed in. This step is optional and can take a few minutes for large outputs, so the code below is commented out by default — uncomment it to run it. Pass aoi to select a chunk-aligned bounding window from a single Zarr source. It accepts polygon or multipolygon WKT in EPSG:4326, or an S3 GeoJSON or GeoParquet URI with a CRS. Pixels outside the polygon remain within that rectangular window. Omit aoi to process the full store.
Let’s check out our mosaic result with xarray to see what a Zarr change detection store looks like.
The prediction result mosaic is shaped similar to the input, height and width are the same. Rather than have 4 bands, it has 3 bands for the prediction result, representing the categories. The FTW model outputs 3 categories, whereas other models may output a binary classification and there will be only one prediction band. Instead of 2 time steps, there is only 1, representing the change interval. We index the time coordinate of the Zarr store using the start date used to build the input mosaic. We also store a time delta coordinate to represent the interval of time between the start_date and end_date.

Visualizing outputs

You can visualize the Zarr, GeoParquet, and other geospatial outputs using cloud.wherobots.com/map.

Vectorize the raster model outputs

The output for the FTW model is a raster with three classes as bands: field, field_boundaries, and non_field_background. We will run a separate flow to convert the fields and field boundaries into vector geometries. Converting these results to geometries allows us to more easily post process the results or join the results with other vector data.

Save the vectorized results to the catalog

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

Visualize the vectorized results

To visualize the vectorized results, we will show the fields around Plymell, Kansas and filter out results with a score lower than 0.5. This threshold was determined through observation to strike a balance: it eliminates obvious noise without being overly aggressive, ensuring that we don’t accidentally filter out too many relevant results.
We will apply some WherobotsDB vector post processing operations to refine the model results.

Generate PM Tiles for visualization

To improve visualization performance of a large number of geometries, we can use Wherobots built-in high performance PM tile generator. The FTW model has a tendency to create extremely large boundary geometries, which doesn’t play nicely with PMTiles. To avoid this we subdivide the boundary geometries.

Viewing the PMTiles on the Wherobots Cloud map

Open the PMTiles archive on cloud.wherobots.com/map with the link printed below. The map reads the archive from your storage with your Wherobots credentials, so you don’t need a pre-signed URL.

References

  1. Kerner, H., Chaudhari, S., Ghosh, A., Robinson, C., Ahmad, A., Choi, E., Jacobs, N., Holmes, C., Mohr, M., et al. (2024). Fields of The World: A Machine Learning Benchmark Dataset For Global Agricultural Field Boundary Segmentation. arXiv preprint arXiv:2409.16252. Accepted at AAAI-2025 Artificial Intelligence for Social Impact (AISI) track.
  2. ESA. (2015). Sentinel-2 User Handbook (Issue 1, Rev. 2). European Space Agency. https://sentinels.copernicus.eu/documents/247904/685211/Sentinel-2_User_Handbook