Not So Fast! Building an ML-Powered Speed Trap

Last summer, developer Rob Lauer was looking for new family activities to replace those, such as soccer practices and Girl Scout meetings, that had been canceled due to concerns over COVID. His family started taking long walks around their hometown of Madison, Wisconsin and found that they were enjoying seeing parts of the city that they would have otherwise never visited. But Lauer noticed that these walks could also be a bit stressful at times, because of some drivers that were behaving recklessly behind the wheel. Always looking for a technological solution to his problems, Lauer came up with the idea of building a device to gauge the frequency of dangerous driving behaviors along a street. If a number of these devices were installed around the city, they would be able to provide information about the most, and least, safe places for pedestrians.

The basic idea that Lauer settled on was to use machine learning to determine when a car was driving by, then record the speed at which it was traveling and send that data to a dashboard hosted in the cloud. A Raspberry Pi 4 was chosen to provide the computational horsepower to run the machine learning algorithm, which was designed with the help of Edge Impulse. A Raspberry Pi Camera Module V2 was selected to capture images of the street, and when a car is detected, a OmniPreSense OPS243-A Doppler Radar Sensor records its speed of travel. That information is then transmitted to the cloud via cellular networks with a Blues Wireless Notecard. And if you happen to be near the device while it is operating, Lauer included a seven-segment display to show the vehicle’s speed.

Developing a prototype

This hardware was assembled in a custom plastic case, along with a 30,000 mAh USB-C battery pack capable of powering the device for up to 41 hours on a single charge. As Lauer noted, machine learning-based solutions are only as good as the model that underlies them, so he turned to Edge Impulse to help sort out the complexities of building this model and the associated data processing pipeline. As a first step, a selection of about 100 vehicle images were downloaded from the internet. This dataset was supplemented with some additional images that Lauer captured around town, then all of the images were uploaded to Edge Impulse.

According to Lauer, designing the data analysis pipeline was the easiest part of the project.  With the dataset uploaded, it was a matter of clicking a few buttons to create and train a neural network optimized for object detection. On the first attempt, validation of the model showed object detection accuracy had achieved 87% — this is quite impressive given the very small training dataset that was provided.  Adding further examples to the training dataset would be expected to improve this result and may be a worthwhile exercise for a future iteration of the device.

Validating the model

After a quick installation of Edge Impulse for Linux, the model was deployed directly to the Raspberry Pi, such that it was able to run inferences locally without needing to send any data to the cloud. Lauer wrote some simple Python scripts to glue the various pieces of hardware together and create a finished device implementing the full functionality, then he deployed that device on some streets in his neighborhood. After the device had been in the field for some time, Lauer checked in on the Ubidots dashboard and found some eye-opening statistics. In a 30 MPH speed zone, 50% of cars were speeding (defined as greater than or equal to 5 MPH over the speed limit). The highest speed recorded was 54 MPH, which is certainly cause for concern on residential streets.

Lauer had no plans to capture license plate numbers, or otherwise identify individual cars, but suggested that a network of these devices may be useful in helping a city create optimal plans for their traffic enforcement efforts. Full details and source code are available in the project write-up.


Want to see Edge Impulse in action? Schedule a demo today.

Comments

Subscribe

Are you interested in bringing machine learning intelligence to your devices? We're happy to help.

Subscribe to our newsletter