Link to this sectionFast Segment Anything Model (FastSAM)#
Fast Segment Anything Model(FastSAM)은 Segment Anything 작업을 위한 새롭고 실시간 CNN 기반 솔루션입니다. 이 작업은 다양한 사용자 상호 작용 프롬프트에 기반하여 이미지 내의 모든 객체를 세그멘테이션하도록 설계되었습니다. FastSAM은 경쟁력 있는 성능을 유지하면서 계산 요구 사항을 크게 줄여, 다양한 비전 작업에 실용적인 선택지가 됩니다.
Watch: Object Tracking using FastSAM with Ultralytics
Link to this section모델 아키텍처#

Link to this section개요#
FastSAM is designed to address the limitations of the Segment Anything Model (SAM), a heavy Transformer model with substantial computational resource requirements. The FastSAM decouples the segment anything task into two sequential stages: all-instance segmentation and prompt-guided selection. The first stage uses YOLOv8-seg to produce the segmentation masks of all instances in the image. In the second stage, it outputs the region-of-interest corresponding to the prompt.
Link to this section주요 특징#
-
실시간 솔루션: CNN의 계산 효율성을 활용하여, FastSAM은 segment anything 작업을 위한 실시간 솔루션을 제공하며, 빠른 결과를 요구하는 산업 분야의 애플리케이션에 매우 유용합니다.
-
효율성 및 성능: FastSAM은 성능 품질을 저하시키지 않으면서 계산 및 자원 요구 사항을 크게 줄여줍니다. SAM과 비교 가능한 성능을 달성하면서도 계산 자원을 대폭 절감하여 실시간 적용을 가능하게 합니다.
-
프롬프트 기반 세그멘테이션: FastSAM은 다양한 사용자 상호 작용 프롬프트의 안내에 따라 이미지 내의 모든 객체를 세그먼트할 수 있으며, 다양한 시나리오에서 유연성과 적응성을 제공합니다.
-
YOLOv8-seg 기반: FastSAM은 인스턴스 세그멘테이션 브랜치를 갖춘 객체 탐지기인 YOLOv8-seg를 기반으로 합니다. 이를 통해 이미지 내 모든 인스턴스의 세그멘테이션 마스크를 효과적으로 생성할 수 있습니다.
-
벤치마크에서의 경쟁력 있는 결과: MS COCO의 객체 제안 작업에서, FastSAM은 단일 NVIDIA RTX 3090 환경에서 SAM보다 훨씬 빠른 속도로 높은 점수를 달성하여 그 효율성과 성능을 입증했습니다.
-
실용적인 애플리케이션: 제안된 접근 방식은 현재 방식보다 수십 배 또는 수백 배 더 빠른 속도로 수많은 비전 작업에 대해 새롭고 실용적인 솔루션을 제공합니다.
-
모델 압축 가능성: FastSAM은 구조에 인위적인 사전 지식을 도입하여 계산 노력을 크게 줄일 수 있는 경로의 타당성을 입증하며, 일반 비전 작업을 위한 대규모 모델 아키텍처에 새로운 가능성을 제시합니다.
Link to this section사용 가능한 모델, 지원되는 작업 및 작동 모드#
이 표는 특정 사전 훈련된 가중치를 가진 사용 가능한 모델, 지원하는 작업, 그리고 추론(Inference), 검증(Validation), 학습(Training), 내보내기(Export)와 같은 다양한 운영 모드와의 호환성을 보여줍니다. ✅ 이모지는 지원되는 모드를, ❌ 이모지는 지원되지 않는 모드를 나타냅니다.
| 모델 유형 | 사전 학습된 가중치 | 지원되는 작업 | 추론 | 검증 | 학습 | 내보내기(Export) |
|---|---|---|---|---|---|---|
| FastSAM-s | FastSAM-s.pt | 인스턴스 세분화(Instance Segmentation) | ✅ | ❌ | ❌ | ✅ |
| FastSAM-x | FastSAM-x.pt | 인스턴스 세분화(Instance Segmentation) | ✅ | ❌ | ❌ | ✅ |
Link to this sectionFastSAM과 YOLO 비교#
여기에서는 가장 작은 SAM2-t 변형을 포함하여 Meta의 SAM 2 모델을 YOLO26n-seg를 포함한 Ultralytics 세그멘테이션 모델과 비교합니다:
| 모델 | 크기 (MB) | 매개변수 (M) | 속도 (CPU) (ms/im) |
|---|---|---|---|
| Meta SAM-b | 375 | 93.7 | 41703 |
| Meta SAM2-b | 162 | 80.8 | 28867 |
| Meta SAM2-t | 78.1 | 38.9 | 23430 |
| MobileSAM | 40.7 | 10.1 | 23802 |
| FastSAM-s with YOLOv8 backbone | 23.9 | 11.8 | 58.0 |
| Ultralytics YOLOv8n-seg | 7.1 (11.0배 작음) | 3.4 (11.4배 적음) | 24.8 (945배 빠름) |
| Ultralytics YOLO11n-seg | 6.2 (12.6배 작음) | 2.9 (13.4배 적음) | 24.3 (964배 빠름) |
| Ultralytics YOLO26n-seg | 6.7 (11.7배 작음) | 2.7 (14.4배 적음) | 25.2 (930배 빠름) |
이 비교는 SAM 변형 모델과 YOLO 세그멘테이션 모델 간의 모델 크기와 속도에 대한 상당한 차이를 보여줍니다. SAM이 고유한 자동 세그멘테이션 기능을 제공하는 반면, YOLO 모델(특히 YOLOv8n-seg, YOLO11n-seg 및 YOLO26n-seg)은 훨씬 작고 빠르며 계산 효율성이 뛰어납니다.
SAM 속도는 PyTorch로 측정되었으며, YOLO 속도는 ONNX Runtime으로 측정되었습니다. 테스트는 torch==2.10.0, ultralytics==8.4.31 및 onnxruntime==1.24.4를 사용하여 16GB RAM이 탑재된 2025 Apple M4 Air에서 수행되었습니다. 이 테스트를 재현하려면:
from ultralytics import ASSETS, SAM, YOLO, FastSAM
# Profile SAM2-t, SAM2-b, SAM-b, MobileSAM
for file in ["sam_b.pt", "sam2_b.pt", "sam2_t.pt", "mobile_sam.pt"]:
model = SAM(file)
model.info()
model(ASSETS)
# Profile FastSAM-s
model = FastSAM("FastSAM-s.pt")
model.info()
model(ASSETS)
# Profile YOLO models (ONNX)
for file_name in ["yolov8n-seg.pt", "yolo11n-seg.pt", "yolo26n-seg.pt"]:
model = YOLO(file_name)
model.info()
onnx_path = model.export(format="onnx", dynamic=True)
model = YOLO(onnx_path)
model(ASSETS)Link to this section사용 예시#
FastSAM 모델은 귀하의 Python 애플리케이션에 쉽게 통합할 수 있습니다. Ultralytics는 개발을 간소화하기 위해 사용자 친화적인 Python API 및 CLI 명령을 제공합니다.
Link to this sectionPredict 사용법#
이미지에서 객체 탐지를 수행하려면 아래와 같이 predict 메서드를 사용하십시오:
from ultralytics import FastSAM
# Define an inference source
source = "path/to/bus.jpg"
# Create a FastSAM model
model = FastSAM("FastSAM-s.pt") # or FastSAM-x.pt
# Run inference on an image
everything_results = model(source, device="cpu", retina_masks=True, imgsz=1024, conf=0.4, iou=0.9)
# Run inference with bboxes prompt
results = model(source, bboxes=[439, 437, 524, 709])
# Run inference with points prompt
results = model(source, points=[[200, 200]], labels=[1])
# Run inference with texts prompt
results = model(source, texts="a photo of a dog")
# Run inference with bboxes and points and texts prompt at the same time
results = model(source, bboxes=[439, 437, 524, 709], points=[[200, 200]], labels=[1], texts="a photo of a dog")이 스니펫은 사전 학습된 모델을 로드하고 이미지에서 예측을 실행하는 간편함을 보여줍니다.
이 방법을 사용하면 이미지에 대해 추론을 실행하여 모든 세그먼트 results를 한 번에 얻고, 여러 번 추론을 실행하지 않고도 프롬프트 추론을 여러 번 수행할 수 있습니다.
from ultralytics.models.fastsam import FastSAMPredictor
# Create FastSAMPredictor
overrides = dict(conf=0.25, task="segment", mode="predict", model="FastSAM-s.pt", save=False, imgsz=1024)
predictor = FastSAMPredictor(overrides=overrides)
# Segment everything
everything_results = predictor("ultralytics/assets/bus.jpg")
# Prompt inference
bbox_results = predictor.prompt(everything_results, bboxes=[[200, 200, 300, 300]])
point_results = predictor.prompt(everything_results, points=[200, 200])
text_results = predictor.prompt(everything_results, texts="a photo of a dog")위의 예시에서 반환되는 모든 results는 예측된 마스크와 원본 이미지에 쉽게 접근할 수 있도록 해주는 Results 객체입니다.
Link to this sectionVal 사용법#
데이터셋에 대한 모델 검증은 다음과 같이 수행할 수 있습니다:
from ultralytics import FastSAM
# Create a FastSAM model
model = FastSAM("FastSAM-s.pt") # or FastSAM-x.pt
# Validate the model
results = model.val(data="coco8-seg.yaml")FastSAM은 단일 클래스 객체의 탐지 및 세그멘테이션만 지원한다는 점을 유의하십시오. 즉, 모든 객체를 동일한 클래스로 인식하고 세그먼트합니다. 따라서 데이터셋을 준비할 때 모든 객체 카테고리 ID를 0으로 변환해야 합니다.
Link to this sectionTrack 사용법#
이미지에서 객체 추적을 수행하려면 아래와 같이 track 메서드를 사용하십시오:
from ultralytics import FastSAM
# Create a FastSAM model
model = FastSAM("FastSAM-s.pt") # or FastSAM-x.pt
# Track with a FastSAM model on a video
results = model.track(source="path/to/video.mp4", imgsz=640)Link to this sectionFastSAM 공식 사용법#
FastSAM은 https://github.com/CASIA-IVA-Lab/FastSAM 저장소에서도 직접 제공됩니다. FastSAM을 사용하기 위해 수행할 일반적인 단계에 대한 간략한 개요입니다:
Link to this section설치#
-
FastSAM 저장소를 복제(Clone)합니다:
git clone https://github.com/CASIA-IVA-Lab/FastSAM.git -
Python 3.9를 사용하여 Conda 환경을 생성하고 활성화합니다:
conda create -n FastSAM python=3.9 conda activate FastSAM -
복제된 저장소로 이동하여 필요한 패키지를 설치합니다:
cd FastSAM pip install -r requirements.txt -
CLIP 모델을 설치합니다:
pip install git+https://github.com/ultralytics/CLIP.git
Link to this section사용 예제#
-
모델 체크포인트를 다운로드합니다.
-
추론을 위해 FastSAM을 사용합니다. 명령 예제:
-
이미지의 모든 것을 세그먼트합니다:
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg -
텍스트 프롬프트를 사용하여 특정 객체를 세그먼트합니다:
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg --text_prompt "the yellow dog" -
바운딩 박스 내의 객체를 세그먼트합니다 (xywh 형식으로 박스 좌표를 제공):
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg --box_prompt "[570,200,230,400]" -
특정 지점 근처의 객체를 세그먼트합니다:
python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg --point_prompt "[[520,360],[620,300]]" --point_label "[1,0]"
-
추가로, CASIA-IVA-Lab Colab 데모를 통해 FastSAM을 체험해 볼 수 있습니다.
Link to this section인용 및 감사의 글#
실시간 인스턴스 세그멘테이션 분야에 중요한 기여를 한 FastSAM 저자들에게 감사를 표합니다:
@misc{zhao2023fast,
title={Fast Segment Anything},
author={Xu Zhao and Wenchao Ding and Yongqi An and Yinglong Du and Tao Yu and Min Li and Ming Tang and Jinqiao Wang},
year={2023},
eprint={2306.12156},
archivePrefix={arXiv},
primaryClass={cs.CV}
}원래의 FastSAM 논문은 arXiv에서 찾을 수 있습니다. 저자들은 연구 결과를 공개했으며, 코드베이스는 GitHub에서 액세스할 수 있습니다. 해당 분야를 발전시키고 더 넓은 커뮤니티가 연구 결과를 접할 수 있게 해준 그들의 노력에 감사드립니다.
Link to this sectionFAQ#
Link to this sectionFastSAM이란 무엇이며 SAM과 어떻게 다른가요?#
FastSAM(Fast Segment Anything Model의 약자)은 객체 세그멘테이션 작업에서 높은 성능을 유지하면서 계산 요구 사항을 줄이도록 설계된 실시간 합성곱 신경망(CNN) 기반 솔루션입니다. 더 무거운 Transformer 기반 아키텍처를 사용하는 Segment Anything Model(SAM)과 달리, FastSAM은 Ultralytics YOLOv8-seg를 활용하여 전체 인스턴스 세그멘테이션과 프롬프트 기반 선택이라는 두 단계로 효율적인 인스턴스 세그멘테이션을 수행합니다.
Link to this sectionFastSAM은 어떻게 실시간 세그멘테이션 성능을 달성합니까?#
FastSAM은 YOLOv8-seg를 통한 전체 인스턴스 세그멘테이션과 프롬프트 기반 선택 단계로 세그멘테이션 작업을 분리하여 실시간 성능을 달성합니다. CNN의 계산 효율성을 활용함으로써, FastSAM은 경쟁력 있는 성능을 유지하면서도 계산 및 자원 요구 사항을 크게 줄입니다. 이러한 2단계 접근 방식은 FastSAM이 빠른 결과를 필요로 하는 애플리케이션에 적합한 빠르고 효율적인 세그멘테이션을 제공할 수 있게 합니다.
Link to this sectionFastSAM의 실용적인 애플리케이션은 무엇입니까?#
FastSAM은 실시간 세그멘테이션 성능을 요구하는 다양한 컴퓨터 비전 작업에 실용적입니다. 애플리케이션은 다음과 같습니다:
- 품질 관리 및 보증을 위한 산업 자동화
- 보안 및 감시를 위한 실시간 비디오 분석
- 객체 탐지 및 세그멘테이션을 위한 자율 주행 자동차
- 정밀하고 빠른 세그멘테이션 작업을 위한 의료 영상
다양한 사용자 상호 작용 프롬프트를 처리하는 능력 덕분에 FastSAM은 여러 시나리오에 적응 가능하고 유연합니다.
Link to this sectionPython에서 추론을 위해 FastSAM 모델을 어떻게 사용합니까?#
Python에서 추론을 위해 FastSAM을 사용하려면 아래 예제를 따라 할 수 있습니다:
from ultralytics import FastSAM
# Define an inference source
source = "path/to/bus.jpg"
# Create a FastSAM model
model = FastSAM("FastSAM-s.pt") # or FastSAM-x.pt
# Run inference on an image
everything_results = model(source, device="cpu", retina_masks=True, imgsz=1024, conf=0.4, iou=0.9)
# Run inference with bboxes prompt
results = model(source, bboxes=[439, 437, 524, 709])
# Run inference with points prompt
results = model(source, points=[[200, 200]], labels=[1])
# Run inference with texts prompt
results = model(source, texts="a photo of a dog")
# Run inference with bboxes and points and texts prompt at the same time
results = model(source, bboxes=[439, 437, 524, 709], points=[[200, 200]], labels=[1], texts="a photo of a dog")추론 방법에 대한 자세한 내용은 문서의 Predict 사용법 섹션을 확인하십시오.
Link to this sectionFastSAM은 세그멘테이션 작업을 위해 어떤 유형의 프롬프트를 지원합니까?#
FastSAM은 세그멘테이션 작업을 안내하기 위해 여러 프롬프트 유형을 지원합니다:
- Everything 프롬프트: 보이는 모든 객체에 대해 세그멘테이션을 생성합니다.
- 바운딩 박스(BBox) 프롬프트: 지정된 바운딩 박스 내의 객체를 세그먼트합니다.
- 텍스트 프롬프트: 설명 텍스트를 사용하여 설명과 일치하는 객체를 세그먼트합니다.
- 포인트 프롬프트: 사용자가 정의한 특정 지점 근처의 객체를 세그먼트합니다.
이러한 유연성 덕분에 FastSAM은 광범위한 사용자 상호 작용 시나리오에 적응할 수 있어 다양한 애플리케이션에서 유용성을 높입니다. 이러한 프롬프트 사용에 대한 자세한 정보는 주요 기능 섹션을 참조하십시오.