Skip to main content

YOLOv8 with AS-One

Mongkok, HongKong

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:

AS-One with YOLOv8 Introduction

We can change the detector and tracker that is being used with anyone from this list:

Trackers

DeepSort

ModelModel FlagFPS-GPUFPS-CPU
DeepSort-ONNX-Yolov5sDEEPSORT133.2
DeepSort-Pytorch-Yolov5sDEEPSORT133.2

ByteTrack

ModelModel FlagFPS-GPUFPS-CPU
ByteTrack-ONNX-YOLOv5sBYTETRACK33.717.4
ByteTrack-Pytorch-Sample-YOLOv5sBYTETRACK33.717.4

NorFair

ModelModel FlagFPS-GPUFPS-CPU
tryolab-ONNX-YOLOv5sNORFAIR25.812
tryolab-Pytorch-YOLOv5sNORFAIR25.812

Detectors (Excerpt)

YOLOv8

Pytorch
Model Name / Model FlagFPS-GPUFPS-CPU
YOLOV8N_PYTORCH26.717.0
YOLOV8S_PYTORCH26.412.3
YOLOV8M_PYTORCH25.16.8
YOLOV8L_PYTORCH23.64.0
YOLOV8X_PYTORCH20.72.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:

AS-One with YOLOv8 Introduction

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

AS-One with YOLOv8 Introduction