TensorFlow is Google’s neural network library. Considering that machine learning is the hottest thing right now, it’s no surprise that Google is one of the leaders in this new technology.
In this article, you will learn how to install TensorFlow on a Raspberry Pi and perform simple image classification on a pre-trained neural network.
To get started with image recognition, you need a Raspberry Pi (any model will do) and an SD card running Raspbian Stretch (9.0+) (if you’re new to Raspberry Pi, check out our setup guide).
Boot up the Pi and open a terminal window. Make sure your Pi is up to date and check your Python version.
sudo apt-get update python --version python3 --version
For this tutorial, you can use both Python 2.7 and Python 3.4+. This example is for Python 3. For Python 2.7, replace Python3 on the Python a pip3 on the pip in this tutorial.
Pip is a package manager for Python, usually installed as standard on Linux distributions.
Installing TensorFlow used to be a rather frustrating process, but a recent update makes it incredibly easy. While you can follow this tutorial without any prior knowledge, it might be worth getting familiar with the basics of machine learning before trying it out.
Install the library before installing TensorFlow Atlas .
sudo apt install libatlas-base-dev
After that, install TensorFlow via pip3.
pip3 install --user tensorflow
Once installed, you can check if it works with the TensorFlow equivalent Hello world!
From the command line, create a new Python script using nano or vim (if you’re not sure which one to use, they both have benefits) and name it easy to remember.
sudo nano tftest.py
Enter this code provided by Google for testing TensorFlow:
import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print(sess.run(hello))
If you are using nano, exit by pressing ctrl+X, and save the file by typing Y in response to a request.
Run the code from terminal: