Deep-SORT-YOLOv4
Deep SORT and YOLO v4 for people tracking and detection with Tensorflow backend.
With asynchronous processing
As you can see in the gif, asynchronous processing has better FPS but causes stuttering.
This code only detects and tracks people, but can be changed to detect other objects by changing lines 101 and 102 in yolo.py:
if predicted_class != 'person':
continue
Please note that Deep SORT is only trained on tracking people, so you'd need to train a model yourself for tracking other objects.
See https://github.com/nwojke/cosine_metric_learning.
Performance
Real-time FPS with video writing:
- ~4.3fps with YOLO v3
- ~10.6fps with YOLO v4
YOLO v4 performs much faster and appears to be more stable than YOLO v3. All tests were done using an Nvidia GTX 1070 8gb GPU
and an i7-8700k CPU.
Quick start
Download and convert the Darknet YOLO v4 model to a Keras model by modifying convert.py accordingly and run:
python convert.py
Then run demo.py:
python demo.py
Settings
By default, video writing is turned on and asynchronous processing is turned off. These can be edited in demo.py by changing:
writeVideo_flag = True
asyncVideo_flag = False
To change target file in demo.py:
file_path = 'video.webm'
To change output settings in demo.py:
out = cv2.VideoWriter('output_yolov4.avi', fourcc, 30, (w, h))
Training your own YOLO v4 model
See https://github.com/Ma-Dan/keras-yolo4.
Dependencies
- Tensorflow GPU 1.14
- Keras 2.3.1
- opencv-python 4.2.0
- imutils 0.5.3
- numpy 1.18.2
- sklearn