Install required dependencies:
pip install -r requirements.txt
Download the yolov3 weights by clicking here and then save them to the weights folder.
Load the weights using load_weights.py
script to convert the yolov3 weights into .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
#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.
load_weights.py:
--output: path to output
(default: './weights/yolov3.tf')
--[no]tiny: yolov3 or yolov3-tiny
(default: 'false')
--weights: path to weights file
(default: './weights/yolov3.weights')
--num_classes: number of classes in the model
(default: '80')
(an integer)
object_tracker.py:
--classes: path to classes file
(default: './data/labels/coco.names')
--video: path to input video (use 0 for webcam)
(default: './data/video/test.mp4')
--output: path to output video (remember to set right codec for given format. e.g. XVID for .avi)
(default: None)
--output_format: codec used in VideoWriter when saving video to file
(default: 'XVID)
--[no]tiny: yolov3 or yolov3-tiny
(default: 'false')
--weights: path to weights file
(default: './weights/yolov3.tf')
--num_classes: number of classes in the model
(default: '80')
(an integer)
--yolo_max_boxes: maximum number of detections at one time
(default: '100')
(an integer)
--yolo_iou_threshold: iou threshold for how close two boxes can be before they are detected as one box
(default: 0.5)
(a float)
--yolo_score_threshold: score threshold for confidence level in detection for detection to count
(default: 0.5)
(a float)