09 Tensorflow101 Slide
09 Tensorflow101 Slide
DataLab
• Why TensorFlow?
• Environment Setup
• TensorFlow 2 Quickstart
• Dataset Preparation
• Building Model via Sequential API, Functional API, and Model Subclassing
• Why TensorFlow?
• Environment Setup
• TensorFlow 2 Quickstart
• Dataset Preparation
• Building Model via Sequential API, Functional API, and Model Subclassing
•
Initialization
•
Feedforward
• The forward pass consists of the dot operation, which
turns out to be just matrix multiplication
• As you have learned in the earlier lecture, a numerical stable version of the
softmax function was chosen
Backpropagation
• Backpropagation, short for backward propagation of
errors, is key to supervised learning of deep neural
networks
• The backward pass is hard to get right, because there are so many sizes
and operations that have to align, for all the operations to be successful
Training
• We have defined a forward and backward pass, but how
can we start using them?
Number of epochs
Compute predictions
Compute gradients
Update networks
Optimization
•
Optimization
Results
• The results completely dependent on how the weights are
initialized and the activation function we use
• Training with SGD optimizer with momentum should have better result
since it avoids from getting stuck in local minima or saddle points
• Why TensorFlow?
• Environment Setup
• TensorFlow 2 Quickstart
• Dataset Preparation
• Building Model via Sequential API, Functional API, and Model Subclassing
• Why TensorFlow?
• Environment Setup
• TensorFlow 2 Quickstart
• Dataset Preparation
• Building Model via Sequential API, Functional API, and Model Subclassing
LINK
Install CUDA
• Please refer to TensorFlow website, GPU Support section,
for more details and latest information
• Python 3.5–3.8
• Windows 7 or later
• The types of GPUs available in Colab vary over time, including Nvidia K80, T4,
P4, P100
• There is no way to choose what type of GPU you can connect to in Colab at
any given time
• Why TensorFlow?
• Environment Setup
• TensorFlow 2 Quickstart
• Dataset Preparation
• Building Model via Sequential API, Functional API, and Model Subclassing
• This is done to more efficiently use the relatively precious GPU memory
resources on the devices by reducing memory fragmentation
Allocate subset
of memory
Outline
• Neural Networks from Scratch
• Why TensorFlow?
• Environment Setup
• TensorFlow 2 Quickstart
• Dataset Preparation
• Building Model via Sequential API, Functional API, and Model Subclassing
• Why TensorFlow?
• Environment Setup
• TensorFlow 2 Quickstart
• Dataset Preparation
• Building Model via Sequential API, Functional API, and Model Subclassing
Model architecture
Loss function
Optimizer
Build model via Sequential API
• The Model.summary method prints a string summary of
the network, which is quite useful to examining model
architecture before training
= 784*128 + 128
= 128*10 + 10
Build model via Sequential API
• The Model.fit method adjusts the model parameters to
minimize the loss:
• The functional API can handle models with non-linear topology, shared
layers, and even multiple inputs or outputs
Build model via Functional API
• The main idea is that a deep learning model is usually a
directed acyclic graph (DAG) of layers. So the functional
API is a way to build graphs of layers
= 784*128 + 128
= 128*10 + 10
Build model via Model Subclassing
• Model subclassing is fully-customizable and enables
you to implement your own custom forward-pass of
the model
Model architecture
Forward path
Custom Training
• You can always train the model with model.fit and
model.evaluate, no matter which method you used to
build the model
Compute predictions
Compute
gradients
Update networks
Gradients and Automatic Differentiation
• One of the most important and powerful features of deep
learning framework is automatic differentiation and
gradients
Gradients and Automatic Differentiation
• As we can see in Neural Networks from Scratch, building
neural networks manually requires strong knowledge of
backpropagation algorithm
Simple
1 2 3
Flexibility
3 2 1
• Why TensorFlow?
• Environment Setup
• TensorFlow 2 Quickstart
• Dataset Preparation
• Building Model via Sequential API, Functional API, and Model Subclassing
• Why TensorFlow?
• Environment Setup
• TensorFlow 2 Quickstart
• Dataset Preparation
• Building Model via Sequential API, Functional API, and Model Subclassing
•
Customize Gradient Flow
• The gradient expression can be analytically simplified to
provide numerical stability:
Reference
• TensorFlow