Prerequisite
• TensorFlow iscompletely based on Python.
• Basic knowledge of Python.
• Good understanding of basic mathematics and artificial intelligence concept.
3.
What is TensorFlow?
•TensorFlow is a popular framework of machine learning and deep learning.
• It is a free and open-source library which is released on 9 November 2015 and developed
by Google Brain Team.
• It is entirely based on Python programming language and use for numerical computation
and data flow, which makes machine learning faster and easier.
4.
What is TensorFlow?
•TensorFlow can train and run the deep neural networks for image recognition, handwritten
digit classification, recurrent neural network, word embedding, natural language
processing, video detection, and many more.
• TensorFlow is run on multiple CPUs or GPUs and also mobile operating systems.
5.
Tensor and Flow
Tensoris a multidimensional array.
Flow is used to define the flow of data in operation.
6.
History of TensorFlow
•Deep learning started to exceed all other machine learning algorithms when giving extensive
data. Google has seen it could use these deep neural networks to upgrade its services.
• Google search engine
• Gmail
• Photo
• They build a framework called TensorFlow to permit researchers and developers to work
together in an AI model.
• It is an open- source platform under Apache Open Source License.
• Use it, modify it, and reorganize the revised version for free without paying anything to
Google.
7.
Components of TensorFlow
•The name TensorFlow is derived from its core framework, "Tensor."
• A tensor is a vector or a matrix of n-dimensional that represents all type of data.
• All values in a tensor hold similar data type with a known shape. The shape of the data is the
dimension of the matrix or an array.
• A tensor can be generated from the input data or the result of a computation.
• In TensorFlow, all operations are conducted inside a graph.
• The group is a set of calculation that takes place successively.
8.
Graphs
• TensorFlow makesuse of a graph framework.
• The chart gathers and describes all the
computations done during the training.
9.
Advantages
• It wasfixed to run on multiple CPUs or GPUs and mobile operating systems.
• The portability of the graph allows to conserve the computations for current or later use.
• The graph can be saved because it can be executed in the future.
• All the computation in the graph is done by connecting tensors together.
10.
TensorFlow Computational Graphsand Sessions
• Consider the following expression a= (b+c)*(c+2)
• Break the functions into components given below:
d=b+c
e=c+2
a=d*e
• A session can execute the operation from the graph.
• To feed the graph with the value of a tensor, first need to open a session.
• Inside a session, run an operator to create an output.
11.
Why is TensorFlowpopular?
• TensorFlow is the better library for all because it is accessible to everyone.
• TensorFlow library integrates different API to create a scale deep learning architecture like CNN
(Convolutional Neural Network) or RNN (Recurrent Neural Network).
• TensorFlow is based on graph computation.
• It can allow the developer to create the construction of the neural network with Tensorboard.
• This tool helps debug the program.
• It runs on CPU (Central Processing Unit) and GPU (Graphical Processing Unit).
Use Cases/Applications of
TensorFlow
•TensorFlow provides amazing
functionalities and services when
compared to other popular deep
learning frameworks.
• TensorFlow is used to create a large-
scale neural network with many
layers.
• It is mainly used for deep learning or
machine learning problems such
as Classification, Perception, Underst
anding, Discovering Prediction,
14.
Applications : Voice/SoundRecognition
• The neural networks have proper input data feed.
• Neural networks are capable of understanding audio signals.
• Voice recognition is used in the Internet of Things, automotive, security, and UX/UI.
• Flaw Detection (engine noise) is mostly used in automotive and Aviation.
• Voice search is mostly used in customer relationship management (CRM)
15.
Applications : ImageRecognition
• Image recognition is the first application that made deep learning and machine learning popular.
• Telecom, Social Media, and handset manufacturers mostly use image recognition.
• It is also used for face recognition, image search, motion detection, machine vision, and photo
clustering.
• Image recognition is used to recognize and identify people and objects in from of images. Image
recognition is used to understand the context and content of any image.
• For object recognition, TensorFlow helps to classify and identify arbitrary objects within larger
images.
• This is also used in engineering application to identify shape for modeling purpose
(3d reconstruction from 2d image) and by Facebook for photo tagging.
16.
Applications: Time Series
•Deep learning is using Time Series algorithms for examining the time series data to extract
meaningful statistics.
• For example, it has used the time series to predict the stock market.
• A recommendation is the most common use case for Time Series.
• Amazon, Google, Facebook, and Netflix are using deep learning for the suggestion.
• So, the deep learning algorithm is used to analyze customer activity and compare it to millions
of other users to determine what the customer may like to purchase or watch.
• For example, it can be used to recommend us TV shows or movies that people like based on
TV shows or movies we already watched.
17.
Video Detection
• Thedeep learning algorithm is used for video detection.
• It is used for motion detection, real-time threat detection in gaming, security, airports, and
UI/UX field.
• For example, NASA is developing a deep learning network for object clustering of asteroids
and orbit classification.
• So, it can classify and predict NEOs (Near Earth Objects).
18.
Text-Based Applications
• Text-basedapplication is also a popular deep learning algorithm.
• Sentimental analysis, social media, threat detection, and fraud detection, are the example of
Text-based applications.
• For example, Google Translate supports over 100 languages.
• Some companies who are currently using TensorFlow are Google, eBay, Intel, DropBox, Deep
Mind, Airbus, CEVA, Snapchat, SAP, Uber, Twitter, Coca-Cola, and IBM.
19.
Features of TensorFlow
•TensorFlow has an interactive multiplatform programming interface which is scalable and
reliable compared to other deep learning libraries which are available.
20.
Responsive Construct
• Visualizeeach part of the graph, which is not an option while using Numpy or SciKit.
• To develop a deep learning application, firstly, there are two or three components that are
required to create a deep learning application and need a programming language.
21.
Flexible
• It isone of the essential TensorFlow Features according to its operability.
• It has modularity and parts of it which we want to make standalone.
• Easily Trainable.
• It is easily trainable on CPU and for GPU in distributed computing.
22.
Parallel Neural NetworkTraining
• TensorFlow offers to the pipeline in the sense that we can train multiple neural networks and
various GPUs, which makes the models very efficient on large-scale systems.
23.
Large Community
• Googlehas developed it, and there already is a large team of software engineers who work
on stability improvements continuously.
24.
Open Source
• Thebest thing about the machine learning library is that it is open source so anyone can use it as much as they
have internet connectivity.
• People can manipulate the library and come up with a fantastic variety of useful products.
• And it has become another DIY community which has a massive forum for people getting started with it and
those who find it hard to use it.
25.
Feature Columns
• TensorFlowhas feature columns which could be thought of as intermediates between raw
data and estimators; accordingly, bridging input data with our model.
• The feature below describes how the feature column is implemented.
26.
Layered Components
• TensorFlowproduces layered operations of weight and biases from the function such as
tf.contrib.layers and also provides batch normalization, convolution layer, and dropout layer.
• tf.contrib.layers.optimizers have optimizers such as Adagrad,SGD which are often used to
solve optimization problems for numerical analysis.
Visualizer (With TensorBoard)
• Inspect a different representation of a model and make the changed necessary while debugging it with the
help of TensorBoard.
Advantage and Disadvantageof TensorFlow
• TensorFlow is an open-source machine learning concept which is designed and developed by
Google. It offers a very high level and abstract approach to organizing low-level numerical
programming. And supporting libraries that can allow our software to run without changes
on regular CPU.
• It supported platforms include Linux, macOS, Windows, and Android.
• TensorFlow models can also be run without a traditional computer platform in the Google
Cloud Machine Learning Engine.
32.
Advantages
• Graphs
• TensorFlowhas better computational graph visualizations. Which are inherent when
compared to other libraries like Torch and Theano.
33.
• Library management:
•Google backs it. And has the advantages of seamless performance, quick updates, and frequent new releases with
new features.
• Debugging:
• It helps us execute subpart of a graph which gives it an upper hand as we can introduce and retrieve discrete data
• Scalability:
• The libraries are deployed on a hardware machine, which is a cellular device to the computer with a complex
setup.
• It has a unique approach that allows monitoring the training progress of our models and tracking several metrics.
• TensorFlow has excellent community support.
• Its performance is high and matching the best in the industry.
34.
Tensor Flow basics
•TensorFlow is a machine learning framework and developed by Google Brain Team.
• It is derived from its core framework: Tensor.
• In TensorFlow, all the computations involve tensors.
• A tensor is a vector or a matrix of n-dimensions which represents the types of data.
• All the values in a TensorFlow identify data type with a known shape.
• The shape of the data is the dimension of the matrix or array.
35.
Representation of aTensor
• In TensorFlow, a tensor is the collection of feature vector (Like, array) of n-dimension.
• For instance, if we have any 2x3 matrix with values 1 to 6, we write:
• TensorFlow represents this matrix as:
[[1, 3, 5],
[2, 4, 6]]
Types of Tensor
•All computations pass through one or more Tensors in TensorFlow.
• A tensor is an object which has three properties which are as follows:
• A unique label (name)
• A dimension (shape)
• A data type (dtype)
38.
Operations
• Each operationwe will TensorFlow involves the manipulation of a tensor.
• There are four main tensors we can create:
• tf.Variable
• tf.constant
• tf.placeholder
• tf.SparseTensor
39.
Scalar, Vector, Matrix,Tensor
• Tensors can be represented as multi-dimensional arrays.
• The number of dimensions a tensor spans is known as the tensor's rank.
• Tensors with ranks 0, 1, and 2 are used often and have their own names, which are scalars,
vectors, and matrices, respectively, although the term tensors can be used to describe each of
them.
40.
Scalar, Vector, Matrix,Tensor
Scalar:
• A scalar consists of a single number, making it a zero-dimensional array.
• It is an example of zero-order tensors.
• Scalars do not have any axes. For instance, the width of an object is a scalar.
Vector:
• Vectors are one-dimensional arrays and are an example of first-order tensors. They
can be considered lists of values.
• Vectors have one axis.
• The size of a given object denoted by the width, height, and depth is an example of a
vector field.
41.
Tensor
Matrix:
• Matrices aretwo-dimensional arrays with two axes.
• They are an example of second-order tensors.
• Matrices might be used to store the size of several objects.
• Each dimension of the matrix comprises the size of each object (width, height, depth)
and the other matrix dimension is used to differentiate between objects.
Tensor
• The general entities that encapsulate scalars, vectors, and matrices, although the name
is generally reserved for tensors of rank 3 or more.
• A tensor can be used to store the size of many objects and their locations over time.
• The first dimension of the matrix comprises the size of each object (width, height,
depth), the second dimension is used to differentiate between the objects, and the third
dimension describes the location of these objects over time.
42.
TensorFlow works in3 main components
Components Description
Graph The graph is essential in TensorFlow. All the mathematical operations (ops)
are performed inside the graph. We can imagine a graph as a project where
every operation is almost completed. The nodes represent these ops, and
they can delete or create new tensors.
Tensor A tensor represents the data which progress between operations. We saw
previously how to initialize the tensor. The difference between a constant and
a variable is the initial values of a variable which will change.
Session A session will execute the operation to the graph. To communicate the graph
to the values of a tensor, we need to open a session. Inside a session, we
must run an operator to create an output.
43.
Session
• Graphs andsessions are independent.
• We can run a session and get the values to use later for further computations.
• In the example below, we will:
• Create two tensors
• Create an operation
• Open a session
• Print the result
44.
Session
create two tensorsx and y ## Create run and evaluate a session
X= tf.constant([2])
X= tf.constant([2])
create the operator by multiplying
x and y
## Create operator
multiply = tf.multiply(x,y)
open a session. ## Create a session to run the given code
Sess= tf.Session()
result_1=sess.run(multiply)
print(result_1)
sess.close()
45.
Graph
• The graphshows a node and edge.
• The node is the representation of operation, i.e., the unit of computation.
• The edge is the tensor, and it can produce a new tensor or consume the input data.
• It depends on the dependencies between individual operations.
• Tensor Flow depends on a brilliant approach to render the operation.
• All computations are represented with a dataflow schema.
• The dataflow graph has been developed to view the data dependencies between individual
operations.
• Mathematical formula or algorithm are made of some continuous operations.
• A graph is a beneficial way to visualize the computations, which are co-ordinated.
46.
Code
x = tf.get_variable("x",dtype=tf.int32, initializer=tf.constant([5]))
z = tf.get_variable("z", dtype=tf.int32, initializer=tf.constant([6]))
c = tf.constant([5], name ="constant")square = tf.constant([2], name ="square")
f = tf.multiply(x, y) + tf.pow(x, square) + y + c
init = tf.global_variables_initializer()
with tf.Session() as sess:init.run() #Initialization of x and y
function_result = f.eval()
print (function_result)
[66]
SAMPLE DATASET
• CIFAR-10(CanadianInstitute For Advanced Research) DATASET:
• Consists of total 60,000 Colored images
• Size of 32× 32 images
• Total of 10 classes (6000 images in each class)
• The Dataset are divided into
• Training dataset - 50,000 images
• Testing dataset -10,000 images
49.
Tools for implementation
•Tensorflow
• Keras
• Datasets
• Layers
• Conv2d, maxpooling2d, flatten, dense
• Matplotlib
50.
Loading the dataset…
Generallythe pixel values are between 0 and 255. But CNN process inputs
using small weights. Hence we normalize the pixel values so that the pixel
value is between 0 and 1.
CNN Model
• TheCNN has
• Two convolutional layers followed by two maxpooling layers
• Two dense layers
53.
Calculation of OutputShape and Parameters in CONV2D
Input Shape – 32×32×3 (Image size and channel)
n=32, f= 3
Output shape = (n-f+1) ×(n-f+1)
= (32-3+1) ×(32-3+1)
= 30× 30 × 32 , (where 32 is the filter in the current conv2D, so as 32
featuremaps)
Parameters in the CONV2D(filter shape =3*3, stride=1) layer is:
((shape of width of filter*shape of height filter*number of filters in the previous
layer+1)*number of filters)
= (((3*3*3)+1)*32)
=896
54.
Parameters in Denselayer
Parameters in the dense
((current layer c*previous layer p)+1*c)
= (64*2304)+1 *64)
=147520
55.
Hyperparameters
• Epochs –10
• Optimizer – Adam
• Learning rate - .001
• Loss Function – Sparse Categorical Crossentropy
• Activation Function in Convolution Layer – ReLU
• Activation in first dense layer - ReLU
• Activation in output layer - Softmax
The only difference between sparse categorical cross entropy and categorical cross entropy is the
format of true labels. When we have a single-label, multi-class classification problem, the labels are
mutually exclusive for each data, meaning each data entry can only belong to one class. Then we can
represent y_true using one-hot embeddings.
#3 TensorFlow – Overview
Popular framework for machine learning and deep learning.
Free and open-source library.
Released on 9 November 2015 by the Google Brain Team.
Based on Python for numerical computation and data flow.
Helps make machine learning faster and easier.
#4 TensorFlow – Capabilities
Can train and run deep neural networks for:
Image recognition
Handwritten digit classification
Recurrent Neural Networks (RNNs)
Word embedding
Natural Language Processing (NLP)
Video detection
And more applications.
Works on multiple CPUs, GPUs, and mobile operating systems.
#5 Tensor and Flow
Tensor: A multidimensional array used to store data.
Flow: Describes the flow of data through operations in a computational graph.
Example:
Tensor stores numbers in a matrix form.
Flow defines how these numbers move through operations like addition and multiplication.
#6 Background of TensorFlow
Deep learning began outperforming other machine learning algorithms when provided with large amounts of data.
Google recognized its potential and applied deep neural networks to improve services like:
Google Search Engine
Gmail
Google Photos
Why TensorFlow Was Created
Developed to help researchers and developers collaborate on AI models.
Open-source platform under the Apache Open Source License.
Free to use, modify, and redistribute without paying Google.
#7 TensorFlow – Tensor Basics
Name comes from its core concept: Tensor.
A tensor is a vector or matrix of n-dimensions that can represent any type of data.
All tensor values have:
The same data type
A known shape (dimensions of the matrix or array).
Tensors can be generated from input data or as a result of computation.
In TensorFlow, all operations happen inside a graph.
A graph is a group of calculations executed in sequence.
#8 Graphs in TensorFlow
TensorFlow uses a graph framework.
A graph collects and describes all computations performed during training.
This structure helps organize and execute operations efficiently.
#9 Graph Portability in TensorFlow
Can run on multiple CPUs, GPUs, and mobile operating systems.
Graphs are portable, so computations can be saved for current or future use.
Saved graphs can be executed later.
All computations in a graph are performed by connecting tensors together.
#10 Key Points:
Graphs represent computations as connected operations and variables.
A session executes operations from the graph.
To run a graph:
Open a session.
Feed the graph with tensor values.
Run an operator to produce the output.
#11 TensorFlow – Features and Benefits
Accessible to everyone; widely used in machine learning and deep learning.
Integrates various APIs to build scalable deep learning models, including:
CNN (Convolutional Neural Network)
RNN (Recurrent Neural Network)
Based on graph computation.
Allows developers to design and visualize neural networks using TensorBoard.
Helps with debugging programs.
Can run on both CPU (Central Processing Unit) and GPU (Graphical Processing Unit).
#13 TensorFlow – Functionalities and Uses
Offers advanced functionalities and services compared to other deep learning frameworks.
Can build large-scale neural networks with many layers.
Used for deep learning and machine learning tasks such as:
Classification
Perception
Understanding
Discovery & Prediction
Creation
#14 Neural Network Applications
Require proper input data for accurate results.
Can understand audio signals.
Voice recognition is used in:
Internet of Things (IoT)
Automotive
Security
UX/UI design
Flaw detection (e.g., engine noise) is used in:
Automotive industry
Aviation
Voice search is widely used in Customer Relationship Management (CRM).
#15 Image Recognition – Applications
First application that made deep learning and machine learning popular.
Widely used in telecom, social media, and handset manufacturing.
Applications include:
Face recognition
Image search
Motion detection
Machine vision
Photo clustering
Recognizes and identifies people and objects in images.
Understands the context and content of an image.
TensorFlow supports object recognition to classify and identify arbitrary objects within larger images.
Used in engineering for shape identification and 3D reconstruction from 2D images.
Used by Facebook for photo tagging.