Smart traffic light
While emergency vehicles speed up to save lives, they put themselves in a dangerous condition. We developed a smart traffic light system to guarantee the safety of the emergency vehicles. When emergency vehicles pass a crossroad, the sensors of traffic light know and send the message to the cloud so that the cloud controls the traffic lights to let emergency vehicles pass the traffic light at a higher speed.
Setup. Each camera detect the emergency vehicle in one direction.
Hardware Requirements
- Four Raspberry Pis with Micro SD cards
- LED Traffic lights
- Cameras
- Sound detectors
- AC Police car
Installation and setup
Client and Server
Use a laptop as the server to communicate with the Pis (Python code). On the server side, the server determines the mode of the current situation.
- Regular Mode: Normal traffic light, each color will last 5 seconds. Lights in north & south direction are orthogonal to west and east.
- Flashing Mode: Sound detector is triggered. Amber lights in all directions are turned on and blinking for 10 seconds.
- Emergency Mode: Both sound detector and camera is triggered. When Flashing Mode is on, if the camera detects the objects within 10 seconds, the Emergency mode will be turned on. The traffic light in the direction of that moving emergency vehicle will trun green, the orthogonal direction will turn red for 10 seconds.
Connection and sequence diagram.
Emergency Vehicle Detection
- Dataset: Emergency vs Non-Emergency Vehicle Classification dataset from Kaggle
- Contains the image name and correct class for 1646 train images.
- This dataset contains labels
- Does not contain the Yolo required annotation
- Generate annotation for YOLOV4:
- Generate image annotations in the images and annotations in the Darknet format.
- Use YOLOv4 Darknet detect all the vehicles
- Transform the output format to YOLOV4 required bounding box input format
- Output the detected bounding box
- Write the bounding box annotation to a .txt file
- Train YOLOv4 tiny darknet
- Customize training configuration
- Train custom YOLOv4 detector
- Save the YOLOv4 .weights file
- Convert Darknet Model to TensorFlow Lite
- Convert .weights file to apply in TensorFlow Lite use the tool TensorFlow-YOLOv4-TFLite
- Convert from Darknet to TensorFlow
- Convert from TensorFlow SavedModel to TensorFlow Lite
- Save .tflite file to use on Raspberry Pi
Trained YoloV4 model use self annotated emergency vehicle dataset.
Demo
Camera detect the emergency vehicle using Tensorflow LITE.
When the sound sensor detects the siren, amber light of all directions will be on to warn the pedestrians and other vehicles. The flashing mode will last 10 seconds, if the camera does not detects the emergency vehicle on any direction, the regular mode will be recovered.
When the flashing mode is on and the camera detects the emergency vehicle on one direction, the emergency mode will be on. Green lights is given to the emergency vehicle. When flashing mode is off, the camera cannot turn on emergency mode.