Skip to main content

Get Started With Image Recognition Using TensorFlow and Raspberry Pi

The post Get Started With Image Recognition Using TensorFlow and Raspberry Pi appeared first on BardTech.

image-recognition-raspi-tensorflow

TensorFlow is Google’s Neural Network library. Given that machine learning is the hottest thing around currently, it is no surprise that Google are among the leaders in this new technology.

In this article, you will learn how to install TensorFlow on the Raspberry Pi, and run simple image classification on a pre-trained neural network.

Getting Started

To get started with image recognition, you will need a Raspberry Pi (any model will work) and an SD card with the Raspbian Stretch (9.0+) operating system (if you’re new to the Raspberry Pi, use our installation 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

You can use both Python 2.7 or Python 3.4+ for this tutorial. This example is for Python 3. For Python 2.7, replace Python3 with Python, and pip3 with pip throughout this tutorial.

Pip is a package manager for Python, usually installed as standard on Linux distributions. If you find you don’t have it, follow the install for Linux instructions in this article to install it.

Installing TensorFlow

Installing TensorFlow used to be quite a frustrating process, but a recent update makes it incredibly simple. While you can follow this tutorial without any prior knowledge, it might be worth understanding the basics of machine learning before trying it out.

Before installing TensorFlow, install the Atlas library.

sudo apt install libatlas-base-dev

Once that is finished install TensorFlow via pip3

pip3 install --user tensorflow

This will install TensorFlow for the logged in user. If you prefer to use a virtual environment , modify your code here to reflect this.

Testing TensorFlow

Once it has installed, you can test whether it is working with the TensorFlow equivalent of a Hello, world!

From the command line create a new Python script using nano or vim (If you aren’t sure which one to use, they both have advantages ) and name it something 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 your file by typing Y when prompted.

Run the code from the terminal:

python3 tftest.py

You should see “Hello, TensorFlow” printed. If you are running Python 3.5, you will get several runtime warnings. The official TensorFlow tutorials acknowledge that this happens, and to ignore it.

TensorFlow and Python3.5 - Ignorable error

It works! Now to do something interesting with TensorFlow.

Installing the Image Classifier

In the terminal, create a directory for the project in your home directory and navigate into it.

mkdir tf1
cd tf1

TensorFlow has a git repository with example models to try out. Clone the repository into the new directory:

git clone https://github.com/tensorflow/models.git

You want to use the image classification example, which can be found at models/tutorials/image/imagenet. Navigate to that folder now:

cd models/tutorials/image/imagenet

The standard image classifying script runs with a provided image of a panda:

Tiny TensorFlow Panda

To run the standard image classifier with the panda image provided enter:

python3 classify_image.py

This feeds an image of a panda to the neural network, which returns guesses as to what the image is with a value for its level of certainty.

TensorFlow Panda Classifying Output

As the output image shows, the neural net guessed correctly, with an almost 90 percent certainty. It also thought the image might contain an custard apple, but it was not very confident with that answer.

Using a Custom Image

The panda image proves that TensorFlow works, but that is perhaps unsurprising given it is the example the project provides. For a better test, you can give your own image to the neural net for classification. In this instance, you’ll be seeing if the TensorFlow neural net can identify George.

George the Dinosaur

Meet George. George is a dinosaur. To feed this image (available in cropped form here ) into the neural net, add arguments when running the script.

python3 classify_image.py --image_file=/home/pi/george.jpg

The image_file= following the script name allows the addition of any image by path. Lets see how this neural net did.

TensorFlow Dinosaur Classification Output

Not bad! While George is not a triceratops, the neural net classified the image as a dinosaur with a high degree of certainty when compared to the other options.

TensorFlow and Raspberry Pi, Ready to Go

This basic implementation of TensorFlow already has potential. This object recognition is happening on the Pi, and needs no internet connection to function. This means that with the addition of a Raspberry Pi camera module and a Raspberry Pi-suitable battery unit , the whole project could go portable.

Most tutorials only scratch the surface of a subject, but it has never been truer than in this case. Machine learning is an incredibly dense subject. One way to take your knowledge further would be by taking a dedicated course . In the meantime, get hands on with machine learning and the Raspberry Pi with these TensorFlow projects you can try yourself.

Read the full article: Get Started With Image Recognition Using TensorFlow and Raspberry Pi

Original Content By MakeUseOf

The post Get Started With Image Recognition Using TensorFlow and Raspberry Pi appeared first on BardTech.



Tags: DIY, Google TensorFlow, Image Recognition, Raspberry Pi, image, raspberry, recognition, started, tensorflow, using

Original link: here
via BardTech

Comments

Popular posts from this blog

How to change the PIM of a VeraCrypt volume

The developers of VeraCrypt introduced Personal Iterations Multiplier (PIM) functionality in the encryption program in version 1.12 . PIM stands for "Personal Iterations Multiplier". It is a parameter that was introduced in VeraCrypt 1.12 and whose value controls the number of iterations used by the header key derivation function. PIM is used by volumes even if the creator of the volume did not specify a value. It is an optional component that improves security: it adds another step to the authentication process similarly to two-factor authentication. The main difference is that the PIM value is fixed and not generated on the fly when requested. An attacker needs to know the master password and the PIM, if not set to default, to breach the encryption successfully and access the content of the drive or partition. A couple of good reasons exist to change the PIM value: It was leaked or stolen. The default value is used and that is not as secure as using a custom PIM. Yo...

Huawei Mate 20 Pro launched in India with Kirin 980 for ₹69,990 ($988)

For years, the highest-end Android flagship used to be defined by Samsung’s Galaxy Note series as the “best-of-the-best” Android phones. Google entered the premium smartphone segment in 2016 with the Google Pixel . In addition, one company that has been steadily improving its flagship phones is Huawei. Huawei has also been steadily increasing the prices of its flagship phones at the same rate. Indian consumers, however, were left out as Huawei had not opted to launch any Mate series phone in India before. This year, as the company’s strategy has changed, high-end flagship smartphone buyers now have another option to choose from. The Huawei P20 Pro was launched in India in April . Now, Huawei has launched the Huawei Mate 20 Pro in India—the first ever launch of a Mate series phone in the country. The Huawei Mate 20 Pro is the successor of the Huawei Mate 10 Pro . It’s positioned as a higher-end variant of the standard Huawei Mate 20. It should be noted that Huawei didn’t launch the s...

The 5 Best Free IPTV Apps to Watch Live TV on Android

It’s easier than ever to watch on-demand TV shows and movies on your Android device. But what about live TV? Yes, there are services like Sling and PlayStation Vue. However, if you know where to look, you don’t need to subscribe to their expensive plans. You can use free IPTV instead; you just need an IPTV app and an IPTV source. What Is an IPTV App? IPTV apps are a bit like Kodi; they are empty shells that can’t stream any content without some user input. You have the responsibility for adding channels, playlists, and other sources. Typically, you cannot use the apps to watch Netflix, Hulu, or direct content from other third-party providers. Here, we’re not interested in the best on-demand streaming apps or places to watch TV online. We are only looking at the IPTV apps themselves. Specifically, we want to know what the best IPTV apps on Android are. 1. Lazy IPTV Our first pick is Lazy IPTV. It supports M3U playlists in open-view, ZIP, and GZ formats. The app can also read pl...