Skip to content

Commit

Permalink
ultralytics 8.2.83 fix SAM2 CLI usage (ultralytics#15871)
Browse files Browse the repository at this point in the history
Signed-off-by: UltralyticsAssistant <[email protected]>
Co-authored-by: UltralyticsAssistant <[email protected]>
  • Loading branch information
glenn-jocher and UltralyticsAssistant authored Aug 28, 2024
1 parent f8c5bf7 commit a222b94
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 52 deletions.
56 changes: 28 additions & 28 deletions docs/en/models/sam-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,47 +168,45 @@ SAM 2 can be utilized across a broad spectrum of tasks, including real-time vide

- This example demonstrates how SAM 2 can be used to segment the entire content of an image or video if no prompts (bboxes/points/masks) are provided.

## SAM comparison vs YOLOv8
## SAM 2 comparison vs YOLOv8

Here we compare Meta's smallest SAM model, SAM-b, with Ultralytics smallest segmentation model, [YOLOv8n-seg](../tasks/segment.md):
Here we compare Meta's smallest SAM 2 model, SAM2-t, with Ultralytics smallest segmentation model, [YOLOv8n-seg](../tasks/segment.md):

| Model | Size | Parameters | Speed (CPU) |
| ---------------------------------------------- | -------------------------- | ---------------------- | -------------------------- |
| Meta's SAM-b | 358 MB | 94.7 M | 51096 ms/im |
| [MobileSAM](mobile-sam.md) | 40.7 MB | 10.1 M | 46122 ms/im |
| [FastSAM-s](fast-sam.md) with YOLOv8 backbone | 23.7 MB | 11.8 M | 115 ms/im |
| Ultralytics [YOLOv8n-seg](../tasks/segment.md) | **6.7 MB** (53.4x smaller) | **3.4 M** (27.9x less) | **59 ms/im** (866x faster) |
| Model | Size<br><sup>(MB)</sup> | Parameters<br><sup>(M)</sup> | Speed (CPU)<br><sup>(ms/im)</sup> |
| ---------------------------------------------- | ----------------------- | ---------------------------- | --------------------------------- |
| [Meta SAM-b](sam.md) | 375 | 93.7 | 161440 |
| Meta SAM2-b | 162 | 80.8 | 121923 |
| Meta SAM2-t | 78.1 | 38.9 | 85155 |
| [MobileSAM](mobile-sam.md) | 40.7 | 10.1 | 98543 |
| [FastSAM-s](fast-sam.md) with YOLOv8 backbone | 23.7 | 11.8 | 140 |
| Ultralytics [YOLOv8n-seg](../tasks/segment.md) | **6.7** (11.7x smaller) | **3.4** (11.4x less) | **79.5** (1071x faster) |

This comparison shows the order-of-magnitude differences in the model sizes and speeds between models. Whereas SAM presents unique capabilities for automatic segmenting, it is not a direct competitor to YOLOv8 segment models, which are smaller, faster and more efficient.

Tests run on a 2023 Apple M2 Macbook with 16GB of RAM. To reproduce this test:
Tests run on a 2023 Apple M2 Macbook with 16GB of RAM using `torch==2.3.1` and `ultralytics==8.3.82`. To reproduce this test:

!!! Example

=== "Python"

```python
from ultralytics import SAM, YOLO, FastSAM
from ultralytics import ASSETS, SAM, YOLO, FastSAM

# Profile SAM-b
model = SAM("sam_b.pt")
model.info()
model("ultralytics/assets")

# Profile MobileSAM
model = SAM("mobile_sam.pt")
model.info()
model("ultralytics/assets")
# 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("ultralytics/assets")
model(ASSETS)

# Profile YOLOv8n-seg
model = YOLO("yolov8n-seg.pt")
model.info()
model("ultralytics/assets")
model(ASSETS)
```

## Auto-Annotation: Efficient Dataset Creation
Expand Down Expand Up @@ -331,11 +329,13 @@ This mechanism ensures continuity even when objects are temporarily obscured or

SAM 2 and Ultralytics YOLOv8 serve different purposes and excel in different areas. While SAM 2 is designed for comprehensive object segmentation with advanced features like zero-shot generalization and real-time performance, YOLOv8 is optimized for speed and efficiency in object detection and segmentation tasks. Here's a comparison:

| Model | Size | Parameters | Speed (CPU) |
| ---------------------------------------------- | -------------------------- | ---------------------- | -------------------------- |
| Meta's SAM-b | 358 MB | 94.7 M | 51096 ms/im |
| [MobileSAM](mobile-sam.md) | 40.7 MB | 10.1 M | 46122 ms/im |
| [FastSAM-s](fast-sam.md) with YOLOv8 backbone | 23.7 MB | 11.8 M | 115 ms/im |
| Ultralytics [YOLOv8n-seg](../tasks/segment.md) | **6.7 MB** (53.4x smaller) | **3.4 M** (27.9x less) | **59 ms/im** (866x faster) |
| Model | Size<br><sup>(MB)</sup> | Parameters<br><sup>(M)</sup> | Speed (CPU)<br><sup>(ms/im)</sup> |
| ---------------------------------------------- | ----------------------- | ---------------------------- | --------------------------------- |
| [Meta SAM-b](sam.md) | 375 | 93.7 | 161440 |
| Meta SAM2-b | 162 | 80.8 | 121923 |
| Meta SAM2-t | 78.1 | 38.9 | 85155 |
| [MobileSAM](mobile-sam.md) | 40.7 | 10.1 | 98543 |
| [FastSAM-s](fast-sam.md) with YOLOv8 backbone | 23.7 | 11.8 | 140 |
| Ultralytics [YOLOv8n-seg](../tasks/segment.md) | **6.7** (11.7x smaller) | **3.4** (11.4x less) | **79.5** (1071x faster) |

For more details, see the [SAM comparison vs YOLOv8](#sam-comparison-vs-yolov8) section.
For more details, see the [SAM 2 comparison vs YOLOv8](#sam-2-comparison-vs-yolov8) section.
32 changes: 14 additions & 18 deletions docs/en/models/sam.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ The Segment Anything Model can be employed for a multitude of downstream tasks t

Here we compare Meta's smallest SAM model, SAM-b, with Ultralytics smallest segmentation model, [YOLOv8n-seg](../tasks/segment.md):

| Model | Size | Parameters | Speed (CPU) |
| ---------------------------------------------- | -------------------------- | ---------------------- | -------------------------- |
| Meta's SAM-b | 358 MB | 94.7 M | 51096 ms/im |
| [MobileSAM](mobile-sam.md) | 40.7 MB | 10.1 M | 46122 ms/im |
| [FastSAM-s](fast-sam.md) with YOLOv8 backbone | 23.7 MB | 11.8 M | 115 ms/im |
| Ultralytics [YOLOv8n-seg](../tasks/segment.md) | **6.7 MB** (53.4x smaller) | **3.4 M** (27.9x less) | **59 ms/im** (866x faster) |
| Model | Size<br><sup>(MB)</sup> | Parameters<br><sup>(M)</sup> | Speed (CPU)<br><sup>(ms/im)</sup> |
| ---------------------------------------------- | ----------------------- | ---------------------------- | --------------------------------- |
| Meta SAM-b | 358 | 94.7 | 51096 |
| [MobileSAM](mobile-sam.md) | 40.7 | 10.1 | 46122 |
| [FastSAM-s](fast-sam.md) with YOLOv8 backbone | 23.7 | 11.8 | 115 |
| Ultralytics [YOLOv8n-seg](../tasks/segment.md) | **6.7** (53.4x smaller) | **3.4** (27.9x less) | **59** (866x faster) |

This comparison shows the order-of-magnitude differences in the model sizes and speeds between models. Whereas SAM presents unique capabilities for automatic segmenting, it is not a direct competitor to YOLOv8 segment models, which are smaller, faster and more efficient.

Expand All @@ -154,27 +154,23 @@ Tests run on a 2023 Apple M2 Macbook with 16GB of RAM. To reproduce this test:
=== "Python"

```python
from ultralytics import SAM, YOLO, FastSAM
from ultralytics import ASSETS, SAM, YOLO, FastSAM

# Profile SAM-b
model = SAM("sam_b.pt")
model.info()
model("ultralytics/assets")

# Profile MobileSAM
model = SAM("mobile_sam.pt")
model.info()
model("ultralytics/assets")
# Profile SAM-b, MobileSAM
for file in ["sam_b.pt", "mobile_sam.pt"]:
model = SAM(file)
model.info()
model(ASSETS)

# Profile FastSAM-s
model = FastSAM("FastSAM-s.pt")
model.info()
model("ultralytics/assets")
model(ASSETS)

# Profile YOLOv8n-seg
model = YOLO("yolov8n-seg.pt")
model.info()
model("ultralytics/assets")
model(ASSETS)
```

## Auto-Annotation: A Quick Path to Segmentation Datasets
Expand Down
2 changes: 1 addition & 1 deletion ultralytics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license

__version__ = "8.2.82"
__version__ = "8.2.83"

import os

Expand Down
6 changes: 1 addition & 5 deletions ultralytics/cfg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,7 @@ def entrypoint(debug=""):
from ultralytics import FastSAM

model = FastSAM(model)
elif "sam2" in stem:
from ultralytics import SAM2

model = SAM2(model)
elif "sam" in stem:
elif "sam_" in stem or "sam2_" in stem:
from ultralytics import SAM

model = SAM(model)
Expand Down

0 comments on commit a222b94

Please sign in to comment.