# Multi-Object Tracking with Ultralytics YOLO
<img width="1024" src="https://user-images.githubusercontent.com/26833433/243418637-1d6250fd-1515-4c10-a844-a32818ae6d46.png">
Object tracking in the realm of video analytics is a critical task that not only identifies the location and class of objects within the frame but also maintains a unique ID for each detected object as the video progresses. The applications are limitless—ranging from surveillance and security to real-time sports analytics.
## Why Choose Ultralytics YOLO for Object Tracking?
The output from Ultralytics trackers is consistent with standard object detection but has the added value of object IDs. This makes it easy to track objects in video streams and perform subsequent analytics. Here's why you should consider using Ultralytics YOLO for your object tracking needs:
- **Efficiency:** Process video streams in real-time without compromising accuracy.
- **Flexibility:** Supports multiple tracking algorithms and configurations.
- **Ease of Use:** Simple Python API and CLI options for quick integration and deployment.
- **Customizability:** Easy to use with custom trained YOLO models, allowing integration into domain-specific applications.
**Video Tutorial:** [Object Detection and Tracking with Ultralytics YOLOv8](https://www.youtube.com/embed/hHyHmOtmEgs?si=VNZtXmm45Nb9s-N-).
## Features at a Glance
Ultralytics YOLO extends its object detection features to provide robust and versatile object tracking:
- **Real-Time Tracking:** Seamlessly track objects in high-frame-rate videos.
- **Multiple Tracker Support:** Choose from a variety of established tracking algorithms.
- **Customizable Tracker Configurations:** Tailor the tracking algorithm to meet specific requirements by adjusting various parameters.
## Available Trackers
Ultralytics YOLO supports the following tracking algorithms. They can be enabled by passing the relevant YAML configuration file such as `tracker=tracker_type.yaml`:
- [BoT-SORT](https://github.com/NirAharon/BoT-SORT) - Use `botsort.yaml` to enable this tracker.
- [ByteTrack](https://github.com/ifzhang/ByteTrack) - Use `bytetrack.yaml` to enable this tracker.
The default tracker is BoT-SORT.
## Tracking
To run the tracker on video streams, use a trained Detect, Segment or Pose model such as YOLOv8n, YOLOv8n-seg and YOLOv8n-pose.
#### Python
```python
from ultralytics import YOLO
# Load an official or custom model
model = YOLO("yolov8n.pt") # Load an official Detect model
model = YOLO("yolov8n-seg.pt") # Load an official Segment model
model = YOLO("yolov8n-pose.pt") # Load an official Pose model
model = YOLO("path/to/best.pt") # Load a custom trained model
# Perform tracking with the model
results = model.track(
source="https://youtu.be/LNwODJXcvt4", show=True
) # Tracking with default tracker
results = model.track(
source="https://youtu.be/LNwODJXcvt4", show=True, tracker="bytetrack.yaml"
) # Tracking with ByteTrack tracker
```
#### CLI
```bash
# Perform tracking with various models using the command line interface
yolo track model=yolov8n.pt source="https://youtu.be/LNwODJXcvt4" # Official Detect model
yolo track model=yolov8n-seg.pt source="https://youtu.be/LNwODJXcvt4" # Official Segment model
yolo track model=yolov8n-pose.pt source="https://youtu.be/LNwODJXcvt4" # Official Pose model
yolo track model=path/to/best.pt source="https://youtu.be/LNwODJXcvt4" # Custom trained model
# Track using ByteTrack tracker
yolo track model=path/to/best.pt tracker="bytetrack.yaml"
```
As can be seen in the above usage, tracking is available for all Detect, Segment and Pose models run on videos or streaming sources.
## Configuration
### Tracking Arguments
Tracking configuration shares properties with Predict mode, such as `conf`, `iou`, and `show`. For further configurations, refer to the [Predict](https://docs.ultralytics.com/modes/predict/) model page.
#### Python
```python
from ultralytics import YOLO
# Configure the tracking parameters and run the tracker
model = YOLO("yolov8n.pt")
results = model.track(
source="https://youtu.be/LNwODJXcvt4", conf=0.3, iou=0.5, show=True
)
```
#### CLI
```bash
# Configure tracking parameters and run the tracker using the command line interface
yolo track model=yolov8n.pt source="https://youtu.be/LNwODJXcvt4" conf=0.3, iou=0.5 show
```
### Tracker Selection
Ultralytics also allows you to use a modified tracker configuration file. To do this, simply make a copy of a tracker config file (for example, `custom_tracker.yaml`) from [ultralytics/cfg/trackers](https://github.com/ultralytics/ultralytics/tree/main/ultralytics/cfg/trackers) and modify any configurations (except the `tracker_type`) as per your needs.
#### Python
```python
from ultralytics import YOLO
# Load the model and run the tracker with a custom configuration file
model = YOLO("yolov8n.pt")
results = model.track(
source="https://youtu.be/LNwODJXcvt4", tracker="custom_tracker.yaml"
)
```
#### CLI
```bash
# Load the model and run the tracker with a custom configuration file using the command line interface
yolo track model=yolov8n.pt source="https://youtu.be/LNwODJXcvt4" tracker='custom_tracker.yaml'
```
For a comprehensive list of tracking arguments, refer to the [ultralytics/cfg/trackers](https://github.com/ultralytics/ultralytics/tree/main/ultralytics/cfg/trackers) page.
## Python Examples
### Persisting Tracks Loop
Here is a Python script using OpenCV (`cv2`) and YOLOv8 to run object tracking on video frames. This script still assumes you have already installed the necessary packages (`opencv-python` and `ultralytics`). The `persist=True` argument tells the tracker than the current image or frame is the next in a sequence and to expect tracks from the previous image in the current image.
#### Python
```python
import cv2
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO("yolov8n.pt")
# Open the video file
video_path = "path/to/video.mp4"
cap = cv2.VideoCapture(video_path)
# Loop through the video frames
while cap.isOpened():
# Read a frame from the video
success, frame = cap.read()
if success:
# Run YOLOv8 tracking on the frame, persisting tracks between frames
results = model.track(frame, persist=True)
# Visualize the results on the frame
annotated_frame = results[0].plot()
# Display the annotated frame
cv2.imshow("YOLOv8 Tracking", annotated_frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord("q"):
break
else:
# Break the loop if the end of the video is reached
break
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()
```
Please note the change from `model(frame)` to `model.track(frame)`, which enables object tracking instead of simple detection. This modified script will run the tracker on each frame of the video, visualize the results, and display them in a window. The loop can be exited by pressing 'q'.
### Plotting Tracks Over Time
Visualizing object tracks over consecutive frames can provide valuable insights into the movement patterns and behavior of detected objects within a video. With Ultralytics YOLOv8, plotting these tracks is a seamless and efficient process.
In the following example, we demonstrate how to utilize YOLOv8's tracking capabilities to plot the movement of detected objects across multiple video frames. This script involves opening a video file, reading it frame by frame, and utilizing the YOLO model to identify and track various objects. By retaining the center points of the detected bounding boxes and connecting them, we can draw lines that represent the paths followed by the tracked objects.
#### Python
```python
from collections import defaultdict
import cv2
import numpy as np
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO("yolov8n.pt")
# Open the video file
v
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
AFPN的核心思想:AFPN主要通过引入渐近的特征融合策略,逐步整合底层、高层和顶层的特征到目标检测过程中。这种融合方式有助于减小不同层次特征间的语义差距,从而提升特征融合效果,使得检测模型能更好地适应不同层次的语义信息。 在YOLOv8中应用AFPN:AFPN被应用于两阶段和一阶段的目标检测框架,并在MS-COCO 2017验证和测试数据集上展示了优于其他先进特征金字塔网络的结果。 AFPN的代码实现:AFPN的实现涉及多个模块,例如ASFF3用于YOLO AFPN头部,它包含多个卷积层和上采样操作,以及对特征层的加权融合。 本资源包含了基于渐近特征金字塔网络(AFPN)优化YOLOv8目标检测模型的完整源码和配置文件。包括针对不同尺度目标检测的改进策略、多层次特征融合技术以及自适应特征选择机制。资源详细记录了从理论到实践的每一步,适合深度学习研究者和目标检测应用开发者学习和参考。在MS-COCO数据集上的训练和测试结果,验证了AFP优化后的YOLOv8在小目标检测精度和运行效率上的显著提升。
资源推荐
资源详情
资源评论
收起资源包目录
YOLOv8小目标检测优化AFPN网络实现 (381个子文件)
dcnv3_cpu.cpp 2KB
vision.cpp 699B
dcnv3_cuda.cu 8KB
dcnv3_im2col_cuda.cuh 52KB
dcnv3.h 3KB
dcnv3_cuda.h 2KB
dcnv3_cpu.h 2KB
bus.jpg 134KB
zidane.jpg 49KB
README.md 13KB
README.md 3KB
readme.md 566B
block.py 105KB
attention.py 58KB
exporter.py 49KB
metrics.py 48KB
augment.py 46KB
tasks.py 44KB
loss.py 34KB
__init__.py 33KB
trainer.py 32KB
orepa.py 32KB
plotting.py 31KB
ops.py 31KB
utils.py 29KB
tiny_encoder.py 28KB
autobackend.py 26KB
checks.py 25KB
encoders.py 24KB
torch_utils.py 24KB
EfficientFormerV2.py 24KB
predict.py 23KB
results.py 23KB
SwinTransformer.py 23KB
loaders.py 22KB
afpn.py 21KB
atss.py 20KB
model.py 19KB
__init__.py 19KB
head.py 18KB
efficientViT.py 18KB
benchmarks.py 18KB
byte_tracker.py 18KB
transformer.py 17KB
downloads.py 17KB
kernel_warehouse.py 17KB
predictor.py 16KB
prompt.py 16KB
dataset.py 16KB
loss.py 16KB
instance.py 16KB
head.py 15KB
repvit.py 15KB
CSwomTramsformer.py 15KB
CSwimTramsformer.py 15KB
dcnv3.py 15KB
kalman_filter.py 15KB
validator.py 14KB
comet.py 14KB
dynamic_snake_conv.py 13KB
tal.py 13KB
base.py 13KB
ops.py 13KB
VanillaNet.py 13KB
val.py 13KB
block.py 13KB
transformer.py 12KB
conv.py 12KB
converter.py 12KB
rep_block.py 12KB
gmc.py 12KB
val.py 12KB
fasternet.py 12KB
tuner.py 11KB
revcol.py 11KB
transformer.py 11KB
val.py 10KB
test.py 10KB
utils.py 9KB
dcnv3_func.py 8KB
bot_sort.py 8KB
session.py 8KB
convnextv2.py 8KB
amg.py 8KB
decoders.py 8KB
lsknet.py 7KB
wb.py 7KB
train.py 7KB
RFAConv.py 7KB
build.py 7KB
val.py 6KB
tuner.py 6KB
clearml.py 6KB
base.py 6KB
train.py 5KB
auth.py 5KB
files.py 5KB
dvc.py 5KB
val.py 5KB
build.py 5KB
共 381 条
- 1
- 2
- 3
- 4
资源评论
E寻数据
- 粉丝: 3318
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功