Installing & Testing Google 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/v1.0.1/tensorflow-1.0.1-cp34-cp34m-linux_armv7l.whl
sudo pip3 install tensorflow-1.0.1-cp34-cp34m-linux_armv7l.whl

# For Python 3.3+
sudo pip3 uninstall mock
sudo pip3 install mock

And then,
Let’s code it below that

Ref.: https://www.tensorflow.org/get_started/

 

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))


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]

screenshot-2017-01-28-22-17-32

Advertisements

Author: iotmaker

I am interested in IoT, robot, figures & leadership. Also, I have spent almost every day of the past 15 years making robots or electronic inventions or computer programs.

24 thoughts on “Installing & Testing Google TensorFlow on Raspberry Pi2”

  1. Thank you for this post.
    I’m trying to install TensorFlow on a Raspberry Pi 2 but I’m facing some issues.
    The error I get is:
    This is not supported wheel on this platform
    The OS installed on is Raspian Jessie.
    Could you help me on this?

    Like

      1. I did but still got the same issue:
        tensorflow-1.0.1-cp34-cp34m-linux_armv7l.whl is not a supported wheel on this platform.
        Have you tried it on your Raspberry Pi 2?

        Like

      1. python3 gives the output:

        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

        hello = tf.constant(“Hello, TensorFlow!”)

        sess = tf.Session()

        print(sess.run(hello))

        Liked by 1 person

      1. No, I’m sorry.
        Just a quick question: I checked with uname and seems like I have armv6l. But as far as I understand tensorflow goes on armv7l. It is a bit strange, isn’t it?

        Like

  2. Hi there, thanks for helping. At the end the problem was the OS Raspbian.
    I changed to Ubuntu MATE 16.04 and the processor was recognized to be ARMv7 and not ARMv6 as for Raspbian.

    Liked by 1 person

    1. Just to let you know, I tried more times to install it on Raspbian Pixel with same negative result. It is fine on Ubuntu Mate but it takes a very long time.
      How fast is TF on Raspbian?

      Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s