TensorFlow is an open source deep learning platform created by Google. Equipped with a Python API, it offers a multitude of tools to train and optimize artificial neural networks.
What is TensorFlow?
A star tool for data scientists, TensorFlow is an open source deep learning library. Developed by Google, it was released at the end of 2015 under the Apache 2.0 license. Coming from the DistBelief infrastructure created by Mountain View to train learning models on clusters of hundreds of servers, it is recognized for its performance.
TensorFlow supports the Python, Julia and R languages. Called TFRT, its training engine is built around a unified framework supporting both CPU and GPU computing servers and TPU architectures for TensorFlow Processing Unit. CPUs specifically designed by Google to train TensorFlow-based neural networks.
Why choose TensorFlow?
More popular than Pytorch, TensorFlow currently supplants its competitor in terms of available skills and associated tools. Among his most popular bricks are his famous Tensorboard. A graphic display console to monitor the training of the models with a view to optimizing the adjustment parameters. Among its main features are:
- Visualization of training indicators (loss, accuracy, etc.)
- Visualization of the neural network graph,
- Visualization of weighting and Tensor histories,
- Bias tracking,
- Visualization of vector representations of the network,
- C++ and Python APIs,
What is TensorFlow Keras?
TensorFlow 2.0 integrates Keras. Created by François Chollet, French engineer researcher in AI at Google, it is a high-level deep learning API. Deployed by Netflix, Uber, NASA, Yelp and of course Google, it allows you to create neural networks in a few lines of code before training and deploying them via TensorFlow.
How to install TensorFlow?
To install TensorFlow, you can go through the pip package manager. Developed for Ubuntu and Windows, the latest stable version of TensorFlow supports both CPU and GPU processors.
How to use TensorFlow?
TensorFlow offers a series of workflows for developing and training models using Python or JavaScript. For beginners, the open source project site advises starting using the Keras (Sequential) API. A programming interface that “allows you to create models by connecting different components”.
What is TensorFlow.js?
TensorFlow.js is the TensorFlow version for developing and training deep learning models using JavaScript.
What does TensorFlow Lite do?
TensorFlow Lite is an interpreter designed to compress neural networks designed using TensorFlow in order to deploy them on small devices: Android or iOS smartphone, connected object…
TensorFlow vs PyTorch: what’s the difference?
PyTorch is a deep learning library developed by Facebook. TensorFlow supplants PyTorch in terms of data and tools offered. Unlike PyTorch, TensorFlow is limited to a static modeling architecture. This implies freezing the graph of the model throughout the training phase.
How to use TensorFlow?
To get started using TensorFlow, we’ll first take a simple example of multiplying two integers.
We will multiply $X$ and $Y$ together. Tensorflow will create a node to connect the operation to these two numbers. When the graph is determined, the Tensorflow calculation engines will perform the multiplication.
To do this, we will start by creating two variables. In TensorFlow, they are called Placeholders or placeholders. Setting a node as a placeholder ensures that the node will receive a value later or during execution.
import numpy as np
import tensorflow as tf
X = tf.placeholder(tf.float32, name = "X")
Y = tf.placeholder(tf.float32, name = "Y")
Next, we can define the node that does the multiplication operation. We can do this using tf.multiply.
We will pass the nodes $X$ and $Y$ to the multiplication node. TensorFlow will connect these nodes in the compute graph, so we ask it to pull the values of $X$ and $Y$ and multiply them to find the result.
multiply = tf.multiply(X, Y, name = "multiply")
To perform operations in the graph, we need to create a session. In Tensorflow, this is done by tf.Session().
with tf.Session() as session:
result = session.run(multiply, feed_dict={X:[1,2,3], Y:[4,5,6]})
print(result)
Now that we have a session, we can request the session to perform the operations on our compute graph by calling session. To run the calculation, we need to use run.
[ 4. 10. 18.]
Classify Images with TensorFlow
To start using TensorFlow for Deep Learning tasks, we will do an example of classifying images of handwritten digits. To do this, we will use the well-known MNIST dataset.

We will also use TensorFlow’s Keras API to create a basic neural network.
We’ll start by importing TensorFlow.
import tensorflow as tf
We will then download the MNIST data using Keras’s load_data function. The data is divided into training and test data.
Each dataset is divided into images and labels. Each image is a 28 x 28 pixel array. The labels are numbers from 0 to 9 corresponding to the ten handwritten digits.
Data must be pre-processed before it can be used in the neural network. Pixel values should be normalized from 0 to 1.
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
We define the neural network model using the Sequential function. Our model includes three layers, one flatten layer and two dense layers. The first layer reshapes the tensor to make it one-dimensional equal to the number of elements contained in the tensor.
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10)
])
The model is compiled with the optimizer and the loss function.
model.compile(
optimizer=tf.keras.optimizers.Adam(0.001),
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=[tf.keras.metrics.SparseCategoricalAccuracy()],
)
The model is trained using the training data. The training is carried out over 10 epochs. The evaluate function allows you to evaluate the model being trained and display performance scores such as loss and accuracy.
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test, verbose=2)

We notice that our model reached >92% accuracy after only one epoch. After 5 epochs, the final score is 98.5%.
TensorFlow can be used for much more complex tasks, such as natural language processing, image segmentation and image generation.
Alternatives to TensorFlow
TensorFlow competes with a host of other machine learning frameworks. PyTorch, CNTK, and MXNet are three main tools that serve many of the same needs.
- PyTorch: PyTorch and TensorFlow are the two main deep learning frameworks. PyTorch is a fairly new, open-source, Python-based deep learning framework. It was developed by Facebook and was released in October 2016. TensorFlow is a more mature framework. It has been around longer and thus has more features. PyTorch is a new framework and is still under active development. It’s not as feature-rich as TensorFlow, but it’s easier to use and has a more intuitive API.
- CNTK: is an open-source toolkit for deep learning developed by Microsoft. It is based on the concept of directed acyclic graphs (DAGs) and is efficient for manipulating very large data sets. CNTK also supports a wide range of neural network architectures, including convolutional neural networks (CNNs), recurrent neural networks (RNNs), and short-term memory networks (LSTM). TensorFlow is a cross-platform deep learning library and easier to use than CNTK. CNTK is faster than TensorFlow.
- MXNet: MXNet is a Deel Learning framework that is developed and maintained by the Apache Software Foundation. It is an open source framework widely used to develop and train deep learning models. MXNet is a more flexible framework than TensorFlow. It allows developers to define custom layers and models. TensorFlow, on the other hand, is a more rigid framework.
MXNet is faster and scalable than TensorFlow. It can train models faster and can also handle large datasets. MXNet is also more portable than TensorFlow. It can be used on a variety of devices such as CPUs, GPUs, and FPGAs. TensorFlow, on the other hand, is not as portable. It can only be used on CPUs and GPUs.
TensorFlow is a widely preferred framework for machine learning and deep learning applications. It is widely used by many large companies around the world. Therefore, learning TensorFlow can help you demonstrate your skills in this area or gain additional knowledge.
ABOUT LONDON DATA CONSULTING (LDC)
We, at London Data Consulting (LDC), provide all sorts of Data Solutions. This includes Data Science (AI/ML/NLP), Data Engineer, Data Architecture, Data Analysis, CRM & Leads Generation, Business Intelligence and Cloud solutions (AWS/GCP/Azure).
For more information about our range of services, please visit: https://london-data-consulting.com/services
Interested in working for London Data Consulting, please visit our careers page on https://london-data-consulting.com/careers