This project aims to create a vehicle tracking and counting system using the YOLOv8 and ByteTrack models. It offers a reliable and efficient system for analyzing traffic flow, monitoring congestion, and enhancing overall road safety. The main components of the project are:
- YOLOv8: The YOLOv8 model from Ultralytics is utilized for accurate and real-time vehicle detection.
- ByteTrack: ByteTrack algorithm is employed for multi-object tracking, ensuring smooth and reliable tracking of vehicles across frames.
- Line Counter: We use the supervision library to count the number of vehicles entering or leaving a region.
- TensorRT Inference: Export the model to TensorRT format to speed up inference.
To use this repository, we need to set up our environment with its required libraries. The steps are:
-
Clone the repository:
git clone https://github.com/arief25ramadhan/vehicle-tracking-counting.git -
Go to the repository, and install dependencies:
cd vehicle-tracking-counting pip install -r requirements.txt -
Inside this current repo, clone the ByteTrack Libraries:
git clone https://github.com/ifzhang/ByteTrack.git -
Install ByteTrack dependencies:
cd ByteTrack # workaround related to https://github.com/roboflow/notebooks/issues/80 sed -i 's/onnx==1.8.1/onnx==1.9.0/g' requirements.txt pip install -r requirements.txt python3 setup.py develop pip install cython_bbox onemetric loguru lap thop
To perform inference using the vehicle tracker and counter pipeline:
-
Go to
main.py. In the last few lines, change theinput_video,output_videoanduse_tensorrtvariables accordingly. Theinput_videorefers to the video we want to perform tracking and counting on, while theoutput_videois the desired path of the prediction. Theuse_tensorrtis a boolean variable indicating whether to use TensorRT format for a quicker inference time. -
Save changes.
-
Run detection and tracking by executing this command in your terminal:
python main.py -
The predicted video should be available in the output_video path. Figure below displays the example frame of the predicted video.
This project is heavily based on tutorial by Roboflow in this colab notebook. It works by combining the YOLOv8 model from Ultralytics and ByteTrack model developed by Yifu Zhange, et al. The links to the YOLOv8 and and ByteTrack repository are:
- YOLOv8: Link to YOLOv8 repository
- ByteTrack: Link to ByteTrack repository