Setup Machine Learning Environment on Raspberry Pi

0xkoji - Mar 10 '19 - - Dev Community

I did this setup on Raspberry Pi3 and Pi3+.
Probably, for Pi zero this setup needs an extra step. (Will be added)

Install berryconda, tensorflow, keras, opencv

First change swapfile size

$ sudo vim /etc/dphys-swapfile
default 100MB --> 1024
$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start
$ free -m 
                total        used        free      shared  buff/cache   available
Mem:            875          65         378          11         431         747
Swap:          1023           0        1023
Enter fullscreen mode Exit fullscreen mode

Install berryconda

# download berryconda
$ wget https://github.com/jjhelmus/berryconda/releases/download/v2.0.0/Berryconda3-2.0.0-Linux-armv7l.sh
$ chmod +x Berryconda3-2.0.0-Linux-armv7l.sh
$ ./Berryconda3-2.0.0-Linux-armv7l.sh
Enter fullscreen mode Exit fullscreen mode

create virtual env & activate

$ conda create --name mlenv python=3.6
$ source activate mlenv

Enter fullscreen mode Exit fullscreen mode

Install Tensorflow

This process takes so much time (my case almost an hour).

$ sudo apt-get install libatlas-base-dev
$ pip install --user tensorflow
$ pip list | grep tensor
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
tensorboard (1.11.0)
tensorflow (1.11.0)
Enter fullscreen mode Exit fullscreen mode

Install Keras

This process also takes so much time (my case almost an hour).

$ sudo apt install libhdf5-serial-dev
$ pip install h5py
$ pip install keras
Enter fullscreen mode Exit fullscreen mode

Install OpenCV3

# Remove previous version
sudo apt autoremove libopencv3
# Install 
wget https://github.com/mt08xx/files/raw/master/opencv-rpi/libopencv3_3.4.3-20180907.1_armhf.deb
sudo apt install -y ./libopencv3_3.4.3-20180907.1_armhf.deb
sudo ldconfig
Enter fullscreen mode Exit fullscreen mode

Eventually, let's try run image classifier on Pi
This could take so much time.

$ git clone https://github.com/tensorflow/models.git
$ cd models/tutorials/image/imagenet
$ python classify_image.py
Enter fullscreen mode Exit fullscreen mode

My Raspberry Pi note repo

https://github.com/koji/RaspberryPi-Note

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .