# What is TensorFlow, and how does it work?

Last Updated on August 8, 2021 by Editorial Team

**Author(s): Mohit Varikuti**

#### Deep Learning

**What is TensorFlow?**

TensorFlow is an open-source end-to-end framework for building Machine Learning apps. It’s a symbolic math toolkit that performs a variety of tasks including deep neural network training and inference using dataflow and differentiable programming. It enables programmers to construct machine learning applications by utilizing a variety of tools, frameworks, and community resources.

Google’s TensorFlow is now the most well-known deep learning package on the planet. Machine learning is used by Google in all of its products to enhance search, translation, picture captions, and recommendations.

For instance, Google users may benefit from AI-assisted search that is both faster and more refined. When a user puts a keyword into Google’s search field, the search engine makes a suggestion for the following word.

Google aims to employ machine learning to make the most of its huge datasets in order to provide the best possible experience for its consumers. Machine learning is used by three different organizations. Researchers, Programmers, and Data Scientists.

They may all cooperate and increase their efficiency by using the same toolbox.

Tensor Flow was developed to scale since Google has more than just data; they also have the world’s most powerful computer. TensorFlow is a machine learning and deep neural network research library created by the Google Brain Team.

It was designed to work on multiple CPUs or GPUs, as well as mobile operating systems in some circumstances, and it includes wrappers in Python, C++, and Java.

### TensorFlow’s History

When given a large quantity of data, deep learning began to surpass all other machine learning algorithms a few years ago. Google realized that deep neural networks may help it improve its services.

They created the Tensorflow framework to allow academics and developers to collaborate on AI models. It can be used by a large number of individuals after it has been created and scaled.

It was originally released in late 2015, with the first stable version following in 2017. It’s free and open-source, thanks to the Apache Open Source license. Without paying anything to Google, you may use it, alter it, and redistribute the updated version for a price.

### How does it work?

By accepting inputs as a multi-dimensional array called Tensor, TensorFlow allows you to create dataflow graphs and structures to specify how data travels through a graph. It lets you to create a flowchart of operations that may be done on these inputs, which travel in one direction and out the other.

### Tensorflow’s Structure

Preprocessing the data, building the model, and finally training and estimating the model are the three elements of the Tensorflow structure.

Tensorflow gets its name from the fact that it takes input in the form of a multi-dimensional array, commonly known as tensors. You can create a flowchart of the operations you’d want to run on that input. The input enters at one end, travels through this system of various processes, and emerges as output at the other.

The tensor goes in, runs through a set of operations, and then comes out the other side, which is why it’s called TensorFlow.

### What do you need to run Tensorflow?

TensorFlow hardware and software requirements may be divided into three categories.

The mode, (Type of AI), is trained during the development phase. The majority of training takes place on a computer or laptop.

Tensorflow may be used on a variety of platforms when the training phase is completed. It may be used on a Windows, macOS, or Linux desktop, in the cloud as a web service, and on mobile platforms such as iOS and Android.

You may train it on several computers and then run it on a separate machine once it’s been trained.

Both GPUs and CPUs may be utilized to train and run the model. GPUs were created with video games in mind. Stanford researchers discovered in late 2010 that GPUs are also very strong at matrix operations and algebra, making them highly quick for these types of tasks. A lot of matrix multiplication is used in deep learning. Because TensorFlow is developed in C++, it is extremely quick at performing matrix multiplication. TensorFlow, although being written in C++, can be accessed and controlled using various languages, most notably Python.

Finally, the TensorBoard is an important element of TensorFlow. TensorFlow may be monitored graphically and visually with the TensorBoard.

### What are Tensorflow Components?

**Tensor**

Tensorflow gets its name from its underlying framework, Tensor. Tensors are used in every computation of Tensorflow. A tensor is an n-dimensional vector or matrix that may represent any form of data. A tensor’s values all have the same data type with a known (or partially known) form. The dimensionality of the matrix or array determines the form of the data.

A tensor might come from either the input data or the output of a calculation. All operations in TensorFlow are carried out within a graph. The graph is a series of computations that happen in order. Each operation is referred to as an op node, and they are all linked together.

The graph depicts the operations and relationships that exist between the nodes. It does not, however, show the values. The tensor, or a means to supply the operation with data, is the edge of the nodes.

#### Graphs

A graph framework is used by TensorFlow. The graph collects and summarizes all of the training’s series calculations. The graph offers a number of benefits:

- It was designed to work on many CPUs or GPUs, as well as on mobile devices.
- The graph’s portability enables the computations to be saved for immediate or later usage. The graph can be saved and run at a later time.
- The graph’s calculations are all done by linking tensors together.
- There is a node and an edge in a tensor. The mathematical process is carried out by the node, which results in endpoint outputs. The node input/output connections are explained by the edges.

### Why do so many people like Tensorflow?

TensorFlow is the finest library of them all since it is designed to be user-friendly. The Tensorflow library includes a variety of APIs for creating large-scale deep learning architectures such as CNNs and RNNs. TensorFlow is a graph-based programming language that allows developers to view the neural network’s creation using Tensorboad. This software debugging tool is really useful. Finally, Tensorflow is designed to be used in large-scale deployments. It runs on both the CPU and the GPU.

In comparison to the other deep learning frameworks, Tensorflow also has the most popularity on GitHub.

### Different Algorithms you can use in Tensorflow

Below are the supported algorithms:

- Linear regression: tf.estimator.LinearRegressor
- Classification:tf.estimator.LinearClassifier
- Deep learning classification: tf.estimator.DNNClassifier
- Deep learning wipe and deep: tf.estimator.DNNLinearCombinedClassifier
- Booster tree regression: tf.estimator.BoostedTreesRegressor
- Boosted tree classification: tf.estimator.BoostedTreesClassifier

### Tensorflow Example

import tensorflow as tf

import numpy as np

Tensorflow is imported as tf in the first two lines of code. It is standard practice in Python to give a library a short name. The benefit is that we don’t have to type the library’s complete name every time we need to use it. For example, when we wish to utilize a TensorFlow function, we may import TensorFlow as tf and use tf.

Let’s practice Tensorflow’s basic process with some easy TensorFlow examples. Let’s build a computational network that multiplies two integers.

We’ll multiply V_1 and V_2 together in this case. To link the operations, Tensorflow will build a node. It’s called multiply in our case. Tensorflow computational engines will multiply V_1 and V_2 together after the graph has been established.

Finally, we’ll start a TensorFlow session that runs the computational graph using V_1 and V_2 values and prints the multiplication result.

Let’s get started by defining the V_1 and V_2 input nodes. When we construct a node in Tensorflow, we must first decide what type of node we want to make. The nodes V1 and V2 will serve as placeholders. Each time we perform a computation, the placeholder assigns a new value. As a TF dot placeholder node, we’ll make them.

#### Step 1: Establish the variable

V_1 = tf.placeholder(tf.float32, name='V_1')

V_2 = tf.placeholder(tf.float32, name='V_2')

When we construct a placeholder node, we must provide the data type. We’ll be putting numbers here, so we’ll choose tf.float32 as our data type. We’ll also need to name this node. When we examine at our model’s graphical representations, this name will appear. Let’s name this node V_1 by providing it a name argument with the value V_1, and then let’s do the same for V_2.

#### Step 2: Define the calculation

multiply = tf.multiply(V_1, V_2, name='x_multiply')

Now we can specify the node that does the multiplication. We can accomplish this in Tensorflow by adding a tf.multiply node.

The V_1 and V_2 nodes will be sent to the multiplication node. It instructs TensorFlow to connect those nodes in the computational graph, thus we’re asking it to multiply the values from x and y. Give the multiplication node the name x_multiply as well. It’s our basic computational graph’s whole definition.

#### Step 3: Execute the Operation

We must first construct a session in order to perform operations in the graph. It’s handled by tf.Session() in Tensorflow. By calling the session now that we have a session, we can ask it to do operations on our computational graph. We must use the run command to complete the computation.

When the addition operation is done, it will notice that it has to grab the values of the V_1 and V_2 nodes, therefore we must additionally feed-in V_1 and V_2 values. We may accomplish this by passing feed dict as a parameter. We give V_1the values 1, 2, 3, and V_2 the values 4, 5, 6.

For 1×4, 2×5, and 3×6, we should see 4, 10, and 18.

## Input:

V_1 = tf.placeholder(tf.float32, name = "V_1")

V_2 = tf.placeholder(tf.float32, name = "V_2")

multiply = tf.multiply(V_1, V_2, name = "x_multiply")

with tf.Session() as session:

vr = session.run(multiply, feed_dict={V_1:[1,2,3], V_2:[4,5,6]})

print(vr)

## Output:

[ 4. 10. 18.]

### How to load data into Tensorflow

Loading data is the initial stage in training a machine learning algorithm. There are two typical methods for loading data:

- Load data into memory: This is the most straightforward technique. All of your data is loaded into memory as a single array. You are able to write Python code. This code has nothing to do with Tensorflow.
- Data pipeline based on Tensorflow. Tensorflow has an API that makes it simple to import data, conduct operations, and feed the machine learning algorithm. This approach is very useful when dealing with big datasets. Image records, for example, are notoriously large and difficult to store in memory. The memory is managed by the data pipeline on its own.

So, what should you use?

**Load data in memory:**

You can use the first approach if your dataset isn’t very large, say less than 10 gigabytes. The information can be stored in the memory. To import CSV files, you may use Pandas, a well-known library.

**Load data with Tensorflow pipeline:**

If you have a huge dataset, the second technique is best. For example, if you have a 50-gigabyte dataset and your computer only has 16 gigabytes of RAM, the computer will crash.

You’ll need to create a Tensorflow pipeline in this case. The data will be loaded in batches, or tiny chunks, by the pipeline. Each batch will be added to the pipeline and made available for training. Building a pipeline is a fantastic option since it enables parallel processing. Tensorflow will use several CPUs to train the model. It promotes computing and allows for the development of strong neural networks.

In a word, if you have a tiny dataset, you can use the Pandas library to load it into memory.

If you have a huge dataset and wish to leverage many CPUs, the Tensorflow pipeline will be more convenient to work with.

### Conclusion

TensorFlow definition: In recent years, TensorFlow has become the most well-known deep learning library. Any deep learning structure, such as a CNN, RNN, or basic artificial neural network, may be built using TensorFlow.

Academics, startups, and major corporations are the most common users of TensorFlow. TensorFlow is used in virtually all Google products, including Gmail, Photos, and the Google Search Engine.

TensorFlow was created by the Google Brain team to bridge the gap between researchers and product developers. TensorFlow was released to the public in 2015, and it is fast gaining popularity. TensorFlow is currently the deep learning library with the most GitHub repositories.

What is TensorFlow, and how does it work? was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

Published via Towards AI