tensorraspberry
Machine Learning is a great and exciting subject in computer science and the recent advances are very promising. The only disadvantage of all current developments is the necessity of having more and more powerful GPUs for the application of artificial intelligence (AI).
From my view artificial intelligence and machine learning can only go main-stream if they can run on smaller mobile devices such as the Raspberry Pi.
This is why I was very excited when I successfully installed TensorFlow, which is a popular machine learning library, on the Raspberry Pi 3. With below method it probably can be installed on older Pis too, but will certainly be slower.

Installation of TensorFlow in a Virtual Environment

The first thing to do is to intall the virtual environment as discribed in the TensorFlow website:

  1. Install pip and Virtualenv.
  2. Create a Virtualenv environment.
  3. Activate the Virtualenv environment and install TensorFlow in it.
  4. After the install you will activate the Virtualenv environment each time you want to use TensorFlow.

Here are the details of above steps:
1. Install pip and Virtualenv:

# Ubuntu/Linux 64-bit
$ sudo apt-get install python-pip python-dev python-virtualenv

2. Create a Virtualenv environment in the directory ~/tensorflow:

$ virtualenv --system-site-packages ~/tensorflow

3. Activate the environment:

$ source ~/tensorflow/bin/activate 
(tensorflow)$  # Your prompt should change

4. Install TensorFlow just as you would for a regular Pip installation. First select the Raspberry Pi binary to install:

# Ubuntu/Linux 64-bit, CPU only, Python 2.7
(tensorflow)$ export TF_BINARY_URL=https://github.com/samjabrahams/tensorflow-on-raspberry-pi/raw/master/bin/tensorflow-0.9.0-cp27-none-linux_armv7l.whl

Finally install TensorFlow for Python 2

(tensorflow)$ pip install --upgrade $TF_BINARY_URL

The last produces some exceptions. However TensorFlow is installed and can be imported in Python.

Testing TensorFlow on the Raspberry Pi

Try this simple TensorFlow Hello World example:

'''
HelloWorld example using TensorFlow library.
Author: Aymeric Damien
Project: https://github.com/aymericdamien/TensorFlow-Examples/
'''

from __future__ import print_function

import tensorflow as tf

# Simple hello world using TensorFlow

# Create a Constant op
# The op is added as a node to the default graph.
#
# The value returned by the constructor represents the output
# of the Constant op.
hello = tf.constant('Hello, TensorFlow!')

# Start tf session
sess = tf.Session()

# Run the op
print(sess.run(hello))

Or test with TensorFlow Example:

$ python
...
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>>print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>>

Summary

Thanks to the work of Sam Abrahams TensorFlow now can be installed on the Raspberry Pi and you can learn Machine Learning skills just using the $35 Pi. This is very exciting, as it opens the world of Machine Learning to hobbyists who want to apply this to their mobile devices or robots.

I can’t wait to add to this article in the following days further examples.
And I also can’t wait to read about your thoughts and insights into this exciting field.