YOLOv8 with AS-One
AS-One is a python wrapper for multiple detection and tracking algorithms all at one place. Different trackers such as ByteTrack, DeepSort or NorFair can be integrated with different versions of YOLO with minimum lines of code. This python wrapper provides YOLO models in both ONNX and PyTorch versions.
AS-One and YOLOv8
git clone https://github.com/augmentedstartups/AS-One.git /run/media/xiaodie/dev/as-one-yolov8/
cd as-one-yolov8
Installation
You can install the dependencies in a virtual environment - if you wish:
python3 -m venv .env
source .env/bin/activate
pip install numpy Cython
pip install cython-bbox
pip install asone
YOLO is build on PyTorch that needs to be installed with our without GPU support:
# for CPU
pip install torch torchvision
# for GPU
pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu113
pip show numpy Cython cython-bbox asone torch torchvision
Name: numpy
Version: 1.23.3
---
Name: Cython
Version: 0.29.33
---
Name: cython-bbox
Version: 0.1.3
---
Name: asone
Version: 0.1.2.dev17
---
Name: torch
Version: 1.13.1
---
Name: torchvision
Version: 0.14.1
Running AS-One
If you run main.py
to test tracker on the data/sample_videos/test.mp4
video:
python main.py data/sample_videos/test.mp4
The test code uses YOLOv7 and Bytetrack:
dt_obj = ASOne(
tracker=asone.BYTETRACK,
detector=asone.YOLOV7_PYTORCH,
weights=args.weights,
use_cuda=args.use_cuda
)
and starts tracking and counting cars in the test video:
We can change the detector and tracker that is being used with anyone from this list:
Trackers
DeepSort
Model | Model Flag | FPS-GPU | FPS-CPU |
---|---|---|---|
DeepSort-ONNX-Yolov5s | DEEPSORT | 13 | 3.2 |
DeepSort-Pytorch-Yolov5s | DEEPSORT | 13 | 3.2 |
ByteTrack
Model | Model Flag | FPS-GPU | FPS-CPU |
---|---|---|---|
ByteTrack-ONNX-YOLOv5s | BYTETRACK | 33.7 | 17.4 |
ByteTrack-Pytorch-Sample-YOLOv5s | BYTETRACK | 33.7 | 17.4 |
NorFair
Model | Model Flag | FPS-GPU | FPS-CPU |
---|---|---|---|
tryolab-ONNX-YOLOv5s | NORFAIR | 25.8 | 12 |
tryolab-Pytorch-YOLOv5s | NORFAIR | 25.8 | 12 |
Detectors (Excerpt)
YOLOv8
Pytorch | ||
---|---|---|
Model Name / Model Flag | FPS-GPU | FPS-CPU |
YOLOV8N_PYTORCH | 26.7 | 17.0 |
YOLOV8S_PYTORCH | 26.4 | 12.3 |
YOLOV8M_PYTORCH | 25.1 | 6.8 |
YOLOV8L_PYTORCH | 23.6 | 4.0 |
YOLOV8X_PYTORCH | 20.7 | 2.8 |
So to change to YOLOv8 we just have to replace it here main.py
:
dt_obj = ASOne(
tracker=asone.BYTETRACK,
detector=asone.YOLOV8M_PYTORCH,
weights=args.weights,
use_cuda=args.use_cuda
)
python main.py data/sample_videos/video2.mp4
And this time we are running YOLOv8:
The tracking function in main.py
also gives us a few more options - for example to draw trails on tracked moving objects:
track_fn = dt_obj.track_video(args.video_path,
output_dir=args.output_dir,
conf_thres=args.conf_thres,
iou_thres=args.iou_thres,
display=args.display,
draw_trails=args.draw_trails,
filter_classes=filter_classes,
class_names=None) # class_names=['License Plate'] for custom weights
Which we can set to true by adding the argument:
python main.py data/sample_videos/video2.mp4 --draw_trails