How to Install and Run Deep Learning DeepBeliefSDK on a RPI B2
DeepBeliefSDK is now running on the B2. It does not use the GPU but still runs stable. This setup works well because the camera can be used at the same time as DeepBelief jpcnn. I have been using the camera on the robot to take images and analyze them using two different ntwk files using a bash script that filters the results. The recognition quality is not very good probably due to the objects I am using and the varied backgrounds but still interesting to work with. I will look at doing this in a python script and implement actions depending on results. In the mean time this is a very basic demo script fyi.
Here are the install instructions for the B2
https://github.com/jetpacapp/DeepBelief ... berry-pi-2
Since this will install the complete eigen and DeepBeliefSDK in your /home/pi/projects folder, I decided to install the essential files in a separate folder called b2_learn per these commands
Code: Select all
sudo cp /home/pi//projects/DeepBeliefSDK/source/libjpcnn.so /usr/lib/
sudo cp /home/pi//projects/DeepBeliefSDK/source/src/include/libjpcnn.h /usr/include/
mkdir /home/pi/b2_learn
mkdir /home/pi/b2_learn/data
cp /home/pi//projects/DeepBeliefSDK/networks/data/* /home/pi/b2_learn/data
# copies dog.jpg and lena.jpg files that can be used for testing purposes.
mkdir /home/pi/b2_learn/networks
cp /home/pi//projects/DeepBeliefSDK/networks/* /home/pi/b2_learn/networks
cp /home/pi//projects/DeepBeliefSDK/source/jpcnn /usr/local/bin
Do a Test to ensure everything is working OK
Code: Select all
cd ~/b2_learn
echo "testing data/dog.jpg"
jpcnn -i data/dog.jpg -n networks/jetpac.ntwk -m s
echo "Sort list highest to lowest percent values"
jpcnn -i data/dog.jpg -n networks/jetpac.ntwk -m s | sort -nrk 1
I then created a demo script called deep_look.sh that uses the pi camera module. This analyses the camera image using more than one ntwk file and filters the results using awk. I currently filter results to display anything above 5 percent.. Also you don't need to specify /usr/local/bin/jpcnn since /usr//local/bin folder should be on the path but I have included it for clarity. This also does not save unique image names but overwrites the previous image. Like I said it is a quick demo.
Code: Select all
#!/bin/bash
# deep_look.sh written by Claude Pageau
image_name=./deep_look.jpg
while true
do
echo "Take photo ......" $image_name
raspistill -w 800 -h 600 -n -t 1 -o $image_name
# /usr/local/bin/jpcnn -i $1 -n ./networks/jetpac.ntwk -m s | awk 'int($1*100)>=50' | sort -nrk 1
echo "jeppack.ntwk"
# change the awk >= value to filter results for higher percentage value. I have set value to 5 percent.
# A higher value will eliminate results with a lower percentage than specified.
/usr/local/bin/jpcnn -i $image_name -n ./networks/jetpac.ntwk -m s | awk 'int($1*100)>=5' | sort -nrk 1
echo "ccv2012.ntwk"
/usr/local/bin/jpcnn -i $image_name -n ./networks/ccv2012.ntwk -m s | awk 'int($1*100)>=5' | sort -nrk 1
done
Here is another script that analyses a specific image passed as a parameter
Code: Select all
#!/bin/bash
# learn.sh written by Claude Pageau
if [ $# -eq 0 ]
then
echo "Error - Missing parameter"
echo "Usage $0 imagepath"
echo "eg $0 ./data/imagename.jpg"
exit 1
else
if [ -f $1 ]
then
# /usr/local/bin/jpcnn -i $1 -n ./networks/jetpac.ntwk -m s | awk 'int($1*100)>=50' | sort -nrk 1
echo "jetpack.ntwk"
/usr/local/bin/jpcnn -i $1 -n ./networks/jetpac.ntwk -m s | awk 'int($1*100)>=5' | sort -nrk 1
echo "ccv2012.ntwk"
/usr/local/bin/jpcnn -i $1 -n ./networks/ccv2012.ntwk -m s | awk 'int($1*100)>=5' | sort -nrk 1
else
echo "Error - Image file $1 Not Found."
exit 1
fi
fi
You can Modify the script or create your own to perform actions based on the results of the analysis.
Let me know if you do anything interesting. I am still playing with this technology.
Note some of the results you get can sometimes be pretty funny.
Regards
Claude ...