This repository implements YOLOv3 and Deep SORT in order to perfrom real-time object tracking. Yolov3 is an algorithm that uses deep convolutional neural networks to perform object detection. We can feed these object detections into Deep SORT (Simple Online and Realtime Tracking with a Deep Association Metric) in order for a real-time object tracker to be created.
📋 Example |
---|
Detailed tutorial by @The AI Guy on Object TrackingYoutube Tutorial.
🧠 Original Repo | 💡 Colab Notebook |
---|---|
Github | Colab |
# TensorFlow CPU
pip install -r requirements.txt
# TensorFlow GPU
pip install -r requirements-gpu.txt
# Tensorflow CPU
conda env create -f conda-cpu.yml
conda activate tracker-cpu
# Tensorflow GPU
conda env create -f conda-gpu.yml
conda activate tracker-gpu
# Ubuntu 18.04
sudo apt-add-repository -r ppa:graphics-drivers/ppa
sudo apt install nvidia-driver-430
# Windows/Other
https://www.nvidia.com/Download/index.aspx
For Linux: You can download official yolov3 weights pretrained on COCO dataset.
# yolov3
wget https://pjreddie.com/media/files/yolov3.weights -O weights/yolov3.weights
# yolov3-tiny
wget https://pjreddie.com/media/files/yolov3-tiny.weights -O weights/yolov3-tiny.weights
If you are on Windows, you can directly download the YOLOv3 weights from 👉 here
Learn How To Train Custom YOLOV3 Weights Here: https://www.youtube.com/watch?v=zJDUhGL26iU
Add your custom weights file to weights folder and your custom .names
file into data/labels folder.
Load the weights using load_weights.py
script. This will convert the yolov3 weights into TensorFlow .tf model files!
# yolov3
python load_weights.py
# yolov3-tiny
python load_weights.py --weights ./weights/yolov3-tiny.weights --output ./weights/yolov3-tiny.tf --tiny
# yolov3-custom (add --tiny flag if your custom weights were trained for tiny model)
python load_weights.py --weights ./weights/<YOUR CUSTOM WEIGHTS FILE> --output ./weights/yolov3-custom.tf --num_classes <# CLASSES>
After executing one of the above lines, you should see proper .tf files in your weights folder. You are now ready to run object tracker.
Now you can run the object tracker for whichever model you have created, pretrained, tiny, or custom.
# yolov3 on video
`python object_tracker.py --video ./data/video/test.mp4 --output ./data/video/results.avi`
#yolov3 on webcam
`python object_tracker.py --video 0 --output ./data/video/results.avi` (May not properly in Colab)
#yolov3-tiny
`python object_tracker.py --video ./data/video/test.mp4 --output ./data/video/results.avi --weights ./weights/yolov3-tiny.tf --tiny`
#yolov3-custom (add --tiny flag if your custom weights were trained for tiny model)
python object_tracker.py --video ./data/video/test.mp4 --output ./data/video/results.avi --weights ./weights/yolov3-custom.tf --num_classes <# CLASSES> --classes ./data/labels/<YOUR CUSTOM .names FILE>
The output flag saves your object tracker results as an avi file for you to watch back. It is not necessary to have the flag if you don't want to save the resulting video.
There is a test video uploaded in the data/video folder called test.mp4. If you have followed all the steps properly then you should see the output as below by running first command.
python object_tracker.py --video ./data/video/test.mp4 --output ./data/video/results.avi