Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters...

23
Midterm Review CS230 Spring 2019

Transcript of Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters...

Page 1: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Midterm ReviewCS230 Spring 2019

Page 2: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Outline- Forward and Backpropagation- Optimization Methods- Bias & Variance- Batch Normalization- Adversarial Examples- GANs- CNNs

Page 3: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Forward and Backpropagation

Activations:

● Relu● Sigmoid● Tanh

Losses:

● Mean Square Error● Cross Entropy

Hints:

● Remember to use the chain rule.● Gradients of a parameter with respect to the loss

function have the same dimension as the parameter.

(1) Forward Propagation - Compute the output of the model - Use the output and label to compute loss

(2) Backward Propagation - Take the gradients of the loss with respect to the parameters - Update parameters with gradients

Further Reading and proofs

Page 4: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Forward and Backpropagation

Further Reading and proofs

Page 5: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Optimization Methods

● Gradient Descent - update parameters in the opposite direction of their gradient.

○ Stochastic - batch size of 1.○ Mini Batch - batch size of 1 < m < n.○ Full Batch - batch size of n.

● Momentum - accelerate gradient descent by adding a fraction of the update vector from previous steps to the current update.

● RMSprop - adapts the learning rate to the features by dividing by previous squared gradients.

● Adam - a mixture of momentum and adaptive learning rate.Visualization of optimization methods.

Page 6: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Optimization Methods

Visualization of optimization methods.

Hyperparameters:● Batch Size● Learning Rate● Learning Rate Decay

Page 7: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Initialization Methods

● Xavier

○ Weights and inputs are centered at zero○ Weights and inputs are independent and identically distributed○ Biases are initialized as zeros○ Activation function is 0 centred eg. TanH○ Var(a)≈Var(z)

● He

○ ReLU activations (Note that ReLU is not a 0 centred activation)

Further Reading and proofs

Page 8: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Bias & Variance

Page 9: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Bias & Variance

- Cat classifier

Human/Optimal/Bayes error: 3%

4%

15%

High variance

11%

12%

High bias

15%

30%

High bias & high variance

Low bias & low variance

4%

4.5%

Train set error

Dev set error

Page 10: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Bias & Variance Recipe

High bias?(train set performance)

High Variance?(dev set performance)

- Bigger network- Train longer- NN architecture search

- More data- Regularization- (NN architecture search)

Y

N

Y

N

Done

Page 11: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Regularization

- L1, L2 (weight decay)- Inverted dropout (no dropout during test time!)- Data augmentation: crop, flip, rotate, …- Early stopping

Page 12: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Normalize inputs

Zero-mean:

Unit-variance:

Page 13: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Batch Normalization

- Mini-batch Batch Norm- Usually applied before activation- At test time: use running average of mean and var computed during train time

Page 14: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Batch Normalization

Why does it work?

- Faster learning: each dimension takes similar range of values- Mitigate covariate shift

(Make weights in later layers more robust to weight changes in earlier layers)- Slight regularization effect: mean and var of mini-batches add noise

Page 15: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Adversarial examples

- Creating adversarial examples (Gradient Method, Fast Gradient Sign Method)

- Black Box vs. White Box attacks- Defences against adversarial examples

- SafetyNet- Train on correctly labelled adversarial examples- Adversarial Training (train with perturbed version of input)

Page 16: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Generative Adversarial Networks (GANs)

Page 17: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Generative Adversarial Networks (GANs)

Page 18: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Convolutional Neural Networks (CNNs)

Motivation:

NN architecture suitable for high dimensional inputs and prediction tasks that benefit from spatial pattern recognition

Why?

● Reduced number of parameters due to parameter sharing and sparsity of connections

● The convolution operation as a way of detecting visual features

Page 19: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Convolutional Neural Networks (CNNs)

Basic building blocks:

● Convolution Layers (CONV)

● Pooling Layers (POOL)

● Fully connected Layers (FC)

Page 20: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Convolutional Neural Networks (CNNs)

Convolution Layers:

● 2D (No depth) ● 3D (e.g RGB channels)

# learnable parameters = (f * f (+1 for bias)) * nf

Output shape = (n-f+1) * (n-f+1) * nf

# learnable parameters = (f * f * nc (+1 for bias)) * nf Output shape = (n-f+1) * (n-f+1) * nf

Hyperparameters: Stride (s), Padding (p), Filter size (f)

Page 21: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Convolutional Neural Networks (CNNs)

Padding and Strided Convolution Layers:

Output shape with padding = (n-f+1+2p) * (n-f+1+2p) * nf

● “Valid” convolutions ⇔ No padding:

● “Same” convolutions ⇔ Output shape should match Input shape

Output shape = (n-f+1) * (n-f+1) * nf

p for “Same” convolutions = (f-1)/2

● General formula for output shape: x nf

Page 22: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Convolutional Neural Networks (CNNs)

Pooling Layers:

x nc ● General formula for output shape:

Hyperparameters: Stride (s), Filter size (f)

Page 23: Midterm Review - CS230 Deep Learning · Optimization Methods Gradient Descent - update parameters in the opposite direction of their gradient. Stochastic - batch size of 1. Mini Batch

Menti Quiz