Basic Deep Learning on the Raspberry Pi

Just a Heads Up

I’m not an expert on deep learning. I’m just sharing with you as I learn. Also, I wouldn’t have been able to make this post if Pete Warden didn’t have such excellent README files in his Github repo. Check out his blog as well! We will be using the DeepBeliefSDK in this post today.

neural sketch

Example of Deep Learning

Taking an image and evaluating it with a neural network model in order to make a conclusion as to what is in the image. Thats a super simplified explanation. I’m not educated enough on the subject to go into further detail. Haha

Deep Learning on the Raspberry Pi

We’ll be working with binaries today so we need to be aware that what may work on original Raspberry Pi will not work on the Raspberry Pi 2. This is because they have two different processors. In this tutorial I will be using a Raspberry Pi B+ that uses the original processor.

Let’s Get Started

First we need to expand our GPU memory. Processing images will require the use of more memory.

sudo raspi-config

Select ‘Advanced Options’, then select ‘Memory Split’. We want to type in the highest number, in my case that’s ‘256’. Select ‘Ok’, then ‘Finish’ and reboot.

Once you get back to the command line, we’ll want to clone Pete’s github repo.

git clone https://github.com/jetpacapp/DeepBeliefSDK.git

Then install..

cd DeepBeliefSDK/RaspberryPiLibrary
sudo ./install.sh

Then..

cd ../examples/SimpleLinux/
make
./deepbelief 

##Now our Pi can start analyzing images! If you add images to the SimpleLinux folder you can now reference them. We are given one to start ‘lena.png’. Which is a picture of woman.

The command looks like this..

sudo deepbelief lena.png

Just swap out ‘lena.png’ for whatever image you want to analyze.

When it runs it will print out 1000 lines. Each line has 3 columns: List number, percentage in decimal and the last column is the object. The object with the highest percentage is the networks best guess as to the subject of the image.

Screenshot of DeepBelief Output

Reminder

You’ll want to make sure that ‘deepbelief’ is in your bin folder so the command is recognized.

Parsing the Output

At first I was just copying all the lines into a spreadsheet and sorting for the highest percentages. This works, but it gets old really quick. Bitpi’s Shane is working on a simple program that will parse this list. I’m sure someone has already created a similar program, possibly even Pete Warden.

Screenshot of DeepBelief sorted results

Above you can see that the networks best guesses were wigs and bonnet. If you look at the image, you can see why it might have guessed that.

lena image

Now try it with other images! It seems to be really great identifying cats! :)

Next Steps

This is a example of what can be done with a neural network, but a great next step would be to provide feedback to the network so it gets better at analysing… The ‘learning’ part of deep learning.

What do you want to see next?

Leave a question or comment below.