This project aims to detect traffic light in real time using deep learning as a part of autonomous driving technology.
Implementation for all the traffic light types are done. But the final model is still being trained almost every day to make it better. Check the Download Trained Weights section to get your desired weight files and try the model on you system.
[x] Detecting red (circular) stop
sign.
[x] Detection green (circular) go
sign.
[x] Train on for night time detection => Working but not perfect. Better updates to come soon.
[x] Detecting warningLeft
sign.
[x] Detecting goLeft
sign.
[x] Detecting stopleft
sign.
[x] Detecting warning
sign.
[ ] Carla support => This one is a bit tricky.
Download the trained weights from here.
best_model_12.pt
: Trained for 67 epochs on all the traffic signs. Current mAP is 0.919This project uses the LISA Traffic Light Dataset.. Download the dataset from Kaggle here.
The current train/test split is 90/10. The input image size is 608x608. So, it might take a lot of time to train if you train on a nominal GPU. I have trained the model on Google Colab with Tesla T4 GPU/P100 GPU. One epoch took with all the classes around 1 hour on a Tesla T4 GPU. Also, check the cfg
folder and files before training. You have to use the cfg files corresponding to the number of classes you are training on. If you want to change the number of classes to train on, then you have to change the cfg file too. The current model has been trained on all 6 classes, so, the cfg file is yolov3-spp-6cls.cfg
.
Prepare the data. Please do take a look at the paths inside the prepare_labels.py
file and change them according to your preference and convenience.
python prepare_labels.py
Create the train and validation text files (Current train/validation split = 90/10).
python prepare_train_val.py
To train on your own system (The current model has been trained for 30 epochs.)
python train.py --data <your_data_folder>/traffic_light.data --batch 2 --cfg cfg/yolov3-spp-6cls.cfg --epochs 55 --weights "" --name from_scratch
python train.py --data <your_data_folder>/traffic_light.data --batch 4 --cfg cfg/yolov3-spp-6cls.cfg --epochs 55 --multi-scale --img-size 608 608 --weights weights/yolov3-spp-ultralytics.pt --name coco_pretrained
python train.py --data <your_data_folder>/traffic_light.data --batch 2 --cfg cfg/yolov3-spp-6cls.cfg --epochs <num_epochs_must_be_greater_than_previous_training> --multi-scale --img-size 608 608 --resume --weights weights/<your_weight_file>.pt --name <name_to_be_saved_with>
cfg
file is not used. Only python executables' argument parser img-size
argument is used.weights
folder.
python detect.py --source <path_to_your_test_video_file> --view-img --weights weights/<your_weight_file_name>.pt --img-size 608
video1.mp4
: https://www.youtube.com/watch?v=yJrW8werMUs.video2.mp4
: https://www.youtube.com/watch?v=pU8ThDYZcCc.# Traffic-Light-Detection-Using-YOLOv3video3.mp4
: https://www.youtube.com/watch?v=iS5sq9IELEo.video4.mp4
: https://www.youtube.com/watch?v=GfWskqDjeTE.video5.mp4
: https://www.youtube.com/watch?v=7HaJArMDKgI.video6.mp4
: https://www.youtube.com/watch?v=NK_HNF1C8yA.video7.mp4
: https://www.youtube.com/watch?v=w-W9esW3eqI.video8.mp4
: https://www.youtube.com/watch?v=RPDYLA8Rh_M.video9.mp4
: https://www.youtube.com/watch?v=imeV3Pm-ZLE.