TensorFlow on Raspberry Pi2

Installing & Testing Google TensorFlow on Raspberry Pi2

*Let’s install TensorFlow.

sudo apt-get update
# For Python 3.3+
sudo apt-get install python3-pip python3-dev
 
# For Python 3.3+
wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v0.12.1/tensorflow-0.12.1-cp34-cp34m-linux_armv7l.whl
sudo pip3 install tensorflow-0.12.1-cp34-cp34m-linux_armv7l.whl
 
# For Python 3.3+
sudo pip3 uninstall mock
sudo pip3 install mock

reference

pi@raspberrypi:~ $ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> import numpy as np
>>>
>>> # Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
... x_data = np.random.rand(100).astype(np.float32)
>>> y_data = x_data * 0.1 + 0.3
>>>
>>> W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
>>> b = tf.Variable(tf.zeros([1]))
>>> y = W * x_data + b
>>>
>>> loss = tf.reduce_mean(tf.square(y - y_data))
>>> optimizer = tf.train.GradientDescentOptimizer(0.5)
>>> train = optimizer.minimize(loss)
>>>
>>> init = tf.global_variables_initializer()
>>>
>>> sess = tf.Session()
>>> sess.run(init)
>>>
>>> for step in range(201):
...     sess.run(train)
...     if step % 20 == 0:
...         print(step, sess.run(W), sess.run(b))
  • result
0 [ 0.2893075] [ 0.26960531]
20 [ 0.14367677] [ 0.27712572]
40 [ 0.11184501] [ 0.29379657]
60 [ 0.10321232] [ 0.29831767]
80 [ 0.10087116] [ 0.29954377]
100 [ 0.10023624] [ 0.29987627]
120 [ 0.10006408] [ 0.29996645]
140 [ 0.10001738] [ 0.29999092]
160 [ 0.1000047] [ 0.29999754]
180 [ 0.10000128] [ 0.29999936]
200 [ 0.10000037] [ 0.29999983]