Home/Inference & Serving/segment-anything
segment-anything logo

segment-anything

facebookresearch/segment-anything

Provides code for running inference with the SegmentAnything Model (SAM).

GraphCanon updated 3w · GitHub synced 3w

55k stars6.4k forksLast push 1y Jupyter Notebook Apache-2.0

Decision brief

An AI tool for segmentation tasks offering pre-trained models and straightforward integration methods.

Good fit when

  • When you need precise segmentation in images with varied objects or regions, as SAM provides high-quality mask generation from prompts.
  • If your project requires both manual prompt-based and automatic segmentation capabilities, leveraging the SamPredictor and SamAutomaticMaskGenerator classes.

Avoid when

  • Avoid using SAM if your project's constraints specifically require real-time performance since running inference demands significant computational resources.
  • Do not choose this tool when a lightweight or resource-efficient solution is needed, as it relies on heavyweight pre-trained models that may be unsuitable for devices with limited computing power.
Requirements:
Min 8 GB RAM; Requires Python >=3.8, PyTorch >=1.7 with CUDA recommended for faster performance; Optional dependencies such as OpenCV and ONNX may further enhance functionality but are not always necessary for basic use.

Observed Jul 12, 2026 · Source: enrich:decision_facts

Verify the decision

Maintenance and security

Full trust report
Maintenance
Dormant (682d since push)
As of 3w
Provenance
Not a fork · Organization account
As of 3w
Security (OSV)
No lockfile
As of 1mo

Public GitHub metadata and optional OSV scans. Signals, not a guarantee. Trust methodology.

Install

git clone https://github.com/facebookresearch/segment-anything

How it fits your stack(2)

Typed graph edges - alternatives, integrations, successors, and dependencies. Ranked by relationship type, not raw GitHub stars.

Relationship graph

Optional deeper exploration of typed edges and category neighbours.

Similar tools

Same-category neighbours not already linked as typed edges.

Evidence and technical details

Sourced facts, taxonomy, compatibility claims, README excerpt, and machine-readable endpoints.

Overview

Repository that offers tools to use and run inference on the pre-trained SegmentAnything Model, along with example notebooks.

Capability facts

Languages
jupyter notebook

Source: github.language · Aug 1, 2026

Categories

Compatibility

Sourced claims from the README excerpt - not unsourced marketing copy.

Python runtimePython

Source: README excerpt (regex_v1, Aug 1, 2026)

The code requires `python>=3.8`, as well as `pytorch>=1.7` and `torchvision>=0.8`. Please follow the inst
Source link

Tags

README

Installation

The code requires python>=3.8, as well as pytorch>=1.7 and torchvision>=0.8. Please follow the instructions here to install both PyTorch and TorchVision dependencies. Installing both PyTorch and TorchVision with CUDA support is strongly recommended.

Install Segment Anything:

pip install git+https://github.com/facebookresearch/segment-anything.git

or clone the repository locally and install with

git clone git@github.com:facebookresearch/segment-anything.git
cd segment-anything; pip install -e .

The following optional dependencies are necessary for mask post-processing, saving masks in COCO format, the example notebooks, and exporting the model in ONNX format. jupyter is also required to run the example notebooks.

pip install opencv-python pycocotools matplotlib onnxruntime onnx

Getting Started

First download a model checkpoint. Then the model can be used in just a few lines to get masks from a given prompt:

from segment_anything import SamPredictor, sam_model_registry
sam = sam_model_registry["<model_type>"](checkpoint="<path/to/checkpoint>")
predictor = SamPredictor(sam)
predictor.set_image(<your_image>)
masks, _, _ = predictor.predict(<input_prompts>)

or generate masks for an entire image:

from segment_anything import SamAutomaticMaskGenerator, sam_model_registry
sam = sam_model_registry["<model_type>"](checkpoint="<path/to/checkpoint>")
mask_generator = SamAutomaticMaskGenerator(sam)
masks = mask_generator.generate(<your_image>)

Additionally, masks can be generated for images from the command line:

python scripts/amg.py --checkpoint <path/to/checkpoint> --model-type <model_type> --input <image_or_folder> --output <path/to/output>

See the examples notebooks on using SAM with prompts and automatically generating masks for more details.


License

The model is licensed under the Apache 2.0 license.

For agents

This page has a .md twin and JSON over the API.

Was this helpful?

Anonymous feedback helps us improve pages and translations.