Ultralytics YOLO27:

MobileSAM lightweight image segmentation model logo

Mobile Segment Anything (MobileSAM)#

MobileSAM is a compact, efficient image segmentation model purpose-built for mobile and edge devices. Designed to bring the power of Meta's Segment Anything Model (SAM) to environments with limited compute, MobileSAM delivers near-instant segmentation while maintaining compatibility with the original SAM pipeline. Whether you're developing real-time applications or lightweight deployments, MobileSAM provides impressive segmentation results with a fraction of the size and speed requirements of its predecessors.



Watch: How to Run Inference with MobileSAM using Ultralytics | Step-by-Step Guide 🎉

MobileSAM has been adopted in a variety of projects, including Grounding-SAM, AnyLabeling, and Segment Anything in 3D.

MobileSAM was trained on a single GPU using a 100k image dataset (1% of the original images) in less than a day.

Available Models, Supported Tasks, and Operating Modes#

The table below outlines the available MobileSAM model, its pretrained weights, supported tasks, and compatibility with different operating modes such as Inference, Validation, Training, and Export. Supported modes are indicated by ✅ and unsupported modes by ❌.

Model TypePretrained WeightsTasks SupportedTrainingValidationInferenceExport
MobileSAMmobile_sam.ptInstance Segmentation❌❌✅❌

MobileSAM Comparison vs YOLO#

The following comparison highlights the differences between Meta's SAM variants, MobileSAM, and Ultralytics segmentation models including YOLO26n-seg:

ModelSize
(MB)
Parameters
(M)
Speed (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.0x smaller)3.4 (11.4x less)24.8 (945x faster)
Ultralytics YOLO11n-seg6.2 (12.6x smaller)2.9 (13.4x less)24.3 (964x faster)
Ultralytics YOLO26n-seg6.7 (11.7x smaller)2.7 (14.4x less)25.2 (930x faster)

This comparison demonstrates the substantial differences in model size and speed between SAM variants and YOLO segmentation models. While SAM models offer unique automatic segmentation capabilities, YOLO models—especially YOLOv8n-seg, YOLO11n-seg and YOLO26n-seg—are significantly smaller, faster, and more computationally efficient.

SAM speeds measured with PyTorch, YOLO speeds measured with ONNX Runtime. Tests run on a 2025 Apple M4 Air with 16GB of RAM using torch==2.10.0, ultralytics==8.4.31, and onnxruntime==1.24.4. To reproduce these results:

Example
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, nms=False)  # YOLO26 NMS-free head; no-op for YOLOv8/YOLO11
    model = YOLO(onnx_path)
    model(ASSETS)

Adapting from SAM to MobileSAM#

MobileSAM retains the same pipeline as the original SAM, including pre-processing, post-processing, and all interfaces. This means you can transition from SAM to MobileSAM with minimal changes to your workflow.

The key difference is the image encoder: MobileSAM replaces the original ViT-H encoder (637M parameters) with a much smaller Tiny-ViT encoder (5M parameters). On a single GPU, MobileSAM processes an image in about 12ms (8ms for the encoder, 4ms for the mask decoder).

ViT-Based Image Encoder Comparison