SlideShare a Scribd company logo
PyTorch Python Tutorial | Deep Learning Using PyTorch | Image Classifier Using PyTorch | Edureka
Agenda
What is Deep Learning?
What is PyTorch?
Creating a Neural Network
PyTorch v/s TensorFlow
Use-Case of PyTorch
Summary
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
What is Deep Learning?
We will begin by looking at what led to formation of Deep Learning.
AI, Machine Learning and Deep Learning
What is Deep Learning?
Input Layer
Hidden Layer 1
Hidden Layer 2
Output Layer
A collection of statistical machine learning techniques used to learn feature hierarchies often based on artificial neural networks
AI & Deep Learning Training www.edureka.co
Programming languages
for Neural Networks
Multiple languages allow support for working with Neural Networks!
Copyright © 2018, edureka and/or its affiliates. All rights reserved.
AI & Deep Learning Training www.edureka.co
Maximised support!
LisP
AI & Deep Learning Training www.edureka.co
Python for Deep Learning
Let’s focus on the libraries Python has to offer!
Copyright © 2018, edureka and/or its affiliates. All rights reserved.
AI & Deep Learning Training www.edureka.co
Python Libraries
4 Python Deep Learning libraries we’ve found to be the most useful and popular!
AI & Deep Learning Training www.edureka.co
Python Libraries
4 Python Deep Learning libraries we’ve found to be the most useful and popular!
AI & Deep Learning Training www.edureka.co
What is PyTorch?
The new kid in the block!
Copyright © 2018, edureka and/or its affiliates. All rights reserved.
AI & Deep Learning Training www.edureka.co
PyTorch – An Introduction
Dynamic Computation
Graphs
Python Support
Easy to Use API
Actively used
Fast and Feels
Native
Support for CUDA
PyTorch is a Python based scientific computing package
AI & Deep Learning Training www.edureka.co
PyTorch - Origin
• PyTorch is a cousin of lua-based Torch framework.
• PyTorch is not a simple set of wrappers to support popular language.
AI & Deep Learning Training www.edureka.co
PyTorch Installation
Let’s up open up PyCharm and see how to install PyTorch!
Copyright © 2018, edureka and/or its affiliates. All rights reserved.
AI & Deep Learning Training www.edureka.co
Major PyTorch Concepts
An insight into what PyTorch has to offer to the developers!
Copyright © 2018, edureka and/or its affiliates. All rights reserved.
AI & Deep Learning Training www.edureka.co
PyTorch - Concepts
Neural Network Layer - Stores State or Learnable Weights
Terminologies
Tensor Imperative N-Dimensional Array Running on GPU
Variable Node in Computational Graph - To store Data and Gradient
Module
AI & Deep Learning Training www.edureka.co
The NumPy Bridge!
Breakthrough performance!
AI & Deep Learning Training www.edureka.co
The NumPy Bridge!
• Converting Torch Tensor to NumPy array and vice versa.
• Torch Tensor and NumPy array will share underlying memory locations.
Torch Tensor
NumPy array
NumPy
PyTorch
AI & Deep Learning Training www.edureka.co
Autograd Module
Saves time by calculating differentiation of parameters at forward pass
Automatic
Differentiation
Replay Backwards
Compute Gradients
Negative of the slope
Calculate the minima of the trace function
Records Operations
Training Dataset
AI & Deep Learning Training www.edureka.co
Autograd Module
torch.Tensor Central Class of Package
.requires_grad as True Track all Operations
Attribute
After
computation
Call .backward() Gradients Computed Stored in .grad Attribute
Stop Tracking History Call .detach()
torch.no_grad()
AI & Deep Learning Training www.edureka.co
Creating a Neural Network
An insight into how a Neural Network can be created and used
Copyright © 2018, edureka and/or its affiliates. All rights reserved.
AI & Deep Learning Training www.edureka.co
Creating a Neural Network
Simple Feed-Forward Network
Neural Networks torch.nn package
using
Autograd
Define models and differentiate them
Layers
Methods Forward(input) Returns output
nn.Module
Start
Construct
AI & Deep Learning Training www.edureka.co
Training Algorithm
Inputs Calculate Loss Back Propagation Update Parameters
train_batch
labels_batch
output_batch
PyTorch
Variables
Derivatives calculated automatically
AI & Deep Learning Training www.edureka.co
Creating a Neural Network
Training procedure for a Neural Network is as follows:
Define the Neural Network
Iterate over Dataset
Process the Input
Compute the Loss
Propagate Gradients Back
Update the weights
weight = weight - learning_rate * gradient
AI & Deep Learning Training www.edureka.co
Creating a Neural Network
Torch.Tensor
nn.Module
nn.Parameter
Autograd.Function
Multi-dimensional array with support for autograd operations like backward()
Neural Network module for encapsulating parameters to move them to GPU
Tensor which is registered as parameter when assigned as attribute to Module
Implements forward and backward definitions of an autograd operation
AI & Deep Learning Training www.edureka.co
Creating a Neural Network
At this point, we covered:
• Defining a Neural Network
• Processing Inputs and Calling Backwards
• Computing the Loss
• Updating the Weights of the Network
AI & Deep Learning Training www.edureka.co
PyTorch v/s TensorFlow
An insight comparing both of the frameworks
Copyright © 2018, edureka and/or its affiliates. All rights reserved.
AI & Deep Learning Training www.edureka.co
Comparison – An overview
Dynamic Computational Graphs Static Computational Graphs
Can make use of Standard Python Flow Control Cannot make use of Standard Python Flow Control
Support for Python Debuggers Cannot use native Python Debuggers
Dynamic Inspection of Variables and Gradients Cannot inspect Variables and Gradients Dynamically
Research Production
AI & Deep Learning Training www.edureka.co
PyTorch – Use Case
Let’s look at the working and generation of an image classifier.
Copyright © 2018, edureka and/or its affiliates. All rights reserved.
AI & Deep Learning Training www.edureka.co
Problem Statement
Generating an Image Classifier which predicts data based on an Image-Set by constructing a Neural Network which is used by
companies like Google to create Image-to-Text Applications such as Translation etc.
Using this we optimise accuracy of data obtained!
AI & Deep Learning Training www.edureka.co
Dataset
What about data?
Standard Python Packages can be used to load data into numpy array.
Then can be converted into a torch.*Tensor.
torchvision package helps to avoid writing boilerplate code
Image
• Pillow
• OpenCV
Audio
• Scipy
• Librosa
Text
• SpaCy
• Cython
AI & Deep Learning Training www.edureka.co
CIFAR10
• Let’s use the CIFAR10 dataset.
• The images in CIFAR-10 are of size 3x32x32, i.e. 3-channel colour images of 32x32 pixels in size.
AI & Deep Learning Training www.edureka.co
Flow Diagram
Start
Load the
Dataset
Read the
Dataset
Normalize test Dataset using
torchvision
Define Convolution Neural
Network (CNN)
Define Loss Function
Train the
Network
Test the Network Based on
Trained Data
End
Repeat the process to
Decrease the Loss
Pre-processing of dataset
Make Prediction on the Test
Data
AI & Deep Learning Training www.edureka.co
Training an Image Classifier
We will do the following steps in order:
Load and Normalize CIFAR10 using torchvision
Define Convolution Neural Network
Define Loss Function
Train the Network on Training Data
Test the Network on Test Data
Update the weights
weight = weight - learning_rate * gradient
AI & Deep Learning Training www.edureka.co
Step 1: Loading and Normalizing CIFAR10
Using torchvision, it’s extremely easy to load CIFAR10!
Load and Normalize CIFAR10
Define CNN
Define Loss Function
Train the Network
Test the Network
Update the weights
Load Data
Normalize Data Convert into Tables
Inputs
AI & Deep Learning Training www.edureka.co
Step 2: Define a Convolution Neural Network
3-Channel Images
Red Green Blue
Load and Normalize CIFAR10
Define CNN
Define Loss Function
Train the Network
Test the Network
Update the weights
AI & Deep Learning Training www.edureka.co
Step 3: Define a Loss Function and Optimizer
Classification Cross-Entropy Loss
Load and Normalize CIFAR10
Define CNN
Define Loss Function
Train the Network
Test the Network
Update the weights
AI & Deep Learning Training www.edureka.co
Step 4: Train the Network
Loop over Data Iterator
Feed the Inputs
Optimize
Training
Load and Normalize CIFAR10
Define CNN
Define Loss Function
Train the Network
Test the Network
Update the weights
AI & Deep Learning Training www.edureka.co
Step 5: Test the Network on Test Data
Check for Changes in Model
Predict Output Class Label
Check against
ground-truth
Add sample to Correct Predictions
Correct
Incorrect
Load and Normalize CIFAR10
Define CNN
Define Loss Function
Train the Network
Test the Network
Update the weights
AI & Deep Learning Training www.edureka.co
Results
• The results seem pretty good. Network did learn something!
• Let us look at how the network performs on the whole dataset.
AI & Deep Learning Training www.edureka.co
Session In A Minute
What is Deep Learning? Programming Languages Deep Learning Libraries
PyTorch PyTorch v/s TensorFlow Use-Case Implementation
Copyright © 2018, edureka and/or its affiliates. All rights reserved.
PyTorch Python Tutorial | Deep Learning Using PyTorch | Image Classifier Using PyTorch | Edureka

More Related Content

What's hot (20)

PPTX
Pytorch
ehsan tr
 
PDF
Transfer Learning: An overview
jins0618
 
PDF
Deep Learning - Convolutional Neural Networks
Christian Perone
 
PDF
GAN - Theory and Applications
Emanuele Ghelfi
 
PPTX
Scikit Learn intro
9xdot
 
PDF
Introduction to Machine Learning with SciKit-Learn
Benjamin Bengfort
 
PDF
An introduction to the Transformers architecture and BERT
Suman Debnath
 
PDF
Neural networks and deep learning
Jörgen Sandig
 
PPTX
Convolutional neural network from VGG to DenseNet
SungminYou
 
PPTX
Transformers AI PPT.pptx
RahulKumar854607
 
PPTX
Introduction For seq2seq(sequence to sequence) and RNN
Hye-min Ahn
 
PPTX
Deep learning
Ratnakar Pandey
 
PDF
ML Basics
SrujanaMerugu1
 
PDF
Neural Networks: Multilayer Perceptron
Mostafa G. M. Mostafa
 
PPTX
Deep neural networks
Si Haem
 
PPTX
Support vector machine-SVM's
Anudeep Chowdary Kamepalli
 
PPTX
Batch normalization presentation
Owin Will
 
PPTX
Scikit-Learn Tutorial | Machine Learning With Scikit-Learn | Sklearn | Python...
Simplilearn
 
Pytorch
ehsan tr
 
Transfer Learning: An overview
jins0618
 
Deep Learning - Convolutional Neural Networks
Christian Perone
 
GAN - Theory and Applications
Emanuele Ghelfi
 
Scikit Learn intro
9xdot
 
Introduction to Machine Learning with SciKit-Learn
Benjamin Bengfort
 
An introduction to the Transformers architecture and BERT
Suman Debnath
 
Neural networks and deep learning
Jörgen Sandig
 
Convolutional neural network from VGG to DenseNet
SungminYou
 
Transformers AI PPT.pptx
RahulKumar854607
 
Introduction For seq2seq(sequence to sequence) and RNN
Hye-min Ahn
 
Deep learning
Ratnakar Pandey
 
ML Basics
SrujanaMerugu1
 
Neural Networks: Multilayer Perceptron
Mostafa G. M. Mostafa
 
Deep neural networks
Si Haem
 
Support vector machine-SVM's
Anudeep Chowdary Kamepalli
 
Batch normalization presentation
Owin Will
 
Scikit-Learn Tutorial | Machine Learning With Scikit-Learn | Sklearn | Python...
Simplilearn
 

Similar to PyTorch Python Tutorial | Deep Learning Using PyTorch | Image Classifier Using PyTorch | Edureka (20)

PDF
Deep-Learning-with-PydddddddddddddTorch.pdf
drjigarsoni28
 
PDF
PyTorch Deep Learning Framework | USDSI®
USDSI
 
PDF
pytdddddddddddddddddddddddddddddddddorch.pdf
drjigarsoni28
 
PDF
Pytorch A Detailed Overview Agladze Mikhail
ilzobrzan47
 
PPTX
Transfer Leaning Using Pytorch synopsis Minor project pptx
Ankit Gupta
 
PPTX
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
Anant Garg
 
PPTX
Mastering PyTorch: A Comprehensive Guide for Deep Learning Enthusiasts
YourTechDiet
 
PDF
Machine learning with py torch
Riza Fahmi
 
PDF
PyTorch vs TensorFlow: The Force Is Strong With Which One? | Which One You Sh...
Edureka!
 
PDF
OpenPOWER Workshop in Silicon Valley
Ganesan Narayanasamy
 
PPTX
python_libraries_for_artificial_intelligence.pptx
salehaalsaleh602
 
PPTX
Machine Learning Toolssssssssssssss.pptx
salehaalsaleh602
 
PDF
Torch: a scientific computing framework for machine-learning practitioners
Hoffman Lab
 
PDF
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
Kendall
 
PDF
PyTorch crash course
Nader Karimi
 
PDF
PyTorch for Deep Learning Practitioners
Bayu Aldi Yansyah
 
PDF
Neural Networks from Scratch - TensorFlow 101
Gerold Bausch
 
PDF
Introduction To TensorFlow | Deep Learning with TensorFlow | TensorFlow For B...
Edureka!
 
PDF
01_pytorch_workflow jutedssd huge hhgggdf
stuartkyeswa4
 
PDF
Scaling Up AI Research to Production with PyTorch and MLFlow
Databricks
 
Deep-Learning-with-PydddddddddddddTorch.pdf
drjigarsoni28
 
PyTorch Deep Learning Framework | USDSI®
USDSI
 
pytdddddddddddddddddddddddddddddddddorch.pdf
drjigarsoni28
 
Pytorch A Detailed Overview Agladze Mikhail
ilzobrzan47
 
Transfer Leaning Using Pytorch synopsis Minor project pptx
Ankit Gupta
 
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
Anant Garg
 
Mastering PyTorch: A Comprehensive Guide for Deep Learning Enthusiasts
YourTechDiet
 
Machine learning with py torch
Riza Fahmi
 
PyTorch vs TensorFlow: The Force Is Strong With Which One? | Which One You Sh...
Edureka!
 
OpenPOWER Workshop in Silicon Valley
Ganesan Narayanasamy
 
python_libraries_for_artificial_intelligence.pptx
salehaalsaleh602
 
Machine Learning Toolssssssssssssss.pptx
salehaalsaleh602
 
Torch: a scientific computing framework for machine-learning practitioners
Hoffman Lab
 
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
Kendall
 
PyTorch crash course
Nader Karimi
 
PyTorch for Deep Learning Practitioners
Bayu Aldi Yansyah
 
Neural Networks from Scratch - TensorFlow 101
Gerold Bausch
 
Introduction To TensorFlow | Deep Learning with TensorFlow | TensorFlow For B...
Edureka!
 
01_pytorch_workflow jutedssd huge hhgggdf
stuartkyeswa4
 
Scaling Up AI Research to Production with PyTorch and MLFlow
Databricks
 
Ad

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
PDF
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
PDF
Tableau Tutorial for Data Science | Edureka
Edureka!
 
PDF
Python Programming Tutorial | Edureka
Edureka!
 
PDF
Top 5 PMP Certifications | Edureka
Edureka!
 
PDF
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
PDF
Linux Mint Tutorial | Edureka
Edureka!
 
PDF
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
PDF
Importance of Digital Marketing | Edureka
Edureka!
 
PDF
RPA in 2020 | Edureka
Edureka!
 
PDF
Email Notifications in Jenkins | Edureka
Edureka!
 
PDF
EA Algorithm in Machine Learning | Edureka
Edureka!
 
PDF
Cognitive AI Tutorial | Edureka
Edureka!
 
PDF
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
PDF
Blue Prism Top Interview Questions | Edureka
Edureka!
 
PDF
Big Data on AWS Tutorial | Edureka
Edureka!
 
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
PDF
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
PDF
Introduction to DevOps | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Edureka!
 
Ad

Recently uploaded (20)

PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PPTX
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
PDF
Open Source Milvus Vector Database v 2.6
Zilliz
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PDF
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Practical Applications of AI in Local Government
OnBoard
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Open Source Milvus Vector Database v 2.6
Zilliz
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 

PyTorch Python Tutorial | Deep Learning Using PyTorch | Image Classifier Using PyTorch | Edureka

  • 2. Agenda What is Deep Learning? What is PyTorch? Creating a Neural Network PyTorch v/s TensorFlow Use-Case of PyTorch Summary
  • 3. Copyright © 2017, edureka and/or its affiliates. All rights reserved. What is Deep Learning? We will begin by looking at what led to formation of Deep Learning.
  • 4. AI, Machine Learning and Deep Learning
  • 5. What is Deep Learning? Input Layer Hidden Layer 1 Hidden Layer 2 Output Layer A collection of statistical machine learning techniques used to learn feature hierarchies often based on artificial neural networks
  • 6. AI & Deep Learning Training www.edureka.co Programming languages for Neural Networks Multiple languages allow support for working with Neural Networks! Copyright © 2018, edureka and/or its affiliates. All rights reserved.
  • 7. AI & Deep Learning Training www.edureka.co Maximised support! LisP
  • 8. AI & Deep Learning Training www.edureka.co Python for Deep Learning Let’s focus on the libraries Python has to offer! Copyright © 2018, edureka and/or its affiliates. All rights reserved.
  • 9. AI & Deep Learning Training www.edureka.co Python Libraries 4 Python Deep Learning libraries we’ve found to be the most useful and popular!
  • 10. AI & Deep Learning Training www.edureka.co Python Libraries 4 Python Deep Learning libraries we’ve found to be the most useful and popular!
  • 11. AI & Deep Learning Training www.edureka.co What is PyTorch? The new kid in the block! Copyright © 2018, edureka and/or its affiliates. All rights reserved.
  • 12. AI & Deep Learning Training www.edureka.co PyTorch – An Introduction Dynamic Computation Graphs Python Support Easy to Use API Actively used Fast and Feels Native Support for CUDA PyTorch is a Python based scientific computing package
  • 13. AI & Deep Learning Training www.edureka.co PyTorch - Origin • PyTorch is a cousin of lua-based Torch framework. • PyTorch is not a simple set of wrappers to support popular language.
  • 14. AI & Deep Learning Training www.edureka.co PyTorch Installation Let’s up open up PyCharm and see how to install PyTorch! Copyright © 2018, edureka and/or its affiliates. All rights reserved.
  • 15. AI & Deep Learning Training www.edureka.co Major PyTorch Concepts An insight into what PyTorch has to offer to the developers! Copyright © 2018, edureka and/or its affiliates. All rights reserved.
  • 16. AI & Deep Learning Training www.edureka.co PyTorch - Concepts Neural Network Layer - Stores State or Learnable Weights Terminologies Tensor Imperative N-Dimensional Array Running on GPU Variable Node in Computational Graph - To store Data and Gradient Module
  • 17. AI & Deep Learning Training www.edureka.co The NumPy Bridge! Breakthrough performance!
  • 18. AI & Deep Learning Training www.edureka.co The NumPy Bridge! • Converting Torch Tensor to NumPy array and vice versa. • Torch Tensor and NumPy array will share underlying memory locations. Torch Tensor NumPy array NumPy PyTorch
  • 19. AI & Deep Learning Training www.edureka.co Autograd Module Saves time by calculating differentiation of parameters at forward pass Automatic Differentiation Replay Backwards Compute Gradients Negative of the slope Calculate the minima of the trace function Records Operations Training Dataset
  • 20. AI & Deep Learning Training www.edureka.co Autograd Module torch.Tensor Central Class of Package .requires_grad as True Track all Operations Attribute After computation Call .backward() Gradients Computed Stored in .grad Attribute Stop Tracking History Call .detach() torch.no_grad()
  • 21. AI & Deep Learning Training www.edureka.co Creating a Neural Network An insight into how a Neural Network can be created and used Copyright © 2018, edureka and/or its affiliates. All rights reserved.
  • 22. AI & Deep Learning Training www.edureka.co Creating a Neural Network Simple Feed-Forward Network Neural Networks torch.nn package using Autograd Define models and differentiate them Layers Methods Forward(input) Returns output nn.Module Start Construct
  • 23. AI & Deep Learning Training www.edureka.co Training Algorithm Inputs Calculate Loss Back Propagation Update Parameters train_batch labels_batch output_batch PyTorch Variables Derivatives calculated automatically
  • 24. AI & Deep Learning Training www.edureka.co Creating a Neural Network Training procedure for a Neural Network is as follows: Define the Neural Network Iterate over Dataset Process the Input Compute the Loss Propagate Gradients Back Update the weights weight = weight - learning_rate * gradient
  • 25. AI & Deep Learning Training www.edureka.co Creating a Neural Network Torch.Tensor nn.Module nn.Parameter Autograd.Function Multi-dimensional array with support for autograd operations like backward() Neural Network module for encapsulating parameters to move them to GPU Tensor which is registered as parameter when assigned as attribute to Module Implements forward and backward definitions of an autograd operation
  • 26. AI & Deep Learning Training www.edureka.co Creating a Neural Network At this point, we covered: • Defining a Neural Network • Processing Inputs and Calling Backwards • Computing the Loss • Updating the Weights of the Network
  • 27. AI & Deep Learning Training www.edureka.co PyTorch v/s TensorFlow An insight comparing both of the frameworks Copyright © 2018, edureka and/or its affiliates. All rights reserved.
  • 28. AI & Deep Learning Training www.edureka.co Comparison – An overview Dynamic Computational Graphs Static Computational Graphs Can make use of Standard Python Flow Control Cannot make use of Standard Python Flow Control Support for Python Debuggers Cannot use native Python Debuggers Dynamic Inspection of Variables and Gradients Cannot inspect Variables and Gradients Dynamically Research Production
  • 29. AI & Deep Learning Training www.edureka.co PyTorch – Use Case Let’s look at the working and generation of an image classifier. Copyright © 2018, edureka and/or its affiliates. All rights reserved.
  • 30. AI & Deep Learning Training www.edureka.co Problem Statement Generating an Image Classifier which predicts data based on an Image-Set by constructing a Neural Network which is used by companies like Google to create Image-to-Text Applications such as Translation etc. Using this we optimise accuracy of data obtained!
  • 31. AI & Deep Learning Training www.edureka.co Dataset What about data? Standard Python Packages can be used to load data into numpy array. Then can be converted into a torch.*Tensor. torchvision package helps to avoid writing boilerplate code Image • Pillow • OpenCV Audio • Scipy • Librosa Text • SpaCy • Cython
  • 32. AI & Deep Learning Training www.edureka.co CIFAR10 • Let’s use the CIFAR10 dataset. • The images in CIFAR-10 are of size 3x32x32, i.e. 3-channel colour images of 32x32 pixels in size.
  • 33. AI & Deep Learning Training www.edureka.co Flow Diagram Start Load the Dataset Read the Dataset Normalize test Dataset using torchvision Define Convolution Neural Network (CNN) Define Loss Function Train the Network Test the Network Based on Trained Data End Repeat the process to Decrease the Loss Pre-processing of dataset Make Prediction on the Test Data
  • 34. AI & Deep Learning Training www.edureka.co Training an Image Classifier We will do the following steps in order: Load and Normalize CIFAR10 using torchvision Define Convolution Neural Network Define Loss Function Train the Network on Training Data Test the Network on Test Data Update the weights weight = weight - learning_rate * gradient
  • 35. AI & Deep Learning Training www.edureka.co Step 1: Loading and Normalizing CIFAR10 Using torchvision, it’s extremely easy to load CIFAR10! Load and Normalize CIFAR10 Define CNN Define Loss Function Train the Network Test the Network Update the weights Load Data Normalize Data Convert into Tables Inputs
  • 36. AI & Deep Learning Training www.edureka.co Step 2: Define a Convolution Neural Network 3-Channel Images Red Green Blue Load and Normalize CIFAR10 Define CNN Define Loss Function Train the Network Test the Network Update the weights
  • 37. AI & Deep Learning Training www.edureka.co Step 3: Define a Loss Function and Optimizer Classification Cross-Entropy Loss Load and Normalize CIFAR10 Define CNN Define Loss Function Train the Network Test the Network Update the weights
  • 38. AI & Deep Learning Training www.edureka.co Step 4: Train the Network Loop over Data Iterator Feed the Inputs Optimize Training Load and Normalize CIFAR10 Define CNN Define Loss Function Train the Network Test the Network Update the weights
  • 39. AI & Deep Learning Training www.edureka.co Step 5: Test the Network on Test Data Check for Changes in Model Predict Output Class Label Check against ground-truth Add sample to Correct Predictions Correct Incorrect Load and Normalize CIFAR10 Define CNN Define Loss Function Train the Network Test the Network Update the weights
  • 40. AI & Deep Learning Training www.edureka.co Results • The results seem pretty good. Network did learn something! • Let us look at how the network performs on the whole dataset.
  • 41. AI & Deep Learning Training www.edureka.co Session In A Minute What is Deep Learning? Programming Languages Deep Learning Libraries PyTorch PyTorch v/s TensorFlow Use-Case Implementation
  • 42. Copyright © 2018, edureka and/or its affiliates. All rights reserved.