Meet YOLO26: next-gen vision AI.

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モデルアーキテクチャ#

Fast Segment Anything Model (FastSAM) architecture overview

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主な特徴#

  1. リアルタイムソリューション: CNNの計算効率を活用することで、FastSAMはsegment anythingタスクに対してリアルタイムなソリューションを提供し、迅速な結果を必要とする産業用アプリケーションにおいて価値を発揮します。

  2. 効率性とパフォーマンス: FastSAMは、パフォーマンス品質を損なうことなく、計算およびリソースの要求を大幅に削減します。SAMと同等のパフォーマンスを達成しながら、計算リソースを劇的に削減し、リアルタイムでの適用を可能にします。

  3. プロンプトガイド付きセグメンテーション: FastSAMは、様々なユーザーインタラクションプロンプトによってガイドされ、画像内のあらゆるオブジェクトをセグメント化でき、異なるシナリオにおいて柔軟性と適応性を提供します。

  4. YOLOv8-segベース: FastSAMは、インスタンスセグメンテーションブランチを備えたオブジェクト検出器であるYOLOv8-segに基づいています。これにより、画像内のすべてのインスタンスのセグメンテーションマスクを効果的に生成できます。

  5. ベンチマークにおける競争力のある結果: MS COCOのオブジェクト提案タスクにおいて、FastSAMは単一のNVIDIA RTX 3090上でSAMよりも大幅に高速に高スコアを達成しており、その効率性と能力を実証しています。

  6. 実用的なアプリケーション: 提案されたアプローチは、現在の手法よりも数十倍から数百倍高速であり、非常に高速で多数のビジョンタスクに対して新しい実用的なソリューションを提供します。

  7. モデル圧縮の実現可能性: FastSAMは、構造に人工的な事前知識を導入することで計算量を大幅に削減できるパスの実現可能性を示しており、一般的なビジョンタスクのための大規模モデルアーキテクチャの新たな可能性を切り拓いています。

Link to this section利用可能なモデル、サポートされているタスク、および動作モード#

この表は、利用可能なモデルとその特定の事前学習済みウェイト、サポートするタスク、および 推論検証トレーニングエクスポート といった異なる動作モードとの互換性を示しています。サポートされているモードは✅、サポートされていないモードは❌で示されています。

モデルタイプ学習済み重みサポートされているタスクInferenceValidationTrainingエクスポート
FastSAM-sFastSAM-s.ptInstance Segmentation
FastSAM-xFastSAM-x.ptInstance Segmentation

Link to this sectionFastSAMとYOLOの比較#

ここでは、MetaのSAM 2モデル(最小のSAM2-tバリアントを含む)と、YOLO26n-segを含むUltralyticsセグメンテーションモデルを比較します:

モデルサイズ
(MB)
パラメータ
(M)
速度 (CPU)
(ms/im)
Meta SAM-b37593.741703
Meta SAM2-b16280.828867
Meta SAM2-t78.138.923430
MobileSAM40.710.123802
FastSAM-s with YOLOv8 backbone23.911.858.0
Ultralytics YOLOv8n-seg7.1 (11.0倍小さい)3.4 (11.4倍少ない)24.8 (945倍高速)
Ultralytics YOLO11n-seg6.2 (12.6倍小さい)2.9 (13.4倍少ない)24.3 (964倍高速)
Ultralytics YOLO26n-seg6.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で測定されました。テストは2025年版Apple M4 Air(16GB RAM)上で torch==2.10.0ultralytics==8.4.31、および onnxruntime==1.24.4 を使用して実行されました。このテストを再現するには:

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")

このコードスニペットは、事前学習済みモデルを読み込み、画像に対して予測を実行するシンプルさを示しています。

FastSAMPredictorの例

このようにして、画像に対して推論を実行し、すべてのセグメント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")
注意

上記の例で返されるすべての resultsResults オブジェクトであり、予測されたマスクとソース画像に簡単にアクセスできます。

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インストール#

  1. FastSAMリポジトリをクローンします:

    git clone https://github.com/CASIA-IVA-Lab/FastSAM.git
  2. Python 3.9でConda環境を作成し、アクティベートします:

    conda create -n FastSAM python=3.9
    conda activate FastSAM
  3. クローンしたリポジトリに移動し、必要なパッケージをインストールします:

    cd FastSAM
    pip install -r requirements.txt
  4. CLIPモデルをインストールします:

    pip install git+https://github.com/ultralytics/CLIP.git

Link to this section使用例#

  1. モデルチェックポイントをダウンロードします。

  2. 推論に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を活用し、全インスタンスセグメンテーションとプロンプトガイド付き選択という2つのステージで効率的なインスタンスセグメンテーションを行います。

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 Usageセクションを確認してください。

Link to this sectionFastSAMはセグメンテーションタスクに対してどのようなタイプのプロンプトをサポートしていますか?#

FastSAMは、セグメンテーションタスクをガイドするために複数のプロンプトタイプをサポートしています:

  • Everythingプロンプト: 表示されているすべてのオブジェクトのセグメンテーションを生成します。
  • Bounding Box (BBox) プロンプト: 指定されたバウンディングボックス内のオブジェクトをセグメント化します。
  • テキストプロンプト: 説明文を使用して、その説明に一致するオブジェクトをセグメント化します。
  • ポイントプロンプト: ユーザーが定義した特定の点付近のオブジェクトをセグメント化します。

この柔軟性により、FastSAMは幅広いユーザーインタラクションシナリオに適応でき、様々なアプリケーション全体での有用性を高めています。これらのプロンプトの使用に関する詳細については、Key Featuresセクションを参照してください。

コメント