tensorflow introduction: architecture and example

Posted by lipsius at 2020-03-28

In this article I will go into the basics of Google TensorFlow and show you a small example of image recognition of handwritten digits.

What is TensorFlow?

TensorFlow is also used for many classic applications of machine learning. However, TensorFlow's strengths lie in the development of complex Deep Learning applications, such as text or image recognition.

A great advantage is that Deep Learning applications can be run on a GPU (graphics card), which makes numerical calculations particularly fast.

In addition to TensorFlow, there is a simplified interface called Keras, which is designed for the modular development of Deep Learning models. Keras is much easier to program and therefore suitable for starting Deep Learning.

Since October 2019, the TensorFlow 2.0 version has been published. In version 2.0, the model construction becomes simpler and above all the performance is significantly increased.

TensorFlow Architecture

For the development of analytical applications, the framework supports many different environments such as desktop, mobile, web and cloud.

The following Google architectural picture shows the possibilities of TensorFlow.

In TensorFlow, a model can be trained on different computing units: CPU, GPU and TPU. TPU stands for Tensor Processing Unit, these are specially designed by Google to speed up machine learning and are specifically designed for TF libraries. This is particularly noticeable with large amounts of data.

There are different possibilities for productive use: TF Serving, TF Lite (for mobile phones and Android applications), a JavaScript version of Js and other implementations such as in C.

TF-Lite and TF.js are particularly interesting, both of which are designed for mobile applications.

The Google Team has set up processes for GitHub and managed all requests. The TF community is large and very active with over 1.000 developers. The high number of reviews (130.000 stars in the middle of 2019) on GitHub also shows the keen interest in the project.

TF models (partly pre-trained)

A large library of (pre-trained) models is provided for free. The project distinguishes between "official models" and "research models".

The models are used via the TensorFlow high-level appi and are maintained for new versions of TF. This includes, for example, the well-known ResNet (suitable for object recognition in pictures), which we have already discussed in my article on Transfer Learning.

Famous Deppe Learning models from TF:

Further models available can be found in the GitHub Repo.

Prepared data sets for the learning process

In TF there is a wide range of defined training data that can be used for learning models.

Here is an example of how to retrieve the MNIST data set:

Example of image recognition

Simple example for TensorFlow image recognition of handwritten digits (MNIST dataset). Here we use the high-level API Keras, which makes our work much easier.

The import function of TF records provides us with the MNIST data broadly in a usable format. This allows us to directly create an artificial neural network:

To execute the code, I can recommend Google Colab, where you can use GPU computing for free.

After the fifth epoch, the artificial neural net should have an accuracy of approximately 98%.