davies46
Posts: 5
Joined: Mon Apr 30, 2018 11:01 pm

Another Tensorflow/Keras installation from scratch

Fri May 18, 2018 4:58 pm

I found that due to various reasons covered elsewhere it goes more smoothly using the Mate distribution. Also using Python 3.4, because there's a tensorflow wheel for that.
There are probably some redundant steps here, but it got me to where I needed to be and I haven't the time to optimise it.

So starting from scratch I did:
Burn Mate for Pi, then partition a USB stick as swap, plug it in and use fdisk to identify the device (e.g. /dev/sda5), then do:
$ swapon <device>
See EKami: https://gist.github.com/EKami/9869ae634 ... -compiling

Make sure the distribution is fairly up to date:
$ sudo apt-get update
Also, auto-upgrade was annoying me, so:
$ sudo edit /etc/apt/apt.conf.d/20auto-upgrades and disable both
Then the following to get Python 3.4:
$ sudo apt-get install libssl-dev openssl
$ wget https://www.python.org/ftp/python/3.4.3 ... 4.3.tar.xz
$ tar xvf Python-3.4.3.tar.xz
$ cd Python-3.4.3/
$ ./configure # You can set a prefix here
$ make
$ sudo make install
Now the prequisites for TensorFlow:
$ sudo apt-get install python3-numpy
$ sudo apt-get install libblas-dev
$ sudo apt-get install liblapack-dev
$ sudo apt-get install python3-dev # Possibly already installed
$ sudo apt-get install libatlas-base-dev # Optional
$ sudo apt-get install gfortran
$ sudo apt-get install python3-setuptools # Possibly already installed
$ sudo pip3 install numpy
$ sudo apt-get install python3-scipy
$ sudo pi3 install scipy
$ sudo pip3 install scikit-learn
$ sudo apt-get install libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk
$ sudo pip3 install pillow
$ sudo apt-get install python3-h5py
$ sudo pip3 install h5py
You'll see there are a few apt-get installs as well as pip3 installs. Both required? Not sure, but this way worked.

Now get TensorFlow:
and install it:
$ sudo pip3 install tensorflow-1.1.0-cp34-cp34m-linux_armv7l.whl
Now install Keras:
$ sudo pip3 install keras
Finally do something weird with mock:
$ sudo pip3 uninstall mock
$ sudo pip3 install mock
Start up Python3 and ensure you can import the tensorflow and keras modules, and do useful stuff with them.
Finally, use shutdown -h now to switch it all off, then take an image copy of your SD card! I lost mine shortly after completing these steps and had to go around again.

The above is actually a mix-and-match from several different howtos, mostly on this forum, none of which worked out the box for me.

More credits and links:
nikhilraghava's blog http://www.instructables.com/id/Install ... erry-Pi-3/
samjabrahams: https://github.com/samjabrahams/tensorf ... spberry-pi
Tensorflow: https://github.com/tensorflow/tensorflo ... b/makefile
Adrian Rosebrock's Santa project page: https://www.pyimagesearch.com/2017/12/1 ... pberry-pi/
Installing Python 3.4 https://raspberrypi.stackexchange.com/q ... spberry-pi
Another Sam J Abraham's guide https://stackoverflow.com/questions/437 ... berry-pi-2

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: No registered users and 15 guests