DEV Community

0xkoji
0xkoji

Posted on

2 1

Setup Machine Learning Environment on Raspberry Pi

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay