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

PDF
PyTorch Introduction
Yash Kawdiya
 
PDF
GAN in medical imaging
Cheng-Bin Jin
 
PDF
Elliptic curve cryptography
Cysinfo Cyber Security Community
 
PDF
Adhesion and Dentin Bonding agent
ameerprin99
 
PDF
IoT material revised edition
pavan penugonda
 
PPTX
Cuda
Amy Devadas
 
PDF
IoT and m2m
pavan penugonda
 
PPTX
Python Seaborn Data Visualization
Sourabh Sahu
 
PyTorch Introduction
Yash Kawdiya
 
GAN in medical imaging
Cheng-Bin Jin
 
Elliptic curve cryptography
Cysinfo Cyber Security Community
 
Adhesion and Dentin Bonding agent
ameerprin99
 
IoT material revised edition
pavan penugonda
 
Cuda
Amy Devadas
 
IoT and m2m
pavan penugonda
 
Python Seaborn Data Visualization
Sourabh Sahu
 

What's hot (20)

PPTX
Pytorch
ehsan tr
 
PDF
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
Edge AI and Vision Alliance
 
PPTX
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
Simplilearn
 
PDF
Introduction to TensorFlow 2.0
Databricks
 
PDF
Introduction to Deep Learning, Keras, and TensorFlow
Sri Ambati
 
PPTX
CNN Tutorial
Sungjoon Choi
 
PPTX
Convolutional Neural Network - CNN | How CNN Works | Deep Learning Course | S...
Simplilearn
 
PDF
Autoencoder
HARISH R
 
PDF
Convolutional Neural Networks (CNN)
Gaurav Mittal
 
PPTX
Chapter 05 classes and objects
Praveen M Jigajinni
 
PDF
Introduction to Recurrent Neural Network
Knoldus Inc.
 
PPTX
Introduction to PyTorch
Jun Young Park
 
PDF
Tensorflow presentation
Ahmed rebai
 
PPTX
Convolutional Neural Network (CNN) - image recognition
YUNG-KUEI CHEN
 
PPTX
Deep Learning Tutorial | Deep Learning Tutorial For Beginners | What Is Deep ...
Simplilearn
 
PDF
Keras: Deep Learning Library for Python
Rafi Khan
 
PPTX
Deep Learning - RNN and CNN
Pradnya Saval
 
PPTX
Convolutional neural network
MojammilHusain
 
PPTX
Convolutional Neural Network and Its Applications
Kasun Chinthaka Piyarathna
 
Pytorch
ehsan tr
 
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
Edge AI and Vision Alliance
 
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
Simplilearn
 
Introduction to TensorFlow 2.0
Databricks
 
Introduction to Deep Learning, Keras, and TensorFlow
Sri Ambati
 
CNN Tutorial
Sungjoon Choi
 
Convolutional Neural Network - CNN | How CNN Works | Deep Learning Course | S...
Simplilearn
 
Autoencoder
HARISH R
 
Convolutional Neural Networks (CNN)
Gaurav Mittal
 
Chapter 05 classes and objects
Praveen M Jigajinni
 
Introduction to Recurrent Neural Network
Knoldus Inc.
 
Introduction to PyTorch
Jun Young Park
 
Tensorflow presentation
Ahmed rebai
 
Convolutional Neural Network (CNN) - image recognition
YUNG-KUEI CHEN
 
Deep Learning Tutorial | Deep Learning Tutorial For Beginners | What Is Deep ...
Simplilearn
 
Keras: Deep Learning Library for Python
Rafi Khan
 
Deep Learning - RNN and CNN
Pradnya Saval
 
Convolutional neural network
MojammilHusain
 
Convolutional Neural Network and Its Applications
Kasun Chinthaka Piyarathna
 
Ad

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

PDF
PyTorch Deep Learning Framework | USDSIÂź
USDSI
 
PDF
Top 8 Deep Learning Frameworks | Which Deep Learning Framework You Should Lea...
Edureka!
 
PDF
IRJET- Python Libraries and Packages for Deep Learning-A Survey
IRJET Journal
 
PDF
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
Stijn Decubber
 
PDF
Pytorch A Detailed Overview Agladze Mikhail
ilzobrzan47
 
PDF
“Quantum” Performance Effects: beyond the Core
C4Media
 
PDF
Synthetic dialogue generation with Deep Learning
S N
 
PPT
Enabling a hardware accelerated deep learning data science experience for Apa...
DataWorks Summit
 
PPTX
B4UConference_machine learning_deeplearning
Hoa Le
 
PDF
Best Data Science Deep Learning In Python in Bangalore
myTectra Learning Solutions Private Ltd
 
PDF
Kubernetes and AI - Beauty and the Beast - Tobias Schneck - DOAG 24 NUE - 20....
Tobias Schneck
 
PDF
Containers & AI - Beauty and the Beast !?! @MLCon - 27.6.2024
Tobias Schneck
 
PDF
Dog Breed Classification using PyTorch on Azure Machine Learning
Heather Spetalnick
 
PDF
OpenPOWER Workshop in Silicon Valley
Ganesan Narayanasamy
 
PDF
Running Emerging AI Applications on Big Data Platforms with Ray On Apache Spark
Databricks
 
PDF
Containers & AI - Beauty and the Beast!?!
Tobias Schneck
 
PPTX
Data Science With Python | Python For Data Science | Python Data Science Cour...
Simplilearn
 
PDF
Python Interview Questions And Answers 2019 | Edureka
Edureka!
 
PDF
Deep learning for FinTech
geetachauhan
 
PPTX
Deep Learning Frameworks 2019 | Which Deep Learning Framework To Use | Deep L...
Simplilearn
 
PyTorch Deep Learning Framework | USDSIÂź
USDSI
 
Top 8 Deep Learning Frameworks | Which Deep Learning Framework You Should Lea...
Edureka!
 
IRJET- Python Libraries and Packages for Deep Learning-A Survey
IRJET Journal
 
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
Stijn Decubber
 
Pytorch A Detailed Overview Agladze Mikhail
ilzobrzan47
 
“Quantum” Performance Effects: beyond the Core
C4Media
 
Synthetic dialogue generation with Deep Learning
S N
 
Enabling a hardware accelerated deep learning data science experience for Apa...
DataWorks Summit
 
B4UConference_machine learning_deeplearning
Hoa Le
 
Best Data Science Deep Learning In Python in Bangalore
myTectra Learning Solutions Private Ltd
 
Kubernetes and AI - Beauty and the Beast - Tobias Schneck - DOAG 24 NUE - 20....
Tobias Schneck
 
Containers & AI - Beauty and the Beast !?! @MLCon - 27.6.2024
Tobias Schneck
 
Dog Breed Classification using PyTorch on Azure Machine Learning
Heather Spetalnick
 
OpenPOWER Workshop in Silicon Valley
Ganesan Narayanasamy
 
Running Emerging AI Applications on Big Data Platforms with Ray On Apache Spark
Databricks
 
Containers & AI - Beauty and the Beast!?!
Tobias Schneck
 
Data Science With Python | Python For Data Science | Python Data Science Cour...
Simplilearn
 
Python Interview Questions And Answers 2019 | Edureka
Edureka!
 
Deep learning for FinTech
geetachauhan
 
Deep Learning Frameworks 2019 | Which Deep Learning Framework To Use | Deep L...
Simplilearn
 
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!
 

Recently uploaded (20)

PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PPTX
Comunidade Salesforce SĂŁo Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira JĂșnior
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PDF
Orbitly Pitch DeckA Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Software Development Company | KodekX
KodekX
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Comunidade Salesforce SĂŁo Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira JĂșnior
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
Orbitly Pitch DeckA Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Software Development Methodologies in 2025
KodekX
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 

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.