65
Hands-on Deep Learning in Python Imry Kissos Deep Learning Meetup TLV August 2015

Hands-on Deep Learning in Python

  • Upload
    imryki

  • View
    13.470

  • Download
    4

Embed Size (px)

Citation preview

Page 1: Hands-on Deep Learning in Python

Hands-on Deep Learning in Python

Imry KissosDeep Learning MeetupTLV August 2015

Page 2: Hands-on Deep Learning in Python

Outline

● Problem Definition● Training a DNN

● Improving the DNN● Open Source Packages● Summary

2

Page 3: Hands-on Deep Learning in Python

Problem Definition

3

Deep Convolution Network

1 http://danielnouri.org/notes/2014/12/17/using-convolutional-neural-nets-to-detect-facial-keypoints-tutorial/

Page 4: Hands-on Deep Learning in Python

Tutorial

● Goal: Detect faciallandmarks on (normal)face images● Data set provided by Dr. Yoshua Bengio● Tutorial code available:https://github.com/dnouri/kfkd-tutorial/blob/master/kfkd.py

4

Page 5: Hands-on Deep Learning in Python

Flow

5

Predict Points on Test Set

Train ModelGeneral

Train Model “Nose Tip”

Train Model “Mouth Corners”

Page 6: Hands-on Deep Learning in Python

Flow

6

Train ImagesTrain Points

Fit TrainedNet

Page 7: Hands-on Deep Learning in Python

Flow

7

Test Images

Predict Predicted Points

Page 8: Hands-on Deep Learning in Python

Python Deep Learning Framework

nolearn - Wrapper to Lasagne

Lasagne - Theano extension for Deep Learning

Theano - Define, optimize, and mathematical expressions

Efficient Cuda GPU for DNN

8

Low Level

High Level

HW Supports: GPU & CPUOS: Linux, OS X, Windows

Page 9: Hands-on Deep Learning in Python

Training a Deep Neural Network

1. Data Analysis2. Architecture Engineering3. Optimization4. Training the DNN

9

Page 10: Hands-on Deep Learning in Python

Training a Deep Neural Network

1. Data Analysisa. Exploration + Validationb. Pre-Processingc. Batch and Split

2. Architecture Engineering3. Optimization4. Training the DNN

10

Page 11: Hands-on Deep Learning in Python

Data Exploration + ValidationData:● 7K gray-scale images of detected faces● 96x96 pixels per image● 15 landmarks per image (?)

Data validation:● Some Landmarks are missing

11

1

Page 12: Hands-on Deep Learning in Python

Pre-Processing

12

Data Normalization

Shuffle train data

Page 13: Hands-on Deep Learning in Python

Batch-- t - train batch

- validation batch

- - test batch

⇐One Epoch’s data

13train/valid/test splits are constant

Page 14: Hands-on Deep Learning in Python

Train / Validation Split

14

Classification - Train/Validation preserve classes proportion

Page 15: Hands-on Deep Learning in Python

Training a Deep Neural Network

1. Data Analysis2. Architecture Engineering

a. Layers Definitionb. Layers Implementation

3. Optimization4. Training

15

Page 16: Hands-on Deep Learning in Python

Architecture

16

X Y

Conv Pool Dense Output

Page 17: Hands-on Deep Learning in Python

Layers Definition

17

Page 18: Hands-on Deep Learning in Python

Activation Function

18

1

ReLU

Page 19: Hands-on Deep Learning in Python

Dense Layer

19

Page 20: Hands-on Deep Learning in Python

Dropout

20

Page 21: Hands-on Deep Learning in Python

Dropout

21

Page 22: Hands-on Deep Learning in Python

Training a Deep Neural Network

1. Data Analysis2. Architecture Engineering3. Optimization

a. Back Propagationb. Objectivec. SGDd. Updatese. Convergence Tuning

4. Training the DNN 22

Page 23: Hands-on Deep Learning in Python

Back PropagationForward Path

23

Conv Dense

X Y

OutputPoints

Page 24: Hands-on Deep Learning in Python

Back PropagationForward Path

24

X Y

ConvOutputPointsDense

X Y

Training Points

Page 25: Hands-on Deep Learning in Python

Back PropagationBackward Path

25

X Y

Conv Dense

Page 26: Hands-on Deep Learning in Python

Back PropagationUpdate

26

Conv Dense

For All Layers:

Page 27: Hands-on Deep Learning in Python

Objective

27

Page 28: Hands-on Deep Learning in Python

S.G.D

28

Updates the network after each batch

Karpathy - “Babysitting”: weights/updates ~1e3

Page 30: Hands-on Deep Learning in Python

Adjusting Learning Rate & Momentum

30

Linear in epoch

Page 31: Hands-on Deep Learning in Python

Convergence Tuning

31

stops according to validation loss

returns best weights

Page 32: Hands-on Deep Learning in Python

Training a Deep Neural Network

1. Data Analysis2. Architecture Engineering3. Optimization4. Training the DNN

a. Fitb. Fine Tune Pre-Trainedc. Learning Curves

32

Page 33: Hands-on Deep Learning in Python

Fit

33

Loop over validation batchs

Forward

Loop over train batchs

Forward+BackProp

Page 34: Hands-on Deep Learning in Python

Fine Tune Pre-Trained

fgd

34

change output layer

load pre-trained weight

fine tune specialist

Page 35: Hands-on Deep Learning in Python

Learning CurvesLoop over 6 Nets:

35

Epochs

Page 36: Hands-on Deep Learning in Python

Learning Curves Analysis

36

Net 1

Net 2

OverfittingConvergence Jittering

EpochsEpochs

RM

SE

RM

SE

Page 37: Hands-on Deep Learning in Python

Part 1 Summary

Training a DNN:

37

Page 38: Hands-on Deep Learning in Python

Part 1 EndBreak

Page 39: Hands-on Deep Learning in Python

Part 2 Beyond Training

Page 40: Hands-on Deep Learning in Python

Outline

● Problem Definition● Motivation● Training a DNN● Improving the DNN● Open Source Packages● Summary

40

Page 41: Hands-on Deep Learning in Python

Beyond Training

1. Improving the DNNa. Analysis Capabilitiesb. Augmentationc. Forward - Backward Pathd. Monitor Layers’ Training

2. Open Source Packages3. Summary

41

Page 42: Hands-on Deep Learning in Python

Improving the DNN

Very tempting:● >1M images● >1M parameters● Large gap: Theory ↔ Practice

⇒Brute force experiments?!

42

Page 43: Hands-on Deep Learning in Python

Analysis Capabilities

1. Theoretical explanationa. Eg. dropout and augmentation decrease overfit

2. Empirical claims about a phenomenaa. Eg. normalization improves convergence

3. Numerical understandinga. Eg. exploding / vanishing updates

43

Page 44: Hands-on Deep Learning in Python

Reduce Overfitting

Solution:Data Augmentation

44

Net 1

Net 2

OverfittingEpochs

Page 45: Hands-on Deep Learning in Python

Data Augmentation

Horizontal Flip Perturbation

45

1

Page 46: Hands-on Deep Learning in Python

Advanced Augmentation

http://benanne.github.io/2015/03/17/plankton.html 46

Page 47: Hands-on Deep Learning in Python

Convergence Challenges

47Need to monitor forward + backward path

EpochsEpochs

RM

SE

Data ErrorNormalization

Page 48: Hands-on Deep Learning in Python

Forward - Backward PathForward

Backward:

Gradient w.r.t parameters

48

Page 49: Hands-on Deep Learning in Python

Monitor Layers’ Training

nolearn - visualize.py

49

Page 50: Hands-on Deep Learning in Python

Monitor Layers’ Training

50

X. Glorot ,Y. Bengio, Understanding the difficulty of training deep feedforward neural networks:

“Monitoring activation and gradients across layers and training iterations is a powerful investigation tool”

Easy to monitor in Theano Framework

Page 51: Hands-on Deep Learning in Python

Weight Initialization matters (1)

51

Layer 1- Gradient are close to zero - vanishing gradients

Page 52: Hands-on Deep Learning in Python

Weight Initialization matters (2)

52

Network returns close to zero values for all inputs

Page 53: Hands-on Deep Learning in Python

Monitoring Activation

plateaus sometimes seen when training neural networks

53

For most epochs the network returns close to zero output for all inputs

Objective plateaus sometimes can be explained by saturation

Page 54: Hands-on Deep Learning in Python

Max of Weights of Conv1:

Max of Updates of Conv1:

54http://cs231n.github.io/neural-networks-3/#baby

Monitoring weights/update ratio3e-1

2e-1

1e-1

0

3e-3

2e-3

1e-3

0

Epoch

Epoch

Page 55: Hands-on Deep Learning in Python

Beyond Training

1. Improving the DNN2. Open Source Packages

a. Hardware and OSb. Python Frameworkc. Deep Learning Open Source Packagesd. Effort Estimation

3. Summary

55

Page 56: Hands-on Deep Learning in Python

Hardware and OS● Amazon Cloud GPU:

AWS Lasagne GPU Setup Spot ~ $0.0031 per GPU Instance Hour● IBM Cloud GPU:

http://www-03.ibm.com/systems/platformcomputing/products/symphony/gpuharvesting.html

● Your Linux machine GPU:pip install -r https://raw.githubusercontent.com/dnouri/kfkd-

tutorial/master/requirements.txt

● Window install

http://deeplearning.net/software/theano/install_windows.html#install-windows

56

Page 57: Hands-on Deep Learning in Python

Starting Tips● Sanity Checks:

○ DNN Architecture : “Overfit a tiny subset of data” Karpathy

○ Check Regularization ↗ Loss ↗

● Use pre-trained VGG as a base line

● Start with ~3 conv layer with ~16 filter each - quickly iterate

57

Page 58: Hands-on Deep Learning in Python

Python

● Rich eco-system● State-of-the-art● Easy to port from prototype to production

58Podcast : http://www.reversim.com/2015/10/277-scientific-python.html

Page 59: Hands-on Deep Learning in Python

Python Deep Learning Framework

59Keras ,pylearn2, OpenDeep, Lasagne - common base

Page 60: Hands-on Deep Learning in Python

Tips from Deep Learning PackagesTorch code organization Caffe’s separation

configuration ↔code

NeuralNet → YAML text format defining experiment’s configuration

60

Page 61: Hands-on Deep Learning in Python

Deep Learning Open Source Packages

61

Caffe for applications Torch and Theano for research on Deep Learning itselfhttp://fastml.com/torch-vs-theano/

Black BoxWhite Box

Open source progress rapidly→ impossible to predict industry’s standard

Page 62: Hands-on Deep Learning in Python

Disruptive Effort Estimation

Feature Eng Deep Learning

62Still requires algorithmic expertise

Page 63: Hands-on Deep Learning in Python

Summary

● Dove into Training a DNN● Presented Analysis Capabilities● Reviewed Open Source Packages

63

Page 64: Hands-on Deep Learning in Python

ReferencesHinton Coursera Neuronal Networkhttps://www.coursera.org/course/neuralnetsTechnion Deep Learning coursehttp://moodle.technion.ac.il/course/view.php?id=4128Oxford Deep Learning coursehttps://www.youtube.com/playlist?list=PLE6Wd9FR--EfW8dtjAuPoTuPcqmOV53FuCS231n CNN for Visual Recognitionhttp://cs231n.github.io/Deep Learning Bookhttp://www.iro.umontreal.ca/~bengioy/dlbook/Montreal DL summer schoolhttp://videolectures.net/deeplearning2015_montreal/

64

Page 65: Hands-on Deep Learning in Python

Questions?

65

Deep Convolution Regression Network