A Slice of AI

Deep learning on a Raspberry Pi? No way! Yes way — researchers trained and ran a facial recognition model on-device by using a few tricks.

Nick Bild
27 days agoMachine Learning & AI
A Raspberry Pi 4 single-board computer (📷: Raspberry Pi)

Raspberry Pi single-board computers may be the workhorses of hobbyists developing experimental embedded systems, but they do have their limits. A Raspberry Pi is the perfect tool for building a home automation system or even a robot, but you would not want to use one for a deep learning application. Or would you? A pair of researchers at Kocaeli University recently showed that these capable little computers may be even more capable than most of us realize.

With the help of a few tricks, they showed that a Raspberry Pi can tackle some very challenging problems in machine learning, like facial recognition. Computer vision tasks such as facial recognition typically require a lot of computing horsepower to be practical, especially where real-time operation is required. So these types of algorithms generally run on beefier hardware, perhaps with a GPU or TPU to accelerate the machine learning operations. But in this case the team not only ran inferences on a Raspberry Pi, but they also trained the model on the same device, significantly upping the ante.

For this work, a Raspberry Pi 4 was selected. These computers sport a quad core Arm Cortex-A72 processor and, in this case, 4 GB of RAM. Not bad at all, yet not nearly as powerful as the desktop or laptop computer that you are probably reading this article on right now.

So how did the researchers manage to run (and train!) a facial recognition algorithm on this platform? It actually was not that hard. No mystical incantations required. It came down to two primary factors — they chose an appropriately-sized model for the hardware resources that were available, and they leveraged a technique called transfer learning.

While there are many model architecture options available, the team chose to work with MobileNetV2 and InceptionV3. These are relatively small models at 2.2 million and 23.8 million parameters, respectively, yet they are also noted for being very highly accurate. This allows them to fit within the memory constraints of the computer, and also limits the number of computations that are required so that inferences can run at an acceptable speed.

Training even models of these sizes would be completely impractical if it was done from scratch. With many millions of images in the training dataset, it would take far, far too long to complete. That is where transfer learning came in. Using this approach, a pretrained model is used as the starting point. It already has a lot of knowledge encoded into it about how to perform its task — in this case, recognize faces. Then the researchers further trained the model using a smaller dataset, consisting of only 1,000 images. That additional training allows the algorithm to adapt to a specific use case and recognize faces that are of interest to a particular application.

After training the models, MobileNetV2 was found to have achieved an average accuracy rate of 98 percent. InceptionV3 also performed pretty well, achieving an accuracy level of 91 percent. The training time was a bit lengthy at 102 minutes for MobileNetV2 and 186 minutes for InceptionV3, but considering that training is a one-time activity, it is not so bad.

A Raspberry Pi is not going to become the development platform of choice for machine learning engineers, but as this work demonstrated, it is quite possible to incorporate some impressive features into our projects. What ideas do you have for machine learning-powered applications on your Raspberry Pi?

Nick Bild
R&D, creativity, and building the next big thing you never knew you wanted are my specialties.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles