All you need to Know and Learn about Tensorflow

Tensorflow is a library which can be used for numerical computing and other architectures released by Google who has developed the library. Since it is an open source library, so other users are permitted to make changes in it. The various libraries included in it are Keras and TfLearn.

The users can develop deep learning and machine learning models through these libraries. The users can learn about CPU, GPU, mobile devices, and distributed machines. The library supports Python and C++ languages also. Google is using the Tensorflow to search various things like search ranking, speech recognition, machine translation for Google Translate, etc.

Google has a large amount of data and learning algorithm, which will help the company to develop artificial intelligence. The company’s engineers are using the library to develop artificial intelligence by introducing various features like speech recognition and searching. The feature is freely available and users can use it easily.

People who want to make a career in machine learning can learn Tensorflow as it comes with many classes and libraries, which help the user to use the machine learning easily.

The library has become the leader among the programmers and developers can develop various things with machine learning.

#Method of installing Tensorflow

The command that is used to install the library is pip install — upgrade tensorflow. The CPU version is also available but for small programming, it is not beneficial. One thing to remember while installing TensorFlow on Windows is that it supports only 64-bit system.  The Python version that the library supports is Python 3.5 as it has many libraries along with Jupyter notebook.

#What are the prerequisites of learning Tensorflow

The person who wants to work in TensorFlow should have a basic knowledge of Python. Along with it, the developer should also know about machine learning workflow, which includes feature preprocessing, model training, loss functions, etc.

#Machine Learning with Tensorflow

Machine learning has gained a good rate and machine learning frameworks are being used to enhance flexibility and simplicity. Users belong to different classes and TensorFlow helps them to develop custom models. There are other users who use common models to include the results in their infrastructure.

There are multiple APIs which then users can use like Keras and tf.estimator. For common users, prebuilt estimators are provided through which common machine learning models can be implemented.

The architecture of the TensorFlow can be seen in the following image.

Image Source: Architecture


#Usage of Tensorflow to create computational graphs

The central units of TensorFlow are Tensors, which can be used as multi-dimensional arrays.

Here is an example of using the tensor.

a = 7 It is a zero-dimensional tensor also called scalar

a = [8,10] It is a one dimensional tensor also called vector

a = [[4,9],[2,2]] It is a two-dimensional tensor also called as matrix

These tensors can be used in tf.operation to perform various types of computations. Tensors are used as inputs in the operation and computations are performed. The result displayed is in the form of zero or more tensors. We can take an example of tf.add in which two values are passed. The result will be the sum of those values.

Here is the computational graph, which shows the connection between tensors and operations.

#Running a session with the use of constants

Here tf.constant will be used to use two values and tf.add will add those values.

import tensorflow as vartf


a = vartf.constant(9,name = “num1”)

b = vartf.constant(6, name = “num2”)

result = vartf.add(num1,num2,name=’add_num1_num2′)


# Output

<vartf.Tensor ‘add_num1_num2:0’ shape=() dtype=int32>

The output is not as we want to have that is the sum of the values of num1 and num2. In order to get the result we will use tf.session class. Here is the code.

sess = vartf.Session()

# Output


#Using Variables and Placeholders

Variables are required to provide data type and initial value. The values of constants cannot be changed but we can use variables for the purpose. The variables can be defined by using tf.variable.

Placeholders can be used to feed the graphs so data can be input from training sets to the model. Placeholders work as tensor objects and their values are not specified. Placeholders can be defined by tf.placeholder.

The values of a place holder are fed when the program is run. The feed_dict argument of method can be used to feed the placeholder with values. The data type and shape of the placeholder should also be defined. If the shape of the placeholder is defined as None, then it can hold any value.

The feed_dict argument is used to overwrite the existing values of the tensors. Here is the code of defining variables and placeholders.

c = vartf.Variable(3,dtype=tf.float32)

d = vartf.placeholder(dtype = tf.float32,shape=None)

The variables can be initialized by using a special operation called tf.global_variables_initializer.

Here is the code of initializing variables and placeholders.

print(,feed_dict = {c:28}))

print(,feed_dict = {d:[3,4,3,5]}))



[ 3.  4.  3.  5.]

#What is Tensorboard?

It is a visual tool in which tensorflow is installed. Tensorboard is used to visualize machine learning model and debug them. The tensorboard can also, be used  to track loss metrics along with changing the training steps.

Tensorboard can be used by saving various types of graphs by writing summaries. These summaries can be written with the help of summary writers. Tensorboard uses this information for visualization. The directory name of the log files of the graph should be mentioned and the summary writer object is used to save the computational graph. The default computational graph is stored in sess.graph object. The writer object uses the logdir parameter to write the graph in a directory.

writer = vartf.summary.FileWriter(logdir= “../my_graph”,graph = sess.graph)


The following command can be used to run the tensorboard in Windows system.

tensorboard –logdir=path/to/log-directory

For the Mac system, use the following code.


The default port on which the tensorboard runs is 6006 so in the browser the user has to type


and the graph will be available on the browser.

#Tensorflow Estimators

Estimators are an API, which can be used to work with pre-implemented models. And users can also create new models with them. Creation of computational graphs, logging files and saving checkpoint can be done by using estimators.

There are input functions, which can be used to pass data, and feature columns are used to interpret the input data. The base class used for using an estimator is Estimators.The subclasses available for estimators are canned estimators and pre-implemented models.

Estimators can be used for creation of computational graphs, initialization of variables, files logging for Tensorboard and many other things. There are pre-developed models in the class. Input functions should be built by the developers to send data to the estimator.

Here are the steps for the workflow.

Libraries and datasets should be loaded.

  1. Start the data preprocessing.
  2. The feature columns should be defined.
  3. The input function should be built.
  4. The next thing to perform is model instantiation, training, and evaluation.
  5. Prediction generation.
  6. Using Tensorboard to view the model and the loss metrics.

The workflow can be seen in the image below.


Image source: Workflow

#Wrapping Up

Tensorflow is a symbolic math library which can be used for machine learning applications. The product was developed by Google and the company uses it to for research and production.

Hi, I'm Raj Hirvate and I am a Tech Blogger from India. I like to post about technology and product reviews to the readers of my blog. Apart from blogging i'm a big Anime fan I Love Watching Naruto, One piece and Death Note.