Create object masks from input prompts with SAM

In this notebook, you will learn how to create object masks from input prompts using the Segment Anything Model (SAM).

Previous article: Use Segment Anything Model (SAM) for Geospatial Data

Input prompts refer to the information or instructions provided to a model to guide its generation or decision-making process. In the context of generating object masks with the Segment Anything Model (SAM), an input prompt could be a single point or multiple points that specifies the object or region for which you want to generate a mask.

This notebook has been derived from Generating object masks from input prompts with SAM, with significant simplifications to facilitate saving the segmentation results and visualising them.

Install and Import libraries

pip install segment-geospatial leafmap localtileserver
import os
import leafmap
from samgeo import SamGeo, tms_to_geotiff

Create an interactive map

m = leafmap.Map(center=[10.029939778759502, 105.76756428014754], zoom=17, height="600px", width="800px")
m.add_basemap("SATELLITE")
m
CTU-Vietnam. Source: Author

Select and download a sample image

--

--