FastSAM: 50x Faster Segment Anything Model
Discover FastSAM, the revolutionary CNN-based Segment Anything Model that delivers SAM-level performance at 50x speed using just 2% of SA-1B dataset. This open-source powerhouse supports everything/text/box/points prompts with Python inference, Gradio UI, HuggingFace demos, and YOLOv8 integration. Run it locally in 40ms inference time on RTX 3090 - perfect for real-time applications like anomaly detection, salient object detection, and building extraction.
FastSAM: The 50x Faster Segment Anything Revolution
Lightning-Fast Performance with SAM-Quality Results
FastSAM from CASIA-LMC-Lab redefines image segmentation. Trained on just 2% of the SA-1B dataset, this CNN-based model matches Meta's Segment Anything (SAM) performance while running 50x faster.
Key Stats:
- 68M parameters (vs SAM-H's 0.6G)
- 40ms inference regardless of prompt count
- 2608MB GPU memory (vs SAM-H's 7060MB)
๐ 4 Powerful Prompt Modes
# Everything mode - segments everything
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg
# Text prompt
python Inference.py --img_path ./images/dogs.jpg --text_prompt "the yellow dog"
# Box prompt [x,y,w,h]
python Inference.py --box_prompt "[[570,200,230,400]]"
# Points prompt
python Inference.py --point_prompt "[[520,360],[620,300]]" --point_label "[1,0]"
๐ ๏ธ Quick Start (5 Minutes)
git clone https://github.com/CASIA-LMC-Lab/FastSAM.git
cd FastSAM
conda create -n FastSAM python=3.9
conda activate FastSAM
pip install -r requirements.txt
# Download FastSAM.pt checkpoint
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg
๐ Live Demos Available
- HuggingFace Space - Everything + Points mode
- Replicate Demo - All modes supported
- Gradio UI - Local web interface
- Colab Notebook - Zero setup testing
๐ Benchmark Results
| Method | Params | 1pt | 10pts | 100pts | E(64x64) |
|---|---|---|---|---|---|
| SAM-H | 0.6G | 446 | 464 | 627 | 6972 |
| SAM-B | 136M | 110 | 125 | 230 | 5417 |
| FastSAM | 68M | 40 | 40 | 40 | 40 |
๐ฌ Real-World Applications
- Edge Detection - BSDS500: ODS 0.750 (vs SAM 0.768)
- Object Proposals - COCO AR@1000: 63.7 (vs SAM-H 67.7)
- Instance Segmentation - COCO AP: 0.379
- Downstream Tasks: Anomaly Detection, Salient Object Detection, Building Extraction
๐ฏ Why Choose FastSAM?
โ
Production Ready - YOLOv8 Model Hub integration
โ
Developer Friendly - Python API + web demos
โ
Hardware Efficient - Runs on consumer GPUs
โ
Extensible - Training code released
โ
Community Driven - 8.3k stars, 26 contributors
Recent Updates (June 2024)
- Edge quality improvements merged to Ultralytics YOLOv8
- HuggingFace demo updated
- TensorRT optimization available
- Semantic FastSAM extension
FastSAM proves you don't need massive ViT models for state-of-the-art segmentation. Perfect for real-time applications where speed matters most.