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.

Segmenting almost any object with a prompt, no task-specific training needed

1. Context

L07 and L08 trained semantic segmentation and instance segmentation models from labeled data you prepared yourself. This lesson introduces a different starting point: a foundation model, the Segment Anything Model (SAM), pre-trained on over a billion masks, that segments objects it has never specifically been trained on, with no task-specific training required from you at all.

This does not make earlier lessons obsolete. It shifts where your effort goes. Instead of spending time on labeling and training, you spend it on prompt design and quality control, deciding what to ask the model for, and how much to trust what it returns.


2. Motivation

Building a training dataset for something like building footprint extraction in a single city already takes real effort: digitizing hundreds of outlines, keeping annotators consistent, then hoping the model generalizes to a different city with different roof materials and imaging conditions. A foundation model changes this calculus. The same pre-trained model can plausibly delineate buildings in Nairobi, fields in Iowa, and rivers in the Amazon without a single labeled example from any of those places.

For a project with limited time, this means initial segmentation results in minutes rather than weeks. It does not remove the need for domain judgment or quality control, a theme this entire lesson returns to repeatedly, but it dramatically lowers the cost of getting a first result to evaluate.


3. Learning objectives

By the end of this lesson, you should be able to:


4. Lesson roadmap

  1. When Segment Anything fits — where zero-shot segmentation is genuinely useful, and where a trained model still wins.

  2. SAM concepts & prompts — the image encoder, prompt encoder, mask decoder, and the “encode once, prompt cheaply” workflow.

  3. samgeo setup & outputs — bridging SAM to georeferenced data: setup, access, and geospatial output formats.

  4. Text, point & box prompts — the three main prompt types, and when each one fits best.

  5. Building extraction — the main hands-on workflow: point and box prompts, vectorization, and polygon regularization.

  6. Batch & tiled segmentation — scaling to multiple images and rasters too large for memory.

  7. Interactive & video segmentation — map-based interactive segmentation, and tracking objects across video frames.

  8. Project transfer — deciding whether Segment Anything fits your project, and planning your prompts and quality checks.

Pages 1–2 build the conceptual foundation, page 3 bridges to geospatial data, page 4 covers prompting, page 5 is the main hands-on workflow, and pages 6–7 extend it to scale and video. Page 8 transfers everything to your project.


5. Project framing

While reading this lesson, keep your own project in mind and consider:


6. Before class


7. After this lesson

After working through this lesson, you should have: