ultralytics 8.3.38 SAM 2 video inference (#14851)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Signed-off-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com>
This commit is contained in:
parent
407815cf9e
commit
dcc9bd536f
16 changed files with 917 additions and 124 deletions
|
|
@ -194,6 +194,34 @@ SAM 2 can be utilized across a broad spectrum of tasks, including real-time vide
|
|||
yolo predict model=sam2.1_b.pt source=path/to/video.mp4
|
||||
```
|
||||
|
||||
#### Segment Video and Track objects
|
||||
|
||||
!!! example "Segment Video"
|
||||
|
||||
Segment the entire video content with specific prompts and track objects.
|
||||
|
||||
=== "Python"
|
||||
|
||||
```python
|
||||
from ultralytics.models.sam import SAM2VideoPredictor
|
||||
|
||||
# Create SAM2VideoPredictor
|
||||
overrides = dict(conf=0.25, task="segment", mode="predict", imgsz=1024, model="sam2_b.pt")
|
||||
predictor = SAM2VideoPredictor(overrides=overrides)
|
||||
|
||||
# Run inference with single point
|
||||
results = predictor(source="test.mp4", points=[920, 470], labels=1)
|
||||
|
||||
# Run inference with multiple points
|
||||
results = predictor(source="test.mp4", points=[[920, 470], [909, 138]], labels=[1, 1])
|
||||
|
||||
# Run inference with multiple points prompt per object
|
||||
results = predictor(source="test.mp4", points=[[[920, 470], [909, 138]]], labels=[[1, 1]])
|
||||
|
||||
# Run inference with negative points prompt
|
||||
results = predictor(source="test.mp4", points=[[[920, 470], [909, 138]]], labels=[[1, 0]])
|
||||
```
|
||||
|
||||
- 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 2 comparison vs YOLOv8
|
||||
|
|
|
|||
|
|
@ -17,4 +17,8 @@ keywords: Ultralytics, SAM, Segment Anything Model, SAM 2, Segment Anything Mode
|
|||
|
||||
## ::: ultralytics.models.sam.predict.SAM2Predictor
|
||||
|
||||
<br><br><hr><br>
|
||||
|
||||
## ::: ultralytics.models.sam.predict.SAM2VideoPredictor
|
||||
|
||||
<br><br>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue