## TensorFlow – The Machine Learning Library

Machine learning is eating the software industry and Deep learning is eating machine learning. Google developed this open source software library for the implementation of Machine Learning and Neural Network research. Big IT firms like Facebook, Microsoft, and Google are already implementing and targeting to excel in Deep Learning.

### Watch this Tensorflow Tutorial for Beginners Video

In our previous tutorial we have discussed how Deep learning is reshaping the world of technology. Here we are going to introduce TensorFlow and its installation steps, Let’s get started.

## What is TensorFlow?

TensorFlow is a Deep Learning toolkit with low-level functionality yet high-level operations, designed for Dataflow programming models. This tool is not only less time consuming both portable and scalable on a lot of platforms, which means the code can run on CPU, GPU (Graphical Processing Units), mobile devices and TPU (Tensor Processing Units, which are Google’s dedicated TensorFlow processors). This effective software framework uses Python as main interface. It is also backed up by a huge community of developers, also because of the early adoption by academic and industrial research teams across the world makes TensorFlow very popular for Deep Learning. Above all, TensorFlow has the power of Google behind it.
TensorFlow and its functions revolve primarily around Tensor, which means multidimensional array and Flow, which refers to graphs.The tensor data flows through the graph while being operated on at the nodes.
TensorFlow describes multi-dimensional numerical array as graphs without using complex mathematical interpretations, which makes model analysis very easy. ### What is Tensor? An n-dimensional array, Scalar, Vector, Matrix these are all Tensors.  Tensors are considered as data structure in TensorFlow.
Rank:
Rank of 1D array =0
Rank of 2D array =1
Rank of 3D array =2

For the best of career growth, check out Intellipaat’s Machine Learning Course and get certified.

### What is “Flow Graph”?

A Flow Graph is a directed graph with, where nodes represent mathematical operations and edges represent flow of data as tensors, where we have learnt how data can be multi-dimensional.
We can have a better idea about tensors and flow graphs from the image shown below. ### TensorFlow Graph for Numeric operations:

Let us take an example, here we are representing flow graph for the numerical calculation ofd=(ab+c)2 So, in a TensorFlow data basically flows in the form of tensors.

Go through this Artificial Intelligence Interview Questions And Answers to excel in your Artificial Intelligence Interview.

## Basic TensorFlow Code Structure

• Build a computational graph or FlowGraph and
• Use a session to execute operations in the graph

## Why TensorFlow?

Now that we have learnt that TensorFlow is, let us discuss why do we choose TensorFlow over any other tool available. Deep learning uses algorithms known as Neural Networks, which have been designed to imitate the biological neurons. Using these Artificial Neural Networks, the computer is able to learn from data, represent it and identify solutions based on the data fed into the system. And TensorFlow lets us build large-scale neural networks with multiple hidden layers.

### Applications of TensorFlow:

• Classifying objects based on attributes
• Having a sense of perception
• Learning and understanding from data
• Discovering new trends, patterns, relationships
• Predicting the outcome of a certain process
• Creating new approaches and applications
• TensorFlow is also used in the telecom domain, social media and handset manufacturers. It is highly useful in detecting motion, searching images, computer vision, photo grouping and other applications. It can identify people and objects to understand the content and context.
• One of the main benefits of TensorFlow is that it is well known for sound-based applications. The neural networks are able to make sense of audio signal language which is used for the purpose of voice recognition. You can identify sound snippets in big audio files and transcribe the audio with the speech-to-text applications.
• Text based application such as sentimental analysis, threat detection and fraud detection application are widely created by TensorFlow.

If you have any doubts or queries related to Data Science, do post on Machine Learning Community.

### Features of TensorFlow

• One of the features of TensorFlow is, we can easily visualize each and every part of the graph whereas in Numpy or Scikit we can’t.
• TensorFlow can separate the functionality of a program into independent and interchangeable modules.
• It is easily trainable on CPU as well as GPU for distributed computing.
• TensorFlow can train multiple neural networks and multiple GPU’s which makes modules very efficient on large scale system.
• TensorFlow affords you the benefit of using it if you have an internet connection thanks to it being completely open source
• It lets you inspect a completely different representation of the model and you can make the changes to it when debugging by deploying the TensorBoard.

Check out our comprehensive blog on Tensorflow Interview Questions that will help you to crack your next job interview.

### Pros and Cons of TensorFlow

Pros

• TensorFlow has better computational graph visualization.
• TensorFlow is highly parallel and designed to use various backend software.
• TensorFlow affords you the benefit of using it if you have an internet connection thanks to it being completely open source.
• TensorFlow neural networks also work on video data. This is mainly used in Motion Detection, Real-Time Thread Detection in Gaming, Security, Airports and UX/UI fields.
• You can analyze time series using the TensorFlow time series algorithms to derive valuable statistics from it.

Cons

• TensorFlow is low level in steep learning curve.
• TensorFlow has low Computational speed. ## How TensorFlow works

TensorFlow is designed to support experimentation with new machine learning models and system-level optimization.

### TensorFlow architecture: TensorFlow architecture has three primary steps.

Preprocessing the data:
• Tensor flow can execute operations on various hardware platforms, CPU,GPU,IOS, Android etc. Wondering how? It achieves that by TensorFlow    Distributed Execution Engine.
• We write the codes in Python, C++ etc.
• TensorFlow Distributed Execution Engine takes the codes, and converts that into hardware instruction sets for CPU, GPU, Android etc.
Build the model:
• In layers we have machine learning components for building models, which are also reusable.
Train and estimate the model
• Using Estimator and Keras model we Train and Evaluate the models
• Canned Estimator allows TensorFlow to support Linear Regression, Logistic Regression and Neural Network as well.

Interested in learning Machine Learning? Click here to learn more in this Machine Learning Training in New York!

• Constants
• Variables
• Placeholders
• Session

### Constants

Constant are created by tf.constatnt() function. Vale, dtype, shape, name, verify_shape are the arguments that can be passed to a constant.

```import TensorFlow as tf
hello = tf.constant(“Hello World")```

### Variables

TensorFlow is a way of representing computation without actually performing it until asked. In this sense, it is a form of lazy computing, and it allows for some great improvements to the running of code.

```Import TensorFlow as tf
x = tf.constant(35, name=’x’)
y = tf.Variable(x+5, name=’y’)
model=tf.global_variables_initializer()
withtf.Session()assession:
session.run(model)
print(session.run(y))```

global_vaiables_initializer is used for initializing the variables globally i.e. the variables can be used in any part of the code.

### Placeholders

Placeholders allow you to assign data after creating your operation and adding computation graph. In TensorFlow terminology we can feed data into the graph through these placeholders.

```importTensorFlowastf
x=tf.placeholder("float",None)
y=x*2
withtf.Session()assession:
result=session.run(y,feed_dict={x:[1,2,3]})
print(result)```

### Session

Sessions are used to evaluate tensors and it runs TensorFlow operations. It encapsulated the state of a TensorFlow runtime. Some example of TensorFlow session are

```hello = tf.constant(“Hello World”)
ses = tf.Session()
print(ses.run(hello))```

When you ask for the Session.run output of a node then TensorFlow go through the graph and runs through all the node that gives the input to the requested output node. So that way  you will be able to print the expected value which is Hello World. ## TensorFlow installation steps in Windows

The first thing to notice while installing TensorFlow is to choose either CPU or GPU supported version. For beginners I would recommend you use CPU supported version if you need to train simple machine learning models.
GPU supported TensorFlow requires you to install a number of libraries and drivers. It supports NVIDIA GPU card, with support for CUDA Compute 3.5 or higher.

Become Master of Machine Learning by going through this online Machine Learning course in Sydney.

### TensorFlow installation through pip (Windows):

• To install TensorFlow through pip, you need python to be installed in your computer. Download latest version of Python(website).
• To check if python is installed properly, please open command promptand type python. • To check the version of pip running in your system, open command prompt and type pip –version as mentioned below. • After you ensure that pip and python are installed successfully, it’s time to install TensorFlow
• To install TensorFlow run your command prompt as administrator, right click on the command prompt icon and click on “Run as administrator”.
• After just follow the code below to install TensorFlow. • The command will take some time to execute, so remain patient. With pip, you can install TensorFlow with GPU support as follows: ### TensorFlow through Virtual Environment

I would recommend you install TensorFlow through virtual environment because it is very useful when you change your environment or platform.

• Install virtualenv through pip. • Create a virtualenv and activate your virtual environment by following the given scripts below. • Once you activate your virtual environment and then install TensorFlow inside that virtual environment. ## Conclusion

As we discussed TensorFlow is a very powerful Machine Learning frameworks and has grown in popularity and is now being used by developers for solving problems using deep learning methods for image recognition, video detection, text processing like sentiment analysis, etc. It takes some time to get used to TensorFlow but once you’re clear with the concepts you can master TensorFlow and play around it.
In the next part, which is based on Artificial Intelligence Course, we will build our very first Deep Neural Network model and how tensor flow helps us implement Deep Learning.

To get a more elaborate idea of the algorithms of deep learning refers to our Artificial Intelligence Online Course.

Course Schedule

Name Date
Data Science Course 2022-10-01 2022-10-02
(Sat-Sun) Weekend batch
View Details
Data Science Course 2022-10-08 2022-10-09
(Sat-Sun) Weekend batch
View Details
Data Science Course 2022-10-15 2022-10-16
(Sat-Sun) Weekend batch
View Details

Browse Categories