Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Use existing segmentation models for rapid inference

1. Motivation

The previous two pages trained models from scratch on labeled data. Sometimes that is unnecessary: a well-suited pre-trained model can produce a usable mask with no custom training data or training time at all. Knowing when a ready-made, sensor-agnostic model is a reasonable shortcut, and knowing that “pre-trained” does not mean “beyond question,” is a practical skill in its own right, separate from knowing how to train a model yourself.


2. Core idea

A sensor-agnostic pre-trained model has already been trained, generally on a large and diverse dataset, to perform one specific task (water masking, cloud detection) across multiple sensor types. You supply your imagery and a description of its band order; the model returns a mask. This removes the data-preparation and training steps from your workflow.


3. Two sensor-agnostic examples

A. OmniWaterMask: Water segmentation

OmniWaterMask combines a sensor-agnostic deep learning model with a spectral water index and OpenStreetMap reference data, and supports multiple sensors including Sentinel-2, NAIP, Landsat, and others, all without any custom training.

band_order="sentinel2" tells the function how to map your specific input raster’s bands to the red, green, blue, and NIR channels the underlying model expects; a "naip" preset does the same for NAIP’s native band order. Passing output_vector runs vectorization and polygon smoothing in the same call, giving you a ready-to-use GeoDataFrame directly, without a separate vectorization step.

The source material also applies the water workflow to four-band NAIP imagery.

The band-order preset changes:

The model is reused, but the sensor-specific band mapping remains explicit.

B. OmniCloudMask: Cloud segmentation

Cloud contamination affects nearly all optical satellite analysis, which makes cloud masking a common, high-value use case for a pre-trained model. OmniCloudMask is sensor-agnostic and needs only red, green, and NIR bands, classifying every pixel into one of four categories:

ValueClass
0Clear
1Thick cloud
2Thin cloud
3Cloud shadow

For the sample Sentinel-2 raster:

Run:

red_band, green_band, and nir_band map your specific raster’s band indices to what the model expects, the same kind of mapping band_order handled for water segmentation. geoai.calculate_cloud_statistics() then summarizes what fraction of the scene falls into each of the four classes, useful for quickly deciding whether a scene is even worth analyzing further.

geoai.create_cloud_free_mask() then produces a simple usable/not-usable binary mask from these four classes, which you can use to screen out heavily clouded scenes before running any downstream analysis, such as the land-cover classification on the next page.


4. What still needs checking

Before trusting a pre-trained model’s output for a project deliverable, check at least three things: that your imagery’s sensor and resolution genuinely fall within what the model was designed for, that your band_order (or equivalent band-index arguments) actually matches your raster, and that a visual spot-check of the output against the source imagery looks reasonable, especially in regions your project cares about most. None of these checks require retraining anything; they simply require the same skepticism you would apply to a model you trained yourself.


5. Python reactivation

stats.items() iterates over a dictionary’s key-value pairs together, the same pattern used for splits dictionaries in earlier lessons, here used to format percentage values differently from raw pixel counts within a single loop.


6. Common pitfalls


7. Mini task

You need a water mask for a Landsat scene over an area with many small, seasonal ponds that OmniWaterMask has not been specifically validated on. What would you check before relying on the output for a project deliverable, and what would make you decide to train a custom model instead?

Sample solution

You would check whether OmniWaterMask’s supported sensors and resolution range genuinely include Landsat at the relevant resolution, confirm the correct band order for Landsat’s specific band layout, and visually compare the output mask against a few ponds you can identify by eye in the source imagery, particularly the smallest ones, since those are most likely to be missed. If the visual check shows the model consistently missing the small seasonal ponds that matter most for the project, that would be a reasonable signal to invest in a custom-trained model (following the earlier pages in this lesson) rather than relying on the pre-trained one.


8. Key takeaways

Further reading