按需安装 extras(samgeo2/samgeo3/fast/hq/text/api),只装基础包缺少对应模型依赖;文本提示需额外安装 text extra 以引入 Grounding DINO;Windows 装 SAM 3 需另装 triton-windows 并按专门步骤配置 PyTorch/CUDA;模型权重需另行下载,README 未随包提供。
segment-geospatial
opengeosMIT活跃维护用 Segment Anything 模型对遥感影像等地理空间数据做交互式分割的 Python 包,省去自己搭建分割流程的麻烦。
A Python package for segmenting geospatial data with the Segment Anything Model (SAM)
pip install "segment-geospatial[samgeo3]"README 建议使用强力 GPU,显存至少 8 GB;也可用 Google Colab 免费 GPU。CPU 运行方式 README 未说明,支持的 GPU 厂商/型号未具体列出。
用 SAM 系列模型对遥感影像和地理空间数据做分割的 Python 包,少写代码就能出掩膜
用 Segment Anything 模型对遥感影像等地理空间数据做交互式分割的 Python 包,省去自己搭建分割流程的麻烦。
核心能力
- 从 TMS 瓦片服务下载地图瓦片并生成 GeoTIFF
- 用 SAM、HQ-SAM、SAM 2/3 等模型分割 GeoTIFF 影像
- 支持文本提示、点/框提示和交互式前后景标记
- 分割结果导出为 GeoPackage、Shapefile、GeoJSON
- 提供 REST API 以 HTTP 方式提供分割服务
容易踩的坑
- v1.4.2最新正式版2026-08-22 · 2026-08-22 20:39 UTC
What's Changed
- Replace MkDocs with Zensical for the documentation site by @giswqs in https://github.com/opengeos/segment-geospatial/pull/544
- [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci[bot] in https://github.com/opengeos/segment-geospatial/pull/545
- Bump actions/setup-python from 6 to 7 by @dependabot[bot] in https://github.com/opengeos/segment-geospatial/pull/547
- Add wildfire burn area detection example notebook by @Qandeel-01 in https://github.com/opengeos/segment-geospatial/pull/546
- fix: format wildfire example notebook by @giswqs in https://github.com/opengeos/segment-geospatial/pull/548
- feat: include per-mask confidence score in API GeoJSON output by @giswqs in https://github.com/opengeos/segment-geospatial/pull/551
- Release v1.4.2 by @giswqs in https://github.com/opengeos/segment-geospatial/pull/552
New Contributors
- @Qandeel-01 made their first contribution in https://github.com/opengeos/segment-geospatial/pull/546
Full Changelog: https://github.com/opengeos/segment-geospatial/compare/v1.4.1...v1.4.2
- v1.4.12026-07-04 · 2026-07-04 23:51 UTC
查看更新说明
What's Changed
- Fix SAM3 bfloat16/float32 dtype mismatch on CUDA by @giswqs in https://github.com/opengeos/segment-geospatial/pull/541
- Fix SamGeo3Video AssertionError on re-instantiation by @giswqs in https://github.com/opengeos/segment-geospatial/pull/542
- Bump actions/checkout from 6 to 7 by @dependabot[bot] in https://github.com/opengeos/segment-geospatial/pull/539
- [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci[bot] in https://github.com/opengeos/segment-geospatial/pull/540
Full Changelog: https://github.com/opengeos/segment-geospatial/compare/v1.4.0...v1.4.1
- v1.4.02026-06-21 · 2026-06-21 16:11 UTC
查看更新说明
What's Changed
- Add SAM 3.1 model support (#538) — adds
facebook/sam3.1as a backward-compatible SAM3 model option (default remainsfacebook/sam3). Introduces a sharedsamgeo/model_registry.pyas the single source of truth for model ids, wires SAM 3.1 checkpoint loading through the Meta backend, and bumps thesamgeo3extra tosam3>=0.1.4.
Full Changelog: https://github.com/opengeos/segment-geospatial/compare/v1.3.3...v1.4.0
- Add SAM 3.1 model support (#538) — adds
- v1.3.32026-06-14 · 2026-06-14 14:46 UTC
查看更新说明
What's changed
REST API (
samgeo.api) robustness fixes, validated end-to-end against the example imagery indocs/examples/(#535):- Model cache mode collision — the cache key now folds in the model-shaping kwargs (
automatic,backend,confidence_threshold,points_per_side,pred_iou_thresh,stability_score_thresh), so an automatic mask-generation instance is no longer reused for a prompt-predictrequest ('SamGeo2' object has no attribute 'predictor'), and requests that differ only by configuration no longer silently reuse a stale instance. - SAM3 second-request dtype error — SAM3 mutates its encoded-image state during
generate_*, so the image-hash optimization made the 2nd+ SAM3 request fail withexpected scalar type BFloat16 but found Float._set_image_cachednow always re-encodes for SAM3 (SAM/SAM2 still cached). - Empty-mask vectorization —
raster_to_vectornow emits a valid emptyFeatureCollectioninstead of raising geopandas' "no active geometry column" when a mask has no foreground. /segment/automaticgained the empty-masks 404 guard the other endpoints have, and now defaults to SAM3.
Added regression tests for all of the above.
Full diff: https://github.com/opengeos/segment-geospatial/compare/v1.3.2...v1.3.3
- Model cache mode collision — the cache key now folds in the model-shaping kwargs (
- v1.3.22026-03-23 · 2026-03-23 14:21 UTC
查看更新说明
What's Changed
- Bump version: 1.3.0 → 1.3.1 by @giswqs in https://github.com/opengeos/segment-geospatial/pull/509
- Fix OpenCV 4.12 cv2.rectangle error due to non-contiguous arrays by @giswqs in https://github.com/opengeos/segment-geospatial/pull/510
- Add show_points option to show_anns by @giswqs in https://github.com/opengeos/segment-geospatial/pull/511
- Fix OpenCV contiguous array error in _save_blended_frames by @giswqs in https://github.com/opengeos/segment-geospatial/pull/513
Full Changelog: https://github.com/opengeos/segment-geospatial/compare/v1.3.1...v1.3.2
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
SamGeo
A Python package for segmenting geospatial data with the Segment Anything Model (SAM)
Introduction
The SamGeo package draws its inspiration from segment-anything-eo repository authored by Aliaksandr Hancharenka. The primary objective of SamGeo is to simplify the process of leveraging SAM for geospatial data analysis by enabling users to achieve this with minimal coding effort. The source code of SamGeo was adapted from the segment-anything-eo repository, and credit for its original version goes to Aliaksandr Hancharenka.
- Free software: MIT license
- Documentation: https://samgeo.gishub.org
Citations
- Wu, Q., & Osco, L. (2023). samgeo: A Python package for segmenting geospatial data with the Segment Anything Model (SAM). Journal of Open Source Software, 8(89), 5663. https://doi.org/10.21105/joss.05663
- Osco, L. P., Wu, Q., de Lemos, E. L., Gonçalves, W. N., Ramos, A. P. M., Li, J., & Junior, J. M. (2023). The Segment Anything Model (SAM) for remote sensing applications: From zero to one shot. International Journal of Applied Earth Observation and Geoinformation, 124, 103540. https://doi.org/10.1016/j.jag.2023.103540
Features
- Download map tiles from Tile Map Service (TMS) servers and create GeoTIFF files
- Segment GeoTIFF files using the Segment Anything Model (SAM) and HQ-SAM
- Segment remote sensing imagery with text prompts
- Create foreground and background markers interactively
- Load existing markers from vector datasets
- Save segmentation results as common vector formats (GeoPackage, Shapefile, GeoJSON)
- Save input prompts as GeoJSON files
- Visualize segmentation results on interactive maps
- Segment objects from timeseries remote sensing imagery
- REST API for serving segmentation over HTTP (see API docs)
QGIS Plugin
SamGeo is also available as a QGIS plugin. Check out this short video demo and full video tutorial on how to use the plugin.
Installation
Install with pixi (Recommended)
For the most reliable installation experience, especially on Windows or when dealing with complex dependencies like PyTorch/CUDA and SAM 3, we recommend using pixi. Pixi provides faster and more reliable dependency resolution than conda/mamba and avoids common numpy version conflicts. See the full pixi installation guide for detailed instructions.
Quick start with pixi:
# Install pixi (Linux/macOS)
curl -fsSL https://pixi.sh/install.sh | sh
# Or on Windows (PowerShell)
powershell -ExecutionPolicy Bypass -c "irm -useb https://pixi.sh/install.ps1 | iex"
# Create a new pixi project
pixi init geo
cd geo
# Edit pixi.toml with your configuration (see docs for GPU/CPU examples)
# Then install
pixi install
# Start Jupyter Lab
pixi run jupyter lab
Install from PyPI
segment-geospatial is available on PyPI and can be installed in several ways so that its dependencies can be controlled more granularly. This reduces package size for CI environments, since not every time all of the models will be used.
Depending on what tools you need to use, you might want to do:
segment-geospatialorsegment-geospatial[samgeo]: Installs only the minimum required dependencies to run SAMGeosegment-geospatial[samgeo2]: Installs the dependencies to run SAMGeo 2segment-geospatial[samgeo3]: Installs the dependencies to run SAMGeo 3segment-geospatial[fast]: Installs the dependencies to run Fast SAMsegment-geospatial[hq]: Installs the dependencies to run HQ-SAMsegment-geospatial[text]: Installs Grounding DINO to use SAMGeo 1 and 2 with text promptssegment-geospatial[fer]: Installs the dependencies to run the feature edge reconstruction algorithmsegment-geospatial[api]: Installs FastAPI and Uvicorn for serving segmentation as a REST API
Additionally, these other two optional imports are defined:
segment-geospatial[all]: Installs the dependencies to run all of the SAMGeo modelssegment-geospatial[extra]: Installs the dependencies to run all of the SAMGeo models and other utilities to run the examples like Jupyter notebook support,leafmap, etc.
Simply running the following should install the dependencies for each use case:
pip install "segment-geospatial[samgeo3]" # Or any other choice of the above
To see more in detail what packages come with each choice, please refer to pyproject.toml.
Install from conda-forge
segment-geospatial is also available on conda-forge. If you have
Anaconda or Miniconda installed on your computer, you can install segment-geospatial using the following commands. It is recommended to create a fresh conda environment for segment-geospatial. The following commands will create a new conda environment named geo and install segment-geospatial and its dependencies:
conda create -n geo python
conda activate geo
conda install -c conda-forge segment-geospatial
If your system has a GPU, but the above commands do not install the GPU version of pytorch, you can force the installation of the GPU version of pytorch using the following command:
conda install -c conda-forge segment-geospatial "pytorch=*=cuda*"
segment-geospatial has some optional dependencies that are not included in the default conda environment. To install these dependencies, run the following command:
conda install -c conda-forge groundingdino-py segment-anything-fast
Install SAM 3 on Windows
It is a bit tricky to install SAM 3 on Windows. Run the following commands on Windows to install SamGeo:
conda create -n geo python=3.12
conda activate geo
conda install pytorch torchvision pytorch-cuda=12.1 -c pytorch -c nvidia
pip install "segment-geospatial[samgeo3]"
pip install triton-windows ipykernel jupyterlab
Examples
- Segmenting remote sensing imagery
- Automatically generating object masks
- Segmenting remote sensing imagery with input prompts
- Segmenting remote sensing imagery with box prompts
- Segmenting remote sensing imagery with text prompts
- Batch segmentation with text prompts
- Using segment-geospatial with ArcGIS Pro
- Segmenting swimming pools with text prompts
- Segmenting satellite imagery from the Maxar Open Data Program
Demos
- Automatic mask generator

- Interactive segmentation with input prompts

- Input prompts from existing files

- Interactive segmentation with text prompts

Tutorials
Video tutorials are available on my YouTube Channel.
- Automatic mask generation
- Using SAM with ArcGIS Pro
- Interactive segmentation with text prompts
Using SAM with Desktop GIS
- QGIS: Check out the SamGeo QGIS Plugin.
- ArcGIS: Check out the Segment Anything Model (SAM) Toolbox for ArcGIS and the Resources for Unlocking the Power of Deep Learning Applications Using ArcGIS.
Computing Resources
The Segment Anything Model is computationally intensive, and a powerful GPU is recommended to process large datasets. It is recommended to have a GPU with at least 8 GB of GPU memory. You can utilize the free GPU resources provided by Google Colab. Alternatively, you can apply for AWS Cloud Credit for Research, which offers cloud credits to support academic research. If you are in the Greater China region, apply for the AWS Cloud Credit here.
Legal Notice
This repository and its content are provided for educational purposes only. By using the information and code provided, users acknowledge that they are using the APIs and models at their own risk and agree to comply with any applicable laws and regulations. Users who intend to download a large number of image tiles from any basemap are advised to contact the basemap provider to obtain permission before doing so. Unauthorized use of the basemap or any of its components may be a violation of copyright laws or other applicable laws and regulations.
Contributing
Please refer to the contributing guidelines for more information.
Acknowledgements
This project is based upon work partially supported by the National Aeronautics and Space Administration (NASA) under Grant No. 80NSSC22K1742 issued through the Open Source Tools, Frameworks, and Libraries 2020 Program.
This project is also supported by Amazon Web Services (AWS). In addition, this package was made possible by the following open source projects. Credit goes to the developers of these projects.



