SlideShare a Scribd company logo
1 of 51
Download to read offline
MUNICH
IN DATA REPLY
Dmitrii Azarnykh | Data Scientist at Data Reply
Jupyter notebook: https://goo.gl/z6Guvo WLAN: DO-Tagungswelt
HTML version: https://goo.gl/Nh953A PASS: DesignOffice
Git-Hub: https://goo.gl/j8LEb9
CONSULTING TEAMS IN
DATA REPLY
6
DataStrategy
Big Data3
Data Science1
Data Incubator2
Ab Initio4
MicroStrategy5
Teams
• Different aspects of Data Science are done by
different types of specialists
• Python is most used language in Data Science
group
• International, fast-growing team: more than 30
nationalities
• Employees from best Universities, >30% PhD
• Free trainings, certificates
• Traveling to conferences: ICML, ML-Prague
6
DataStrategy
Big Data3
Data Science1
Data Incubator2
Ab Initio4
MicroStrategy5
Teams
CONSULTING TEAMS IN
DATA REPLY
• Different aspects of Data Science are done by
different types of specialists
• Python is most used language in Data Science
group
• International, fast-growing team: more than 30
nationalities
• Employees from best Universities, >30% PhD
• Free trainings, certificates
• Traveling to conferences: ICML, ML-Prague
UNDERSTANDING PYTORCH:
PYTORCH IN IMAGE
PROCESSING
Dmitrii Azarnykh | Data Scientist at Data Reply
Jupyter notebook: https://goo.gl/spXV6b WLAN: DO-Tagungswelt
HTML version: https://goo.gl/Nh953A PASS: DesignOffice
OUTLINE
Automatic Differentiation
Pytorch Basics
Pytorch in image processing
AUTOMATIC
DIFFERENTIATION
THE TRUTH ABOUT TRAINING
DEEP NEURAL NETWORKS
THE TRUTH ABOUT TRAINING
DEEP NEURAL NETWORKS
𝜕𝐹(𝒙, 𝒚, 𝒘)
𝜕𝒘
TWO WAYS COMPUTE GRADIENTS
𝑥1
exp
𝑓(𝑥1)
Backward pathForward path
𝑓(𝑥1)
𝜕𝑓(𝑥1)
𝜕𝑥1
𝑥1
exp
𝑓(𝑥1)
Forward path
𝑓(𝑥1),
𝜕𝑓(𝑥1)
𝜕𝑥1
Backward propagationForward propagation
AUTOMATIC DIFFERENTIATION
𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥1
=? ;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥2
=?
𝑥1 𝑥2
exp
𝑑3
𝑑2= 0
+
𝑓(𝑥1, 𝑥2)
Forwardpropagation
ofderivativevalues
𝑑1= 1
𝑑5=𝑑3+ 𝑑4
𝑑4
mult
Loss function
Weights
AUTOMATIC DIFFERENTIATION
𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥1
=? ;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥2
=?
𝑥1 𝑥2
exp
𝑑2= 0
+
𝑓(𝑥1, 𝑥2)
Forwardpropagation
ofderivativevalues
𝑑1= 1
𝑑5=𝑑3+ 𝑑4
𝑑4
mult
𝑑3
Loss function
Weights
Use 𝑑5 to update weights.
NO BACKPROPAGATIONNEEDED
AUTOMATIC DIFFERENTIATION
𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥1
=? ;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥2
=?
𝑥1 𝑥2
exp
𝑑2= 0
+
𝑓(𝑥1, 𝑥2)
Forwardpropagation
ofderivativevalues
𝑑1= 1
𝑑5=𝑑3+ 𝑑4
𝑑4
mult
𝑑3
How many outputs?
How many inputs?
AUTOMATIC DIFFERENTIATION
𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥1
=? ;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥2
=?
𝑥1 𝑥2
exp
𝑑2= 0
+
𝑓(𝑥1, 𝑥2)
Forwardpropagation
ofderivativevalues
𝑑1= 1
𝑑5=𝑑3+ 𝑑4
𝑑4
mult
𝑑3
one or zero,
cats or dogs
Inception:
6.7 millions
AUTOMATIC DIFFERENTIATION
𝑥1 𝑥2
exp
𝑑2= 0
+
𝑓(𝑥1, 𝑥2)
Forwardpropagation
ofderivativevalues
𝑑1= 1
𝑑5=𝑑3+ 𝑑4
𝑑4
mult
𝑑3
𝑥1 𝑥2
exp
𝑥3 +
𝑓(𝑥1, 𝑥2)
Backwardpropagation
ofderivativevalues
𝑥4
𝑥5
First store values 𝑥3, 𝑥4, 𝑥5
mult
BACKPROPAGATION: FORWARD
𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥1
=? ;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥2
=?
𝑥1 𝑥2
exp mult
+
𝑓(𝑥1, 𝑥2)
Backwardpropagation
ofderivativevalues
𝑑5= 1 (𝑠𝑒𝑒𝑑)
𝑑3= 𝑑5 𝑑4 = 𝑑5
𝑑2= 𝑥1𝑑1= ⅇ 𝑥1+ 𝑥2
First store values 𝑥3, 𝑥4, 𝑥5
Then backpropagate gradients
BACKPROPAGATION: BACKWARD
𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥1
=? ;
𝜕𝑓(𝑥1,𝑥2)
𝜕𝑥2
=?
PYTORCH LIBRARY
Dynamic computational graph
Feels like python, not C++
Python library for neural network
Implemented automatic differentiation
PYTORCH TENSOR
• Tensoris N-dimensional array
• Operations on tensors are done on a CPU in parallel or on a GPU
• Syntaxis is similar to numpy
PYTORCH TENSOR
• Tensorfrom numpyarray and numpy array to tensor
• torch.tensor versus torch.as_tensor
PYTORCH TENSOR
Tensorhas many attributes. Some of these attributes:
• Data of a tensoris a tensoritself
• Gradients of tensors is also a tensor of the same size as data tensor or None
• Parameter requires_grad.Need to compute gradients only for weights, not for data
• A function to compute backpropagation
COMPUTE GRADIENTS
Function backward() computesgradients with
backpropagation
What is the output here?
COMPUTE GRADIENTS
RuntimeError: grad can be implicitly created only
for scalar outputs
Function backward() computesgradients with
backpropagation
COMPUTE GRADIENTS
RuntimeError: grad can be implicitly created only
for scalar outputs
are vectors so a gradient is a matrix. What to do?
COMPUTE GRADIENTS
COMPUTE GRADIENTS
gradients double after the second call of
backward()function
COMPUTE GRADIENTS
Gradients always sum up after backpropagation.
So we need to set gradients to zero before calling
backward() function second time.
𝑥1
exp mult
𝑥3
𝑥4𝑑3= 𝑑5
𝜕𝑑5
𝜕𝑑4
= 𝑑5
𝑑4= 𝑑5
𝜕𝑑5
𝜕𝑑3
= 𝑑5
𝑑1= 𝑑3
𝜕𝑑3
𝜕𝑑1
+ 𝑑4
𝜕𝑑4
𝜕𝑑1
= ⅇ 𝑥1 + 𝑥2
Equation of orange line:
ො𝑦 = 𝑤 ∗ 𝑥 + 𝑏
Blue dots:
(𝑥𝑖, 𝑦𝑖)
Minimize sum of squared lengths
of greenlines:
෍
𝑖
(ො𝑦𝑖 − 𝑦𝑖)2
𝑦
𝑥
LINEAR REGRESSION
features and labels, (𝑥𝑖, 𝑦𝑖)
initialize weights, need gradient 𝑤, 𝑏
train with a gradient descent:
• compute predictions, ො𝑦 = 𝑤 ∗ 𝑥 + 𝑏
• backpropagate loss ෌𝑖
( ො𝑦𝑖 − 𝑦𝑖)2
• update weights
• set gradients to zero
LINEAR REGRESSION
LINEAR REGRESSION
also possible to use optimizer to accept weights
as parameters
optimizer updates all weights and sets gradients
of all weights to zero
LINEAR REGRESSION
Note that these two lines do the same as:
LINEAR REGRESSION
Can easily plot results:
for tensors with requires_grad=True
need to cast .detach()function
before transform to numpy
EXCITING PART:
PYTORCH FOR IMAGE
PROCESSING
OUTLINE
1. Build AlexNet model
2. Load dataset
3. CUDA/GPUcompatibility
4. Training
5. Speed-up,save-load model,evaluation
STEP 1: BUILD
1. Build AlexNet model
2. Load dataset
3. CUDA/GPUcompatibility
4. Training
5. Speed-up,save-load model,evaluation
BUILD ALEXNET MODEL
Weights are downloaded
automatically.
features part is pretrained on
ImageNet.It extracts the most
useful features from the images.
We will not train this part and use
the weights we downloaded.
We will substitute and retrain
this part.
BUILD ALEXNET MODEL
do not need gradients for
features-extractorweights
a new modelforclassification
syntaxis is similar to Keras
set classifieras trainable
set features as not trainable
STEP 2: LOAD
1. Build AlexNet model
2. Load dataset
3. CUDA/GPUcompatibility
4. Training
5. Speed-up,save-load model,evaluation
LOAD DATASET
set transformation for data
create dataset: no images in
memoryyet, only their paths
and labels
split train and test: still no
images in memory
balance dataset and create a
generator, which yields batches
of images
Images are loaded in memory
only when iterations happen
STEP 3: CONVERT
1. Build AlexNet model
2. Load dataset
3. CUDA/GPU compatibility
4. Training
5. Speed-up,save-load model,evaluation
CUDA/GPU COMPATIBILITY
Graphical Processing Unit GPU Random-access memory(RAM)
• Model weights
• Images
• Labels
Solid State Drive (SSD)
• Images
(DataLoader)
STEP 4: TRAIN
1. Build AlexNet model
2. Load dataset
3. CUDA/GPUcompatibility
4. Training
5. Speed-up,save/load model,evaluation
MODEL TRAINING
send images and labels to GPU, if
GPU is used
non_blocking=Trueis used for
asynchronous computations,which
speedsup CUDA computations
MODEL TRAINING
compute predictions,estimate loss
function and backpropagate
MODEL TRAINING
make one step of gradient descent
and set gradients of trainable weights
in alexnet.classifier to zero
only classifierparameters are
passed to the optimizer
MODEL TRAINING
use tqdm to show a progress bar and
evaluate a current average batch loss
function
STEP 5: EVALUATE
1. Build AlexNet model
2. Load dataset
3. CUDA/GPUcompatibility
4. Training
5. Speed-up,save-loadmodel,evaluation
SPEED UP IMAGE LOADING
Graphical Processing Unit GPU Random-access memory(RAM)
• Model weights
• Labels
Solid State Drive (SSD)
• Images
(DataLoader)
MODEL EVALUATION
iterate on test_loaderDataLoader
push labels and probabilities firstly to CPU
and then to numpy
use scikit-learn to show metrics
SAVE/LOAD MODEL
save torch modeland the state
of the optimizer
when loading weights, need to
initialize the modeland the
optimizer first
load the weights and the state of
the optimizer
THANK YOU FOR
YOUR ATTENTION

More Related Content

Similar to Pytorch meetup

Artificial Neural Network
Artificial Neural NetworkArtificial Neural Network
Artificial Neural NetworkDessy Amirudin
 
Alpine Spark Implementation - Technical
Alpine Spark Implementation - TechnicalAlpine Spark Implementation - Technical
Alpine Spark Implementation - Technicalalpinedatalabs
 
Online learning with structured streaming, spark summit brussels 2016
Online learning with structured streaming, spark summit brussels 2016Online learning with structured streaming, spark summit brussels 2016
Online learning with structured streaming, spark summit brussels 2016Ram Sriharsha
 
COCOA: Communication-Efficient Coordinate Ascent
COCOA: Communication-Efficient Coordinate AscentCOCOA: Communication-Efficient Coordinate Ascent
COCOA: Communication-Efficient Coordinate Ascentjeykottalam
 
Learning to Rank with Neural Networks
Learning to Rank with Neural NetworksLearning to Rank with Neural Networks
Learning to Rank with Neural NetworksBhaskar Mitra
 
Introduction to PyTorch
Introduction to PyTorchIntroduction to PyTorch
Introduction to PyTorchJun Young Park
 
NVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA Japan
 
Spark Summit EU talk by Ram Sriharsha and Vlad Feinberg
Spark Summit EU talk by Ram Sriharsha and Vlad FeinbergSpark Summit EU talk by Ram Sriharsha and Vlad Feinberg
Spark Summit EU talk by Ram Sriharsha and Vlad FeinbergSpark Summit
 
Deep Feed Forward Neural Networks and Regularization
Deep Feed Forward Neural Networks and RegularizationDeep Feed Forward Neural Networks and Regularization
Deep Feed Forward Neural Networks and RegularizationYan Xu
 
Online learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and HadoopOnline learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and HadoopHéloïse Nonne
 
Using CNTK's Python Interface for Deep LearningDave DeBarr -
Using CNTK's Python Interface for Deep LearningDave DeBarr - Using CNTK's Python Interface for Deep LearningDave DeBarr -
Using CNTK's Python Interface for Deep LearningDave DeBarr - PyData
 
Deep learning from scratch
Deep learning from scratch Deep learning from scratch
Deep learning from scratch Eran Shlomo
 
Training DNN Models - II.pptx
Training DNN Models - II.pptxTraining DNN Models - II.pptx
Training DNN Models - II.pptxPrabhuSelvaraj15
 
Chap 8. Optimization for training deep models
Chap 8. Optimization for training deep modelsChap 8. Optimization for training deep models
Chap 8. Optimization for training deep modelsYoung-Geun Choi
 
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLab
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLabAdvanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLab
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLabCloudxLab
 
Gradient descent optimizer
Gradient descent optimizerGradient descent optimizer
Gradient descent optimizerHojin Yang
 
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...Universitat Politècnica de Catalunya
 

Similar to Pytorch meetup (20)

Artificial Neural Network
Artificial Neural NetworkArtificial Neural Network
Artificial Neural Network
 
Alpine Spark Implementation - Technical
Alpine Spark Implementation - TechnicalAlpine Spark Implementation - Technical
Alpine Spark Implementation - Technical
 
Online learning with structured streaming, spark summit brussels 2016
Online learning with structured streaming, spark summit brussels 2016Online learning with structured streaming, spark summit brussels 2016
Online learning with structured streaming, spark summit brussels 2016
 
COCOA: Communication-Efficient Coordinate Ascent
COCOA: Communication-Efficient Coordinate AscentCOCOA: Communication-Efficient Coordinate Ascent
COCOA: Communication-Efficient Coordinate Ascent
 
Learning to Rank with Neural Networks
Learning to Rank with Neural NetworksLearning to Rank with Neural Networks
Learning to Rank with Neural Networks
 
Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Backpropagation - Elisa Sayrol - UPC Barcelona 2018Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Backpropagation - Elisa Sayrol - UPC Barcelona 2018
 
Introduction to PyTorch
Introduction to PyTorchIntroduction to PyTorch
Introduction to PyTorch
 
NVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読み
 
Spark Summit EU talk by Ram Sriharsha and Vlad Feinberg
Spark Summit EU talk by Ram Sriharsha and Vlad FeinbergSpark Summit EU talk by Ram Sriharsha and Vlad Feinberg
Spark Summit EU talk by Ram Sriharsha and Vlad Feinberg
 
Deep Feed Forward Neural Networks and Regularization
Deep Feed Forward Neural Networks and RegularizationDeep Feed Forward Neural Networks and Regularization
Deep Feed Forward Neural Networks and Regularization
 
Online learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and HadoopOnline learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and Hadoop
 
Using CNTK's Python Interface for Deep LearningDave DeBarr -
Using CNTK's Python Interface for Deep LearningDave DeBarr - Using CNTK's Python Interface for Deep LearningDave DeBarr -
Using CNTK's Python Interface for Deep LearningDave DeBarr -
 
Deep learning from scratch
Deep learning from scratch Deep learning from scratch
Deep learning from scratch
 
Eye deep
Eye deepEye deep
Eye deep
 
Training DNN Models - II.pptx
Training DNN Models - II.pptxTraining DNN Models - II.pptx
Training DNN Models - II.pptx
 
Chap 8. Optimization for training deep models
Chap 8. Optimization for training deep modelsChap 8. Optimization for training deep models
Chap 8. Optimization for training deep models
 
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLab
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLabAdvanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLab
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLab
 
Gradient descent optimizer
Gradient descent optimizerGradient descent optimizer
Gradient descent optimizer
 
SLE2015: Distributed ATL
SLE2015: Distributed ATLSLE2015: Distributed ATL
SLE2015: Distributed ATL
 
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
 

Recently uploaded

Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...amitlee9823
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfadriantubila
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...amitlee9823
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 

Recently uploaded (20)

Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 

Pytorch meetup

  • 1. MUNICH IN DATA REPLY Dmitrii Azarnykh | Data Scientist at Data Reply Jupyter notebook: https://goo.gl/z6Guvo WLAN: DO-Tagungswelt HTML version: https://goo.gl/Nh953A PASS: DesignOffice Git-Hub: https://goo.gl/j8LEb9
  • 2. CONSULTING TEAMS IN DATA REPLY 6 DataStrategy Big Data3 Data Science1 Data Incubator2 Ab Initio4 MicroStrategy5 Teams • Different aspects of Data Science are done by different types of specialists • Python is most used language in Data Science group • International, fast-growing team: more than 30 nationalities • Employees from best Universities, >30% PhD • Free trainings, certificates • Traveling to conferences: ICML, ML-Prague
  • 3. 6 DataStrategy Big Data3 Data Science1 Data Incubator2 Ab Initio4 MicroStrategy5 Teams CONSULTING TEAMS IN DATA REPLY • Different aspects of Data Science are done by different types of specialists • Python is most used language in Data Science group • International, fast-growing team: more than 30 nationalities • Employees from best Universities, >30% PhD • Free trainings, certificates • Traveling to conferences: ICML, ML-Prague
  • 4. UNDERSTANDING PYTORCH: PYTORCH IN IMAGE PROCESSING Dmitrii Azarnykh | Data Scientist at Data Reply Jupyter notebook: https://goo.gl/spXV6b WLAN: DO-Tagungswelt HTML version: https://goo.gl/Nh953A PASS: DesignOffice
  • 7. THE TRUTH ABOUT TRAINING DEEP NEURAL NETWORKS
  • 8. THE TRUTH ABOUT TRAINING DEEP NEURAL NETWORKS 𝜕𝐹(𝒙, 𝒚, 𝒘) 𝜕𝒘
  • 9. TWO WAYS COMPUTE GRADIENTS 𝑥1 exp 𝑓(𝑥1) Backward pathForward path 𝑓(𝑥1) 𝜕𝑓(𝑥1) 𝜕𝑥1 𝑥1 exp 𝑓(𝑥1) Forward path 𝑓(𝑥1), 𝜕𝑓(𝑥1) 𝜕𝑥1 Backward propagationForward propagation
  • 10. AUTOMATIC DIFFERENTIATION 𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥1 =? ; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥2 =? 𝑥1 𝑥2 exp 𝑑3 𝑑2= 0 + 𝑓(𝑥1, 𝑥2) Forwardpropagation ofderivativevalues 𝑑1= 1 𝑑5=𝑑3+ 𝑑4 𝑑4 mult
  • 11. Loss function Weights AUTOMATIC DIFFERENTIATION 𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥1 =? ; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥2 =? 𝑥1 𝑥2 exp 𝑑2= 0 + 𝑓(𝑥1, 𝑥2) Forwardpropagation ofderivativevalues 𝑑1= 1 𝑑5=𝑑3+ 𝑑4 𝑑4 mult 𝑑3
  • 12. Loss function Weights Use 𝑑5 to update weights. NO BACKPROPAGATIONNEEDED AUTOMATIC DIFFERENTIATION 𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥1 =? ; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥2 =? 𝑥1 𝑥2 exp 𝑑2= 0 + 𝑓(𝑥1, 𝑥2) Forwardpropagation ofderivativevalues 𝑑1= 1 𝑑5=𝑑3+ 𝑑4 𝑑4 mult 𝑑3
  • 13. How many outputs? How many inputs? AUTOMATIC DIFFERENTIATION 𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥1 =? ; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥2 =? 𝑥1 𝑥2 exp 𝑑2= 0 + 𝑓(𝑥1, 𝑥2) Forwardpropagation ofderivativevalues 𝑑1= 1 𝑑5=𝑑3+ 𝑑4 𝑑4 mult 𝑑3
  • 14. one or zero, cats or dogs Inception: 6.7 millions AUTOMATIC DIFFERENTIATION 𝑥1 𝑥2 exp 𝑑2= 0 + 𝑓(𝑥1, 𝑥2) Forwardpropagation ofderivativevalues 𝑑1= 1 𝑑5=𝑑3+ 𝑑4 𝑑4 mult 𝑑3
  • 15. 𝑥1 𝑥2 exp 𝑥3 + 𝑓(𝑥1, 𝑥2) Backwardpropagation ofderivativevalues 𝑥4 𝑥5 First store values 𝑥3, 𝑥4, 𝑥5 mult BACKPROPAGATION: FORWARD 𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥1 =? ; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥2 =?
  • 16. 𝑥1 𝑥2 exp mult + 𝑓(𝑥1, 𝑥2) Backwardpropagation ofderivativevalues 𝑑5= 1 (𝑠𝑒𝑒𝑑) 𝑑3= 𝑑5 𝑑4 = 𝑑5 𝑑2= 𝑥1𝑑1= ⅇ 𝑥1+ 𝑥2 First store values 𝑥3, 𝑥4, 𝑥5 Then backpropagate gradients BACKPROPAGATION: BACKWARD 𝑓(𝑥1, 𝑥2) = 𝑥1 𝑥2 + 𝑒 𝑥1; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥1 =? ; 𝜕𝑓(𝑥1,𝑥2) 𝜕𝑥2 =?
  • 17.
  • 18. PYTORCH LIBRARY Dynamic computational graph Feels like python, not C++ Python library for neural network Implemented automatic differentiation
  • 19. PYTORCH TENSOR • Tensoris N-dimensional array • Operations on tensors are done on a CPU in parallel or on a GPU • Syntaxis is similar to numpy
  • 20. PYTORCH TENSOR • Tensorfrom numpyarray and numpy array to tensor • torch.tensor versus torch.as_tensor
  • 21. PYTORCH TENSOR Tensorhas many attributes. Some of these attributes: • Data of a tensoris a tensoritself • Gradients of tensors is also a tensor of the same size as data tensor or None • Parameter requires_grad.Need to compute gradients only for weights, not for data • A function to compute backpropagation
  • 22. COMPUTE GRADIENTS Function backward() computesgradients with backpropagation What is the output here?
  • 23. COMPUTE GRADIENTS RuntimeError: grad can be implicitly created only for scalar outputs Function backward() computesgradients with backpropagation
  • 24. COMPUTE GRADIENTS RuntimeError: grad can be implicitly created only for scalar outputs are vectors so a gradient is a matrix. What to do?
  • 26. COMPUTE GRADIENTS gradients double after the second call of backward()function
  • 27. COMPUTE GRADIENTS Gradients always sum up after backpropagation. So we need to set gradients to zero before calling backward() function second time. 𝑥1 exp mult 𝑥3 𝑥4𝑑3= 𝑑5 𝜕𝑑5 𝜕𝑑4 = 𝑑5 𝑑4= 𝑑5 𝜕𝑑5 𝜕𝑑3 = 𝑑5 𝑑1= 𝑑3 𝜕𝑑3 𝜕𝑑1 + 𝑑4 𝜕𝑑4 𝜕𝑑1 = ⅇ 𝑥1 + 𝑥2
  • 28. Equation of orange line: ො𝑦 = 𝑤 ∗ 𝑥 + 𝑏 Blue dots: (𝑥𝑖, 𝑦𝑖) Minimize sum of squared lengths of greenlines: ෍ 𝑖 (ො𝑦𝑖 − 𝑦𝑖)2 𝑦 𝑥 LINEAR REGRESSION
  • 29. features and labels, (𝑥𝑖, 𝑦𝑖) initialize weights, need gradient 𝑤, 𝑏 train with a gradient descent: • compute predictions, ො𝑦 = 𝑤 ∗ 𝑥 + 𝑏 • backpropagate loss ෌𝑖 ( ො𝑦𝑖 − 𝑦𝑖)2 • update weights • set gradients to zero LINEAR REGRESSION
  • 30. LINEAR REGRESSION also possible to use optimizer to accept weights as parameters optimizer updates all weights and sets gradients of all weights to zero
  • 31. LINEAR REGRESSION Note that these two lines do the same as:
  • 32. LINEAR REGRESSION Can easily plot results: for tensors with requires_grad=True need to cast .detach()function before transform to numpy
  • 33. EXCITING PART: PYTORCH FOR IMAGE PROCESSING
  • 34. OUTLINE 1. Build AlexNet model 2. Load dataset 3. CUDA/GPUcompatibility 4. Training 5. Speed-up,save-load model,evaluation
  • 35. STEP 1: BUILD 1. Build AlexNet model 2. Load dataset 3. CUDA/GPUcompatibility 4. Training 5. Speed-up,save-load model,evaluation
  • 36. BUILD ALEXNET MODEL Weights are downloaded automatically. features part is pretrained on ImageNet.It extracts the most useful features from the images. We will not train this part and use the weights we downloaded. We will substitute and retrain this part.
  • 37. BUILD ALEXNET MODEL do not need gradients for features-extractorweights a new modelforclassification syntaxis is similar to Keras set classifieras trainable set features as not trainable
  • 38. STEP 2: LOAD 1. Build AlexNet model 2. Load dataset 3. CUDA/GPUcompatibility 4. Training 5. Speed-up,save-load model,evaluation
  • 39. LOAD DATASET set transformation for data create dataset: no images in memoryyet, only their paths and labels split train and test: still no images in memory balance dataset and create a generator, which yields batches of images Images are loaded in memory only when iterations happen
  • 40. STEP 3: CONVERT 1. Build AlexNet model 2. Load dataset 3. CUDA/GPU compatibility 4. Training 5. Speed-up,save-load model,evaluation
  • 41. CUDA/GPU COMPATIBILITY Graphical Processing Unit GPU Random-access memory(RAM) • Model weights • Images • Labels Solid State Drive (SSD) • Images (DataLoader)
  • 42. STEP 4: TRAIN 1. Build AlexNet model 2. Load dataset 3. CUDA/GPUcompatibility 4. Training 5. Speed-up,save/load model,evaluation
  • 43. MODEL TRAINING send images and labels to GPU, if GPU is used non_blocking=Trueis used for asynchronous computations,which speedsup CUDA computations
  • 44. MODEL TRAINING compute predictions,estimate loss function and backpropagate
  • 45. MODEL TRAINING make one step of gradient descent and set gradients of trainable weights in alexnet.classifier to zero only classifierparameters are passed to the optimizer
  • 46. MODEL TRAINING use tqdm to show a progress bar and evaluate a current average batch loss function
  • 47. STEP 5: EVALUATE 1. Build AlexNet model 2. Load dataset 3. CUDA/GPUcompatibility 4. Training 5. Speed-up,save-loadmodel,evaluation
  • 48. SPEED UP IMAGE LOADING Graphical Processing Unit GPU Random-access memory(RAM) • Model weights • Labels Solid State Drive (SSD) • Images (DataLoader)
  • 49. MODEL EVALUATION iterate on test_loaderDataLoader push labels and probabilities firstly to CPU and then to numpy use scikit-learn to show metrics
  • 50. SAVE/LOAD MODEL save torch modeland the state of the optimizer when loading weights, need to initialize the modeland the optimizer first load the weights and the state of the optimizer
  • 51. THANK YOU FOR YOUR ATTENTION