Introduction To DL With TensorFlow
Introduction To DL With TensorFlow
with TensorFlow
Jian Tao
[email protected]
Spring 2020 HPRC Short Course
03/27/2020
Schedule
● Part I. Deep Learning (70 mins)
Data
Computer Prediction
Scientific
Model
Model
Computer Prediction
Data
Types of ML Algorithms
● Supervised Learning
○ trained with labeled data; Machine Learning
including regression and
classification problems
● Unsupervised Learning Supervised Learning
○ trained with unlabeled data;
clustering and association rule
learning problems. Unsupervised Learning
● Reinforcement Learning
○ no training data; stochastic
Markov decision process; robotics Reinforcement Learning
and self-driving cars.
Supervised Learning
When both input variables - X and output variables - Y are known, one can
approximate the mapping function from X to Y.
Data Class 1
Class 2
Class 3
Reinforcement Learning
When the input variables are only available via interacting with the
environment, reinforcement learning can be used to train an "agent".
DL model
4-Element Vector
X Y
1
2 A
3 C M
4 T F
5 G
6
Output/Prediction
Target Output
x x ….. x
1 2 n
Error: - =5
18
Learning Principle
Output/Prediction
Target Output
x x ….. x
1 2 n
Error: - = 15
19
Learning Principle
Output/Prediction
Target Output
x x ….. x
1 2 n
Error: - = 2.5
20
Supervised Deep Learning with Neural Networks
Input Hidden Layers Output
From one layer to the next
X1
W1
X2 W2
f is the activation function,
Wi is the weight, and bi is Y3
the bias.
X3 W3
Training - Minimizing the Loss
The loss function with regard to weights Input Output
and biases can be defined as
W1, b1 X1
Y2
Image Credit: Deep Learning Methods for Vision | CVPR 2012 Tutorial
Activation Functions
Image Credit: Deep Learning Methods for Vision | CVPR 2012 Tutorial
Max Pooling
Image Credit: Deep Learning Methods for Vision | CVPR 2012 Tutorial
CNN Implementation - Drop Out
Dropout is used to prevent overfitting. A neuron is temporarily
“dropped” or disabled with probability P during training.
DA helps to popular
artificial training
instances from the
existing train data sets.
36
A Brief History of TensorFlow
TensorFlow is an end-to-end FOSS (free and open source software)
library for dataflow, differentiable programming. TensorFlow is one of
the most popular program frameworks for building machine learning
applications.
● Google Brain built DistBelief in 2011 for internal usage.
● TensorFlow 1.0.0 was released on Feb 11, 2017
● TensorFlow 2.0 was released in Jan 2018.
TensorFlow, Keras, and PyTorch
import tensorflow as tf
v = tf.constant("Hello World!")
tf.print(v)
TensorFlow Constants
TensorFlow provides several operations to generate constant tensor.
import tensorflow as tf
x = tf.constant(1, tf.int32)
zeros = tf.zeros([2, 3], tf.int32)
ones = tf.ones([2, 3], tf.int32)
y = x *(zeros + ones + ones)
tf.print(y)
TensorFlow Variables
TensorFlow variables can represent shared, persistent state manipulated by
your program. Weights and biases are usually stored in variables.
import tensorflow as tf
W = tf.Variable(tf.random.normal([2,2], stddev=0.1),
name = "W")
b = tf.Variable(tf.zeros(shape=(2)), name="b")
Machine Learning Workflow with tf.keras
The preprocessed data set needs A model could be defined with The configuration of the training The training begins by calling the
to be shuffled and splitted into tf.keras Sequential model for a process requires the fit function. The number of
training and testing data. linear stack of layers or tf.keras specification of an optimizer, a epochs and batch size need to be
functional API for complex loss function, and a list of set. The measurement metrics
network. metrics. need to be evaluated.
tf.keras Built-in Datasets
● tf.keras provides many popular reference datasets that could be used
for demonstrating and testing deep neural network models. To name a
few,
○ Boston Housing (regression)
○ CIFAR100 (classification of 100 image labels)
○ MNIST (classification of 10 digits)
○ Fashion-MNIST (classification of 10 fashion categories)
○ Reuters News (multiclass text classification)
● The built-in datasets could be easily read in for training purpose. E.g.,