[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-600":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":22,"hasPages":22,"topics":24,"createdAt":10,"pushedAt":10,"updatedAt":25,"readmeContent":26,"aiSummary":27,"trendingCount":16,"starSnapshotCount":16,"syncStatus":28,"lastSyncTime":29,"discoverSource":30},600,"segment-anything","facebookresearch\u002Fsegment-anything","facebookresearch","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.","",null,"Jupyter Notebook",54339,6354,330,535,0,10,45,208,46,"Apache License 2.0",false,"main",[],"2026-06-12 02:00:15","## Latest updates -- SAM 2: Segment Anything in Images and Videos\n\nPlease check out our new release on [**Segment Anything Model 2 (SAM 2)**](https:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002Fsegment-anything-2).\n\n* SAM 2 code: https:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002Fsegment-anything-2\n* SAM 2 demo: https:\u002F\u002Fsam2.metademolab.com\u002F\n* SAM 2 paper: https:\u002F\u002Farxiv.org\u002Fabs\u002F2408.00714\n\n ![SAM 2 architecture](https:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002Fsegment-anything-2\u002Fblob\u002Fmain\u002Fassets\u002Fmodel_diagram.png?raw=true)\n\n**Segment Anything Model 2 (SAM 2)** is a foundation model towards solving promptable visual segmentation in images and videos. We extend SAM to video by considering images as a video with a single frame. The model design is a simple transformer architecture with streaming memory for real-time video processing. We build a model-in-the-loop data engine, which improves model and data via user interaction, to collect [**our SA-V dataset**](https:\u002F\u002Fai.meta.com\u002Fdatasets\u002Fsegment-anything-video), the largest video segmentation dataset to date. SAM 2 trained on our data provides strong performance across a wide range of tasks and visual domains.\n\n# Segment Anything\n\n**[Meta AI Research, FAIR](https:\u002F\u002Fai.facebook.com\u002Fresearch\u002F)**\n\n[Alexander Kirillov](https:\u002F\u002Falexander-kirillov.github.io\u002F), [Eric Mintun](https:\u002F\u002Fericmintun.github.io\u002F), [Nikhila Ravi](https:\u002F\u002Fnikhilaravi.com\u002F), [Hanzi Mao](https:\u002F\u002Fhanzimao.me\u002F), Chloe Rolland, Laura Gustafson, [Tete Xiao](https:\u002F\u002Ftetexiao.com), [Spencer Whitehead](https:\u002F\u002Fwww.spencerwhitehead.com\u002F), Alex Berg, Wan-Yen Lo, [Piotr Dollar](https:\u002F\u002Fpdollar.github.io\u002F), [Ross Girshick](https:\u002F\u002Fwww.rossgirshick.info\u002F)\n\n[[`Paper`](https:\u002F\u002Fai.facebook.com\u002Fresearch\u002Fpublications\u002Fsegment-anything\u002F)] [[`Project`](https:\u002F\u002Fsegment-anything.com\u002F)] [[`Demo`](https:\u002F\u002Fsegment-anything.com\u002Fdemo)] [[`Dataset`](https:\u002F\u002Fsegment-anything.com\u002Fdataset\u002Findex.html)] [[`Blog`](https:\u002F\u002Fai.facebook.com\u002Fblog\u002Fsegment-anything-foundation-model-image-segmentation\u002F)] [[`BibTeX`](#citing-segment-anything)]\n\n![SAM design](assets\u002Fmodel_diagram.png?raw=true)\n\nThe **Segment Anything Model (SAM)** produces high quality object masks from input prompts such as points or boxes, and it can be used to generate masks for all objects in an image. It has been trained on a [dataset](https:\u002F\u002Fsegment-anything.com\u002Fdataset\u002Findex.html) of 11 million images and 1.1 billion masks, and has strong zero-shot performance on a variety of segmentation tasks.\n\n\u003Cp float=\"left\">\n  \u003Cimg src=\"assets\u002Fmasks1.png?raw=true\" width=\"37.25%\" \u002F>\n  \u003Cimg src=\"assets\u002Fmasks2.jpg?raw=true\" width=\"61.5%\" \u002F> \n\u003C\u002Fp>\n\n## Installation\n\nThe code requires `python>=3.8`, as well as `pytorch>=1.7` and `torchvision>=0.8`. Please follow the instructions [here](https:\u002F\u002Fpytorch.org\u002Fget-started\u002Flocally\u002F) 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:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002Fsegment-anything.git\n```\n\nor clone the repository locally and install with\n\n```\ngit clone git@github.com:facebookresearch\u002Fsegment-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## \u003Ca name=\"GettingStarted\">\u003C\u002Fa>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[\"\u003Cmodel_type>\"](checkpoint=\"\u003Cpath\u002Fto\u002Fcheckpoint>\")\npredictor = SamPredictor(sam)\npredictor.set_image(\u003Cyour_image>)\nmasks, _, _ = predictor.predict(\u003Cinput_prompts>)\n```\n\nor generate masks for an entire image:\n\n```\nfrom segment_anything import SamAutomaticMaskGenerator, sam_model_registry\nsam = sam_model_registry[\"\u003Cmodel_type>\"](checkpoint=\"\u003Cpath\u002Fto\u002Fcheckpoint>\")\nmask_generator = SamAutomaticMaskGenerator(sam)\nmasks = mask_generator.generate(\u003Cyour_image>)\n```\n\nAdditionally, masks can be generated for images from the command line:\n\n```\npython scripts\u002Famg.py --checkpoint \u003Cpath\u002Fto\u002Fcheckpoint> --model-type \u003Cmodel_type> --input \u003Cimage_or_folder> --output \u003Cpath\u002Fto\u002Foutput>\n```\n\nSee the examples notebooks on [using SAM with prompts](\u002Fnotebooks\u002Fpredictor_example.ipynb) and [automatically generating masks](\u002Fnotebooks\u002Fautomatic_mask_generator_example.ipynb) for more details.\n\n\u003Cp float=\"left\">\n  \u003Cimg src=\"assets\u002Fnotebook1.png?raw=true\" width=\"49.1%\" \u002F>\n  \u003Cimg src=\"assets\u002Fnotebook2.png?raw=true\" width=\"48.9%\" \u002F>\n\u003C\u002Fp>\n\n## ONNX Export\n\nSAM's lightweight mask decoder can be exported to ONNX format so that it can be run in any environment that supports ONNX runtime, such as in-browser as showcased in the [demo](https:\u002F\u002Fsegment-anything.com\u002Fdemo). Export the model with\n\n```\npython scripts\u002Fexport_onnx_model.py --checkpoint \u003Cpath\u002Fto\u002Fcheckpoint> --model-type \u003Cmodel_type> --output \u003Cpath\u002Fto\u002Foutput>\n```\n\nSee the [example notebook](https:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002Fsegment-anything\u002Fblob\u002Fmain\u002Fnotebooks\u002Fonnx_model_example.ipynb) for details on how to combine image preprocessing via SAM's backbone with mask prediction using the ONNX model. It is recommended to use the latest stable version of PyTorch for ONNX export.\n\n### Web demo\n\nThe `demo\u002F` folder has a simple one page React app which shows how to run mask prediction with the exported ONNX model in a web browser with multithreading. Please see [`demo\u002FREADME.md`](https:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002Fsegment-anything\u002Fblob\u002Fmain\u002Fdemo\u002FREADME.md) for more details.\n\n## \u003Ca name=\"Models\">\u003C\u002Fa>Model Checkpoints\n\nThree model versions of the model are available with different backbone sizes. These models can be instantiated by running\n\n```\nfrom segment_anything import sam_model_registry\nsam = sam_model_registry[\"\u003Cmodel_type>\"](checkpoint=\"\u003Cpath\u002Fto\u002Fcheckpoint>\")\n```\n\nClick the links below to download the checkpoint for the corresponding model type.\n\n- **`default` or `vit_h`: [ViT-H SAM model.](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fsegment_anything\u002Fsam_vit_h_4b8939.pth)**\n- `vit_l`: [ViT-L SAM model.](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fsegment_anything\u002Fsam_vit_l_0b3195.pth)\n- `vit_b`: [ViT-B SAM model.](https:\u002F\u002Fdl.fbaipublicfiles.com\u002Fsegment_anything\u002Fsam_vit_b_01ec64.pth)\n\n## Dataset\n\nSee [here](https:\u002F\u002Fai.facebook.com\u002Fdatasets\u002Fsegment-anything\u002F) for an overview of the datastet. The dataset can be downloaded [here](https:\u002F\u002Fai.facebook.com\u002Fdatasets\u002Fsegment-anything-downloads\u002F). By downloading the datasets you agree that you have read and accepted the terms of the SA-1B Dataset Research License.\n\nWe save masks per image as a json file. It can be loaded as a dictionary in python in the below format.\n\n```python\n{\n    \"image\"                 : image_info,\n    \"annotations\"           : [annotation],\n}\n\nimage_info {\n    \"image_id\"              : int,              # Image id\n    \"width\"                 : int,              # Image width\n    \"height\"                : int,              # Image height\n    \"file_name\"             : str,              # Image filename\n}\n\nannotation {\n    \"id\"                    : int,              # Annotation id\n    \"segmentation\"          : dict,             # Mask saved in COCO RLE format.\n    \"bbox\"                  : [x, y, w, h],     # The box around the mask, in XYWH format\n    \"area\"                  : int,              # The area in pixels of the mask\n    \"predicted_iou\"         : float,            # The model's own prediction of the mask's quality\n    \"stability_score\"       : float,            # A measure of the mask's quality\n    \"crop_box\"              : [x, y, w, h],     # The crop of the image used to generate the mask, in XYWH format\n    \"point_coords\"          : [[x, y]],         # The point coordinates input to the model to generate the mask\n}\n```\n\nImage ids can be found in sa_images_ids.txt which can be downloaded using the above [link](https:\u002F\u002Fai.facebook.com\u002Fdatasets\u002Fsegment-anything-downloads\u002F) as well.\n\nTo decode a mask in COCO RLE format into binary:\n\n```\nfrom pycocotools import mask as mask_utils\nmask = mask_utils.decode(annotation[\"segmentation\"])\n```\n\nSee [here](https:\u002F\u002Fgithub.com\u002Fcocodataset\u002Fcocoapi\u002Fblob\u002Fmaster\u002FPythonAPI\u002Fpycocotools\u002Fmask.py) for more instructions to manipulate masks stored in RLE format.\n\n## License\n\nThe model is licensed under the [Apache 2.0 license](LICENSE).\n\n## Contributing\n\nSee [contributing](CONTRIBUTING.md) and the [code of conduct](CODE_OF_CONDUCT.md).\n\n## Contributors\n\nThe Segment Anything project was made possible with the help of many contributors (alphabetical):\n\nAaron Adcock, Vaibhav Aggarwal, Morteza Behrooz, Cheng-Yang Fu, Ashley Gabriel, Ahuva Goldstand, Allen Goodman, Sumanth Gurram, Jiabo Hu, Somya Jain, Devansh Kukreja, Robert Kuo, Joshua Lane, Yanghao Li, Lilian Luong, Jitendra Malik, Mallika Malhotra, William Ngan, Omkar Parkhi, Nikhil Raina, Dirk Rowe, Neil Sejoor, Vanessa Stark, Bala Varadarajan, Bram Wasti, Zachary Winstrom\n\n## Citing Segment Anything\n\nIf you use SAM or SA-1B in your research, please use the following BibTeX entry.\n\n```\n@article{kirillov2023segany,\n  title={Segment Anything},\n  author={Kirillov, Alexander and Mintun, Eric and Ravi, Nikhila and Mao, Hanzi and Rolland, Chloe and Gustafson, Laura and Xiao, Tete and Whitehead, Spencer and Berg, Alexander C. and Lo, Wan-Yen and Doll{\\'a}r, Piotr and Girshick, Ross},\n  journal={arXiv:2304.02643},\n  year={2023}\n}\n```\n","Segment Anything Model (SAM) 是一个用于图像和视频中物体分割的基础模型。它能够根据点或框等输入提示生成高质量的物体掩码，并适用于所有图像中的物体。该模型采用简单的Transformer架构，具有流式内存设计以支持实时视频处理，并通过用户交互的数据引擎不断优化模型与数据集。其核心功能包括强大的零样本性能、广泛的视觉域适应能力以及对多种分割任务的支持。适合需要精确图像或视频分割的应用场景，如计算机视觉研究、内容编辑、自动驾驶等。",2,"2026-06-11 02:37:59","top_all"]