Build a traffic light object detection project based on YOLOv5. At present, the average traffic light detection accuracy based on YOLOv5s is mAP_0 = 0.93919, mAP_0: 0.95 = 0.63967, which basically meets the performance requirements of the business. In addition, in order to be deployed on the mobile Android platform, I have carried out model lightweight on YOLOv5s and developed a light-level version yolov5s05_416 and yolov5s05_320, which can achieve real-time detection and recognition effects on ordinary Android mobile phones. The CPU (4 thread) is about 30ms, and the GPU is about 25ms, which basically meets the performance requirements of the business.
First show the Python version of the traffic light detection demo effect:

Currently collected about 1W + traffic light (traffic light) detection data set: Traffic-Lights-Dataset-Domestic+Traffic-Lights-Dataset-Foreign:
main.py files to support testing of pictures, videos and cameras.
If you have any questions or need the full code or data or need customized development requirements, you can contact me Email Mail me : slowlon@foxmail.com
Python dependency environment, use pip to install, the project code is verified to run normally on Ubuntu system and Windows system and Andriod .
If you need to add/delete category data for training, or need a custom dataset for training, you can refer to the following steps:
Collect pictures, no less than 200 pictures are recommended
Use Labelme and other annotation tools to pull-box the target: labelme tool: GitHub — wkentaro/labelme: Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation).
Convert annotation format to VOC data format, reference tool: labelme/labelme2voc.py at main · wkentaro/labelme · GitHub
Generate training dataset train.txt and validation set val.txt file listModify the data paths of train and val in engine/configs/voc_local
Restart training
The official YOLOv5 provides YOLOv5l, YOLOv5m, YOLOv5s and other models. Considering that the CPU/GPU performance of the mobile phone is relatively weak, the direct deployment of yolov5s is very slow. So I lightweight the model on the basis of yolov5s, that is, the number of channels of the yolov5s model is reduced by half, and the model input is reduced from the original 640 × 640 to 416 × 416 or 320 × 320. The lightweight model I call yolov5s05. From the performance point of view, yolov5s05 is more than 5 times faster than yolov5s, while the mAP is reduced by 16% (0.93 → 0.77). For the mobile phone, this accuracy is barely acceptable.
The following is a comparison of the parameters and computations of yolov5s05 and yolov5s:

Considering the traffic light detection dataset, the target is relatively small, and the target boxes are almost all vertical rectangular boxes; the Anchor effect of directly multiplexing the original COCO may not be very good; therefore, here the label box of the traffic light dataset is re-clustered to obtain a new Anchor; The following table gives the Anchor results of yolov5s, yolov5s05_416 and yolov5s05_320 re-clustering:

Android version traffic light detection effect:

main.py files to support testing of pictures, videos and cameras.
If you have any questions or need the full code or data or need customized development requirements, you can contact me Email Mail me : slowlon@foxmail.com