Buy Aruino   Buy Arduino Uno on AliExpress

Creating a neural network without programming skills

We tell how to create a simple neural network in a few steps and teach it to recognize well-known entrepreneurs in photos.

Step 0. Understand how neural networks are arranged

Teachable Machine uses the image from the camera of the laptop as input data — what needs to be processed by the neural network. As output data - what the neural network should do after processing incoming data - you can use gif or sound.

For example, you can teach Teachable Machine to say “Hi” when your palm is raised upward. With a raised thumb - “Cool”, and with a surprised face with an open mouth - “Wow”.

First, you need to train the neural network. To do this, raise the palm and click on the “Train Green” button - the service takes several dozen shots to find a pattern in the images. A set of such images is called “dataset”.

Now it remains to choose the action that you need to call when recognizing the image - to pronounce the phrase, show the GIF or play the sound. Similarly, we teach the neural network to recognize a surprised face and thumb.

Once the neural network is trained, it can be used. Teachable Machine shows the coefficient of "confidence" - as far as the system is "confident" that it shows one of the skills. Teachable Machine short video:

Step 1. Preparing the computer for work with the neural network

Now we will make our neural network, which, when sending the image, will report on what is shown in the picture. First, we will teach the neural network to recognize the flowers in the picture: chamomile, sunflower, dandelion, tulip or rose.

To create your own neural network, you need Python, one of the most minimalist and common programming languages, and TensorFlow is Google’s open library for creating and training neural networks.

Install Python

If you have Windows: download the installer from the official Python website and run it. When installing you need to tick "Add Python to PATH".

On macOS, Python can be installed immediately via Terminal:

brew install python

To work with a neural network, Python 2.7 or higher is suitable.

Installing a virtual environment

Open the command line on Windows or Terminal on macOS and consistently enter several commands:

pip install --upgrade virtualenv
virtualenv --system-site-packages Name
source Name/bin/activate

A tool for running programs in a virtual environment will be installed on the computer. It will allow you to install and run all libraries and applications within the same folder - in the command, it is designated as “Name”.

Install TensorFlow

Enter the command:

pip install tensorflow

Now that's all, the TensorFlow library is installed in the selected folder. On macOS, it is located at Macintosh HD/Users/User_name/, on Windows - at the root of C://.

You can check the library operation by entering the following commands:

python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow')
sess = tf.Session()
print(sess.run(hello))

If the installation was successful, the phrase “Hello, Tensorflow” will appear on the screen.

Step 2. Add a classifier

The classifier is a tool that allows machine learning methods to understand what an unknown object belongs to. For example, the classifier will help to understand where the plant is in the picture and what kind of flower it is.

Open the “Tensorflow for poets” page on Github, click on the “Clone or download” button and download the classifier in a ZIP file format.

Then unpack the archive into the folder created in the second step.

Step 3. Add a dataset

The data set is needed for training the neural network. These are input data, on the basis of which the neural network will learn to understand which flower is located in the picture.

First, download the dataset of Google with colors. In our example, this is a set of small photos sorted by folders with their names.

The contents of the archive must be unpacked into the classifier's /tf_files folder.

Step 4. Retrain the model

Now we need to start training the neural network so that it analyzes the pictures from the dataset and understands with the help of the classifier how and what type of flower looks like.

Go to the folder with the classifier

Open the command line and enter the command to go to the folder with the classifier.

Windows:

cd C://Name/

macOS:

cd Name

Starting the learning process

python scripts/retrain.py --output_graph=tf_files/retrained_graph.pb --output_labels=tf_files/retrained_labels.txt --image_dir=tf_files/flower_photos

What is indicated in the command:

  • retrain.py is the name of the Python script that is responsible for starting the learning process of the neural network.
  • output_graph - creates a new file with a data graph. It will be used to determine what is in the picture.
  • output_labels - create a new file with tags. In our example, these are daisies, sunflowers, dandelions, tulips or roses.
  • image_dir - the path to the folder where the images with flowers are located.

The program will begin to create bottleneck text files — these are special text files with compact image information. They help the classifier to quickly determine the appropriate picture.

The entire course of training takes about 4000 steps. Working time may take several tens of minutes - depending on the processor power.

After completing the analysis, the neural network will be able to recognize daisies, sunflowers, dandelions, tulips, and roses in any picture.

Before testing the neural network, open the label_image.py file located in the scripts folder in any text editor and replace the values in the lines:

input_height = 299
input_width = 299
input_mean = 0
input_std = 255
input_layer = "Mul"

Step 5. Testing

Select an image of the flower that you want to analyze, and place it in the folder with the neural network. Name the file <code>image.jpg</code>.

To run the analysis, enter the command:

python scripts/label_image.py --image image.jpg

The neural network will check the image for compliance with one of the labels and produce the result.

For example:

This means that with a probability of 72% in the picture shows a rose.

Step 6. We teach the neural network to recognize entrepreneurs

Now you can expand the capabilities of the neural network - to teach it to recognize not only flowers in the picture but also well-known entrepreneurs. For example, Elon Musk and Mark Zuckerberg.

To do this, add new images to the dataset and retrain the neural network.

We collect own dataset

To create a dataset with photos of entrepreneurs, you can use the Google Image Search and Chrome extension, which saves all the images on the page.

The folder with the images of Elon Mask should be placed in:

\tf_files\flower_photos\musk\

Similarly, all the images with the founder of Facebook are in the:

\tf_files\flower_photos\zuckerberg\folder

The more photos will be in the folders, the more accurately the neural network will recognize the entrepreneur on it.

Retrain and check

For retraining and launching a neural network, we use the same commands as in steps 4 and 5.

python scripts/retrain.py --output_graph=tf_files/retrained_graph.pb --output_labels=tf_files/retrained_labels.txt --image_dir=tf_files/flower_photos
python scripts/label_image.py --image image.jpg

Step 7. “Overclocking” the neural network

So that the learning process does not take a lot of time each time, the neural network is best run on a server with a GPU - it is designed specifically for such tasks.

The process of starting and training a neural network on a server is similar to a similar process on a computer.

Creating a server with Ubuntu

We need a server with the Ubuntu operating system. It can be installed independently, or - if the server is rented - through the company's technical support.

Install python

sudo apt-get install python3-pip python3-dev

Install TensorFlow

pip3 install tensorflow-gpu

Download classifier and data set

Similar to steps 2 and 3 on the computer, only the archives must be downloaded directly to the server.

Retrain model

python3 scripts/retrain.py --output_graph=tf_files/retrained_graph.pb --output_labels=tf_files/retrained_labels.txt --image_dir=tf_files/flower_photos

Testing the neural network

python scripts/label_image.py --image image.jpg

Ардуино+