snehitvaddi / YOLOv3-Object-Tracking

Object tracking with YOLOv3, YOLOv3-tiny, Deep Sort and Tensorflow. This repository implements YOLOv3 and Deep SORT in order to perfrom real-time object tracking.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Object Tracking using YOLOv3, Deepsort and Tensorflow

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.

πŸ›  Video Example

πŸ“‹ Example
Demo of Object Tracker
Demo of Object Tracker

Detailed tutorial by @The AI Guy on Object TrackingYoutube Tutorial.

🧠 Original Repo πŸ’‘ Colab Notebook
Github Colab

πŸƒβ€β™‚οΈ Getting started

πŸ“₯ Pip

# TensorFlow CPU
pip install -r requirements.txt

# TensorFlow GPU
pip install -r requirements-gpu.txt

πŸ“₯ Conda (Recommended)

# 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

πŸ›  Nvidia Driver (For GPU, if you haven't set it up already)

# 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

πŸ“₯ Downloading official pretrained weights

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

Using Custom trained weights

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.

Saving your yolov3 weights as a TensorFlow model.

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.

Running the 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

πŸ“§ Acknowledgments

About

Object tracking with YOLOv3, YOLOv3-tiny, Deep Sort and Tensorflow. This repository implements YOLOv3 and Deep SORT in order to perfrom real-time object tracking.

License:Apache License 2.0


Languages

Language:Python 76.4%Language:Jupyter Notebook 23.6%