{"data":{"slug":"facebookresearch-segment-anything","name":"segment-anything","tagline":"Provides code for running inference with the SegmentAnything Model (SAM).","github_url":"https://github.com/facebookresearch/segment-anything","owner":"facebookresearch","repo":"segment-anything","owner_avatar_url":"https://avatars.githubusercontent.com/u/16943930?v=4","primary_language":"Jupyter Notebook","stars":54630,"forks":6353,"topics":[],"archived":false,"github_pushed_at":"2024-09-18T17:46:55+00:00","maintenance_label":"Dormant","url":"https://www.graphcanon.com/tools/facebookresearch-segment-anything","markdown_url":"https://www.graphcanon.com/tools/facebookresearch-segment-anything.md","api_url":"https://www.graphcanon.com/api/graphcanon/tools/facebookresearch-segment-anything","graph_url":"https://www.graphcanon.com/api/graphcanon/graph?tool=facebookresearch-segment-anything","description":"The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.","homepage_url":null,"license":"Apache-2.0","open_issues":595,"watchers":333,"ai_summary":"Repository that offers tools to use and run inference on the pre-trained SegmentAnything Model, along with example notebooks.","readme_excerpt":"## Installation\n\nThe code requires `python>=3.8`, as well as `pytorch>=1.7` and `torchvision>=0.8`. Please follow the instructions [here](https://pytorch.org/get-started/locally/) to install both PyTorch and TorchVision dependencies. Installing both PyTorch and TorchVision with CUDA support is strongly recommended.\n\nInstall Segment Anything:\n\n```\npip install git+https://github.com/facebookresearch/segment-anything.git\n```\n\nor clone the repository locally and install with\n\n```\ngit clone git@github.com:facebookresearch/segment-anything.git\ncd segment-anything; pip install -e .\n```\n\nThe 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.\n\n```\npip install opencv-python pycocotools matplotlib onnxruntime onnx\n```\n\n---\n\n## <a name=\"GettingStarted\"></a>Getting Started\n\nFirst download a [model checkpoint](#model-checkpoints). Then the model can be used in just a few lines to get masks from a given prompt:\n\n```\nfrom segment_anything import SamPredictor, sam_model_registry\nsam = sam_model_registry[\"<model_type>\"](checkpoint=\"<path/to/checkpoint>\")\npredictor = SamPredictor(sam)\npredictor.set_image(<your_image>)\nmasks, _, _ = predictor.predict(<input_prompts>)\n```\n\nor generate masks for an entire image:\n\n```\nfrom segment_anything import SamAutomaticMaskGenerator, sam_model_registry\nsam = sam_model_registry[\"<model_type>\"](checkpoint=\"<path/to/checkpoint>\")\nmask_generator = SamAutomaticMaskGenerator(sam)\nmasks = mask_generator.generate(<your_image>)\n```\n\nAdditionally, masks can be generated for images from the command line:\n\n```\npython scripts/amg.py --checkpoint <path/to/checkpoint> --model-type <model_type> --input <image_or_folder> --output <path/to/output>\n```\n\nSee the examples notebooks on [using SAM with prompts](/notebooks/predictor_example.ipynb) and [automatically generating masks](/notebooks/automatic_mask_generator_example.ipynb) for more details.\n\n<p float=\"left\">\n  <img src=\"assets/notebook1.png?raw=true\" width=\"49.1%\" />\n  <img src=\"assets/notebook2.png?raw=true\" width=\"48.9%\" />\n</p>\n\n---\n\n## License\n\nThe model is licensed under the [Apache 2.0 license](LICENSE).","github_created_at":"2023-03-23T17:03:03+00:00","created_at":"2026-07-11T23:09:22.107929+00:00","updated_at":"2026-08-01T18:00:42.657098+00:00","categories":[{"slug":"inference-serving","name":"Inference & Serving","url":"https://www.graphcanon.com/categories/inference-serving","markdown_url":"https://www.graphcanon.com/categories/inference-serving.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/inference-serving"}],"tags":[{"slug":"image-processing","name":"image-processing"},{"slug":"jupyter-notebook","name":"jupyter-notebook"},{"slug":"machine-learning","name":"machine-learning"},{"slug":"pytorch","name":"pytorch"},{"slug":"segmentation","name":"segmentation"}],"trust":{"provenance":{"is_fork":false,"github_id":618058471,"owner_type":"Organization","methodology":"github_public_v1","parent_repo":null,"near_duplicate_slugs":[]},"computed_at":"2026-08-01T18:00:41.926Z","maintenance":{"label":"Dormant","score":18,"methodology":"github_public_v1","releases_90d":0,"days_since_push":682,"last_release_at":null},"security_summary":{"status":"no_lockfile","scanner":null,"low_count":0,"high_count":0,"last_scan_at":"2026-07-11T23:09:27.907Z","medium_count":0,"scan_profile":"none","critical_count":0}},"capability_facts":{"scan":{"source":"repo_scan","observed_at":"2026-08-01T18:00:42.377Z"},"languages":{"value":["jupyter notebook"],"source":"github.language","observed_at":"2026-08-01T18:00:42.377Z"},"license_spdx":{"value":"Apache-2.0","source":"github.license","observed_at":"2026-08-01T18:00:42.377Z"}},"decision_facts":{"hosting":null,"pricing":null,"requirements":{"notes":["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."],"min_ram_gb":8,"requires_docker":false},"constraints":{"min_ram_gb":8,"requires_docker":false},"when_to_use":["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."],"when_not_to_use":["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."],"source":"enrich:decision_facts","observed_at":"2026-07-12T12:49:01.868Z"},"constraint_facets":{"min_ram_gb":8,"requires_docker":false},"decision_summary":[{"label":"Requirements","value":"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."},{"label":"Adopt for","value":"An AI tool for segmentation tasks offering pre-trained models and straightforward integration methods."},{"label":"License detail","value":"Apache 2.0 license, permitting free use, modification, and distribution of the source code without requiring derivative works to maintain the same license."}]}}