[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-71034":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":15,"forks30d":15,"starsTrendScore":19,"compositeScore":20,"rankGlobal":9,"rankLanguage":9,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":9,"pushedAt":9,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":15,"starSnapshotCount":15,"syncStatus":29,"lastSyncTime":30,"discoverSource":31},71034,"FastSAM","CASIA-LMC-Lab\u002FFastSAM","CASIA-LMC-Lab","Fast Segment Anything",null,"Python",8364,764,54,135,0,8,15,30,24,39.65,"GNU Affero General Public License v3.0",false,"main",true,[],"2026-06-12 02:02:46","![](assets\u002Flogo.png)\r\n\r\n# Fast Segment Anything\r\n\r\n[[`📕Paper`](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2306.12156.pdf)] [[`🤗HuggingFace Demo`](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FAn-619\u002FFastSAM)] [[`Colab demo`](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1oX14f6IneGGw612WgVlAiy91UHwFAvr9?usp=sharing)] [[`Replicate demo & API`](https:\u002F\u002Freplicate.com\u002Fcasia-iva-lab\u002Ffastsam)] [~~[`OpenXLab Demo`](https:\u002F\u002Fopenxlab.org.cn\u002Fapps\u002Fdetail\u002Fzxair\u002FFastSAM)~~] [[`Model Zoo`](#model-checkpoints)] [[`BibTeX`](#citing-fastsam)] [[`Video Demo`](https:\u002F\u002Fyoutu.be\u002FyHNPyqazYYU)]\r\n\r\n![FastSAM Speed](assets\u002Fhead_fig.png)\r\n\r\nThe **Fast Segment Anything Model(FastSAM)** is a CNN Segment Anything Model trained using only 2% of the SA-1B dataset published by SAM authors. FastSAM achieves comparable performance with\r\nthe SAM method at **50× higher run-time speed**.\r\n\r\n![FastSAM design](assets\u002FOverview.png)\r\n\r\n**🍇 Updates**\r\n- **`2024\u002F6\u002F25`** The edge jaggies issue has been slightly improved [#231](https:\u002F\u002Fgithub.com\u002FCASIA-IVA-Lab\u002FFastSAM\u002Fpull\u002F231), and the strategy has also been synchronized to the ultralytics project[#13939](https:\u002F\u002Fgithub.com\u002Fultralytics\u002Fultralytics\u002Fpull\u002F13939),[#13912](https:\u002F\u002Fgithub.com\u002Fultralytics\u002Fultralytics\u002Fpull\u002F13912). The [huggingface demo](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FAn-619\u002FFastSAM) is updated.\r\n- **`2023\u002F11\u002F28`** Recommendation: [Semantic FastSAM](https:\u002F\u002Fgithub.com\u002FKBH00\u002FSemantic-Fast-SAM), which add the semantic class labels to FastSAM. Thanks to [KBH00](https:\u002F\u002Fgithub.com\u002FKBH00\u002FSemantic-Fast-SAM) for this valuable contribution.\r\n- **`2023\u002F09\u002F11`** Release  [Training and Validation Code](https:\u002F\u002Fgithub.com\u002FCASIA-IVA-Lab\u002FFastSAM\u002Freleases).\r\n- **`2023\u002F08\u002F17`** Release  [OpenXLab Demo](https:\u002F\u002Fopenxlab.org.cn\u002Fapps\u002Fdetail\u002Fzxair\u002FFastSAM). Thanks to OpenXLab Team for help.\r\n- **`2023\u002F07\u002F06`** Added to [Ultralytics (YOLOv8) Model Hub](https:\u002F\u002Fdocs.ultralytics.com\u002Fmodels\u002Ffast-sam\u002F). Thanks to [Ultralytics](https:\u002F\u002Fgithub.com\u002Fultralytics\u002Fultralytics) for help 🌹.\r\n- **`2023\u002F06\u002F29`** Support [text mode](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FAn-619\u002FFastSAM) in HuggingFace Space. Thanks a lot to [gaoxinge](https:\u002F\u002Fgithub.com\u002Fgaoxinge) for help 🌹.\r\n- **`2023\u002F06\u002F29`** Release [FastSAM_Awesome_TensorRT](https:\u002F\u002Fgithub.com\u002FChuRuaNh0\u002FFastSam_Awsome_TensorRT). Thanks a lot to [ChuRuaNh0](https:\u002F\u002Fgithub.com\u002FChuRuaNh0) for providing the TensorRT model of FastSAM 🌹.\r\n- **`2023\u002F06\u002F26`** Release [FastSAM Replicate Online Demo](https:\u002F\u002Freplicate.com\u002Fcasia-iva-lab\u002Ffastsam). Thanks a lot to [Chenxi](https:\u002F\u002Fchenxwh.github.io\u002F) for providing this nice demo 🌹.\r\n- **`2023\u002F06\u002F26`** Support [points mode](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FAn-619\u002FFastSAM) in HuggingFace Space. Better and faster interaction will come soon!\r\n- **`2023\u002F06\u002F24`** Thanks a lot to [Grounding-SAM](https:\u002F\u002Fgithub.com\u002FIDEA-Research\u002FGrounded-Segment-Anything) for Combining Grounding-DINO with FastSAM in [Grounded-FastSAM](https:\u002F\u002Fgithub.com\u002FIDEA-Research\u002FGrounded-Segment-Anything\u002Ftree\u002Fmain\u002FEfficientSAM) 🌹.\r\n\r\n## Installation\r\n\r\nClone the repository locally:\r\n\r\n```shell\r\ngit clone https:\u002F\u002Fgithub.com\u002FCASIA-IVA-Lab\u002FFastSAM.git\r\n```\r\n\r\nCreate the conda env. The code requires `python>=3.7`, 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.\r\n\r\n```shell\r\nconda create -n FastSAM python=3.9\r\nconda activate FastSAM\r\n```\r\n\r\nInstall the packages:\r\n\r\n```shell\r\ncd FastSAM\r\npip install -r requirements.txt\r\n```\r\n\r\nInstall CLIP(Required if the text prompt is being tested.):\r\n\r\n```shell\r\npip install git+https:\u002F\u002Fgithub.com\u002Fopenai\u002FCLIP.git\r\n```\r\n\r\n## \u003Ca name=\"GettingStarted\">\u003C\u002Fa> Getting Started\r\n\r\n\r\nFirst download a [model checkpoint](#model-checkpoints).\r\n\r\nThen, you can run the scripts to try the everything mode and three prompt modes.\r\n\r\n```shell\r\n# Everything mode\r\npython Inference.py --model_path .\u002Fweights\u002FFastSAM.pt --img_path .\u002Fimages\u002Fdogs.jpg\r\n```\r\n\r\n```shell\r\n# Text prompt\r\npython Inference.py --model_path .\u002Fweights\u002FFastSAM.pt --img_path .\u002Fimages\u002Fdogs.jpg  --text_prompt \"the yellow dog\"\r\n```\r\n\r\n```shell\r\n# Box prompt (xywh)\r\npython Inference.py --model_path .\u002Fweights\u002FFastSAM.pt --img_path .\u002Fimages\u002Fdogs.jpg --box_prompt \"[[570,200,230,400]]\"\r\n```\r\n\r\n```shell\r\n# Points prompt\r\npython Inference.py --model_path .\u002Fweights\u002FFastSAM.pt --img_path .\u002Fimages\u002Fdogs.jpg  --point_prompt \"[[520,360],[620,300]]\" --point_label \"[1,0]\"\r\n```\r\n\r\nYou can use the following code to generate all masks and visualize the results.\r\n```shell\r\nfrom fastsam import FastSAM, FastSAMPrompt\r\n\r\nmodel = FastSAM('.\u002Fweights\u002FFastSAM.pt')\r\nIMAGE_PATH = '.\u002Fimages\u002Fdogs.jpg'\r\nDEVICE = 'cpu'\r\neverything_results = model(IMAGE_PATH, device=DEVICE, retina_masks=True, imgsz=1024, conf=0.4, iou=0.9,)\r\nprompt_process = FastSAMPrompt(IMAGE_PATH, everything_results, device=DEVICE)\r\n\r\n# everything prompt\r\nann = prompt_process.everything_prompt()\r\n\r\nprompt_process.plot(annotations=ann,output_path='.\u002Foutput\u002Fdog.jpg',)\r\n\r\n```\r\nFor point\u002Fbox\u002Ftext mode prompts, use:\r\n```\r\n# bbox default shape [0,0,0,0] -> [x1,y1,x2,y2]\r\nann = prompt_process.box_prompt(bboxes=[[200, 200, 300, 300]])\r\n\r\n# text prompt\r\nann = prompt_process.text_prompt(text='a photo of a dog')\r\n\r\n# point prompt\r\n# points default [[0,0]] [[x1,y1],[x2,y2]]\r\n# point_label default [0] [1,0] 0:background, 1:foreground\r\nann = prompt_process.point_prompt(points=[[620, 360]], pointlabel=[1])\r\n\r\nprompt_process.plot(annotations=ann,output_path='.\u002Foutput\u002Fdog.jpg',)\r\n\r\n```\r\n\r\nYou are also welcomed to try our Colab demo: [FastSAM_example.ipynb](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1oX14f6IneGGw612WgVlAiy91UHwFAvr9?usp=sharing).\r\n\r\n\r\n\r\n## Different Inference Options\r\n\r\nWe provide various options for different purposes, details are in [MORE_USAGES.md](MORE_USAGES.md).\r\n\r\n## Training or Validation\r\nTraining from scratch or validation: [Training and Validation Code](https:\u002F\u002Fgithub.com\u002FCASIA-IVA-Lab\u002FFastSAM\u002Freleases).\r\n\r\n## Web demo\r\n\r\n### Gradio demo\r\n\r\n- We also provide a UI for testing our method that is built with gradio. You can upload a custom image, select the mode and set the parameters, click the segment button, and get a satisfactory segmentation result. Currently, the UI supports interaction with the 'Everything mode' and 'points mode'. We plan to add support for additional modes in the future. Running the following command in a terminal will launch the demo:\r\n\r\n```\r\n# Download the pre-trained model in \".\u002Fweights\u002FFastSAM.pt\"\r\npython app_gradio.py\r\n```\r\n\r\n- This demo is also hosted on [HuggingFace Space](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FAn-619\u002FFastSAM).\r\n\r\n![HF_Everyhting](assets\u002Fhf_everything_mode.png) ![HF_Points](assets\u002Fhf_points_mode.png)\r\n\r\n### Replicate demo\r\n\r\n- [Replicate demo](https:\u002F\u002Freplicate.com\u002Fcasia-iva-lab\u002Ffastsam) has supported all modes, you can experience points\u002Fbox\u002Ftext mode.\r\n\r\n![Replicate-1](assets\u002Freplicate-1.png) ![Replicate-2](assets\u002Freplicate-2.png) ![Replicate-3](assets\u002Freplicate-3.png)\r\n\r\n## \u003Ca name=\"Models\">\u003C\u002Fa>Model Checkpoints\r\n\r\nTwo model versions of the model are available with different sizes. Click the links below to download the checkpoint for the corresponding model type.\r\n\r\n- **`default` or `FastSAM`: [YOLOv8x based Segment Anything Model](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1m1sjY4ihXBU1fZXdQ-Xdj-mDltW-2Rqv\u002Fview?usp=sharing) | [Baidu Cloud (pwd: 0000).](https:\u002F\u002Fpan.baidu.com\u002Fs\u002F18KzBmOTENjByoWWR17zdiQ?pwd=0000)**\r\n- `FastSAM-s`: [YOLOv8s based Segment Anything Model.](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F10XmSj6mmpmRb8NhXbtiuO9cTTBwR_9SV\u002Fview?usp=sharing)\r\n\r\n## Results\r\n\r\nAll result were tested on a single NVIDIA GeForce RTX 3090.\r\n\r\n### 1. Inference time\r\n\r\nRunning Speed under Different Point Prompt Numbers(ms).\r\n| method | params | 1 | 10 | 100 | E(16x16) | E(32x32\\*) | E(64x64) |\r\n|:------------------:|:--------:|:-----:|:-----:|:-----:|:----------:|:-----------:|:----------:|\r\n| SAM-H | 0.6G | 446 | 464 | 627 | 852 | 2099 | 6972 |\r\n| SAM-B | 136M | 110 | 125 | 230 | 432 | 1383 | 5417 |\r\n| FastSAM | 68M | 40 |40 | 40 | 40 | 40 | 40 |\r\n\r\n### 2. Memory usage\r\n\r\n|  Dataset  | Method  | GPU Memory (MB) |\r\n| :-------: | :-----: | :-------------: |\r\n| COCO 2017 | FastSAM |      2608       |\r\n| COCO 2017 |  SAM-H  |      7060       |\r\n| COCO 2017 |  SAM-B  |      4670       |\r\n\r\n### 3. Zero-shot Transfer Experiments\r\n\r\n#### Edge Detection\r\n\r\nTest on the BSDB500 dataset.\r\n|method | year| ODS | OIS | AP | R50 |\r\n|:----------:|:-------:|:--------:|:--------:|:------:|:-----:|\r\n| HED | 2015| .788 | .808 | .840 | .923 |\r\n| SAM | 2023| .768 | .786 | .794 | .928 |\r\n| FastSAM | 2023| .750 | .790 | .793 | .903 |\r\n\r\n#### Object Proposals\r\n\r\n##### COCO\r\n\r\n|  method   | AR10 | AR100 | AR1000 | AUC  |\r\n| :-------: | :--: | :---: | :-----: | :--: |\r\n| SAM-H E64 | 15.5 | 45.6  |   67.7 | 32.1 |\r\n| SAM-H E32 | 18.5 | 49.5  |   62.5 | 33.7 |\r\n| SAM-B E32 | 11.4 | 39.6  |   59.1 | 27.3 |\r\n|  FastSAM  | 15.7 | 47.3  |   63.7 | 32.2 |\r\n\r\n##### LVIS\r\n\r\nbbox AR@1000\r\n| method | all | small | med. | large |\r\n|:---------------:|:-----:|:------:|:-----:|:------:|\r\n| ViTDet-H | 65.0 | 53.2 | 83.3 | 91.2 |\r\nzero-shot transfer methods\r\n| SAM-H E64 | 52.1 | 36.6 | 75.1 | 88.2 |\r\n| SAM-H E32 | 50.3 | 33.1 | 76.2 | 89.8 |\r\n| SAM-B E32 | 45.0 | 29.3 | 68.7 | 80.6 |\r\n| FastSAM | 57.1 | 44.3 | 77.1 | 85.3 |\r\n\r\n#### Instance Segmentation On COCO 2017\r\n\r\n|  method  |  AP  | APS  | APM  | APL  |\r\n| :------: | :--: | :--: | :--: | :--: |\r\n| ViTDet-H | .510 | .320 | .543 | .689 |\r\n|   SAM    | .465 | .308 | .510 | .617 |\r\n| FastSAM  | .379 | .239 | .434 | .500 |\r\n\r\n### 4. Performance Visualization\r\n\r\nSeveral segmentation results:\r\n\r\n#### Natural Images\r\n\r\n![Natural Images](assets\u002Feightpic.png)\r\n\r\n#### Text to Mask\r\n\r\n![Text to Mask](assets\u002Fdog_clip.png)\r\n\r\n### 5.Downstream tasks\r\n\r\nThe results of several downstream tasks to show the effectiveness.\r\n\r\n#### Anomaly Detection\r\n\r\n![Anomaly Detection](assets\u002Fanomaly.png)\r\n\r\n#### Salient Object Detection\r\n\r\n![Salient Object Detection](assets\u002Fsalient.png)\r\n\r\n#### Building Extracting\r\n\r\n![Building Detection](assets\u002Fbuilding.png)\r\n\r\n## License\r\n\r\nThe model is licensed under the [Apache 2.0 license](LICENSE).\r\n\r\n## Acknowledgement\r\n\r\n- [Segment Anything](https:\u002F\u002Fsegment-anything.com\u002F) provides the SA-1B dataset and the base codes.\r\n- [YOLOv8](https:\u002F\u002Fgithub.com\u002Fultralytics\u002Fultralytics) provides codes and pre-trained models.\r\n- [YOLACT](https:\u002F\u002Farxiv.org\u002Fabs\u002F2112.10003) provides powerful instance segmentation method.\r\n- [Grounded-Segment-Anything](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fyizhangliu\u002FGrounded-Segment-Anything) provides a useful web demo template.\r\n\r\n## Contributors\r\n\r\nOur project wouldn't be possible without the contributions of these amazing people! Thank you all for making this project better.\r\n\r\n\r\n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002FCASIA-IVA-Lab\u002FFastSAM\u002Fgraphs\u002Fcontributors\">\r\n  \u003Cimg src=\"https:\u002F\u002Fcontrib.rocks\u002Fimage?repo=CASIA-IVA-Lab\u002FFastSAM\" \u002F>\r\n\u003C\u002Fa>\r\n\r\n\r\n## Citing FastSAM\r\n\r\nIf you find this project useful for your research, please consider citing the following BibTeX entry.\r\n\r\n```\r\n@misc{zhao2023fast,\r\n      title={Fast Segment Anything},\r\n      author={Xu Zhao and Wenchao Ding and Yongqi An and Yinglong Du and Tao Yu and Min Li and Ming Tang and Jinqiao Wang},\r\n      year={2023},\r\n      eprint={2306.12156},\r\n      archivePrefix={arXiv},\r\n      primaryClass={cs.CV}\r\n}\r\n```\r\n\r\n[![Star History Chart](https:\u002F\u002Fapi.star-history.com\u002Fsvg?repos=CASIA-IVA-Lab\u002FFastSAM&type=Date)](https:\u002F\u002Fstar-history.com\u002F#CASIA-IVA-Lab\u002FFastSAM&Date)\r\n","Fast Segment Anything (FastSAM) 是一个高效的图像分割模型，使用仅2%的SA-1B数据集进行训练，实现了与SAM方法相当的性能，并且运行速度提高了50倍。该项目采用Python语言开发，基于卷积神经网络（CNN）技术，具有快速和高精度的特点。FastSAM适用于需要实时处理的图像分割场景，如视频监控、自动驾驶、医学影像分析等。项目提供了多种演示和API接口，方便用户测试和集成。",2,"2026-06-11 03:35:34","high_star"]