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
PPTX
bonding to enamel & dentin
PPTX
Introduction to PyTorch
PPTX
Unit 1 - Statistics (Part 1).pptx
PDF
Programmable logic controller - Siemens S7-1200
PPTX
Galileo - The European GNSS
PPT
waves and tides
PPT
CUDA Architecture
PyTorch Introduction
bonding to enamel & dentin
Introduction to PyTorch
Unit 1 - Statistics (Part 1).pptx
Programmable logic controller - Siemens S7-1200
Galileo - The European GNSS
waves and tides
CUDA Architecture

What's hot (20)

PDF
Introduction to Neural Networks
PPTX
Deep neural networks
PPTX
Pytorch
PPTX
Artificial Neural Network | Deep Neural Network Explained | Artificial Neural...
PPTX
Neural network
PDF
Deep learning - A Visual Introduction
PDF
Introduction to TensorFlow 2.0
PPTX
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
PPTX
Intro to deep learning
PPTX
Recurrent Neural Networks (RNNs)
PPTX
Introduction to CNN
PPTX
Introduction to Deep Learning
PDF
Convolutional Neural Networks : Popular Architectures
PPTX
Convolutional Neural Network and Its Applications
PPTX
Convolution Neural Network (CNN)
PPTX
Introduction to Deep learning
PPTX
Machine Learning - Convolutional Neural Network
PDF
Intro to Neural Networks
Introduction to Neural Networks
Deep neural networks
Pytorch
Artificial Neural Network | Deep Neural Network Explained | Artificial Neural...
Neural network
Deep learning - A Visual Introduction
Introduction to TensorFlow 2.0
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
Intro to deep learning
Recurrent Neural Networks (RNNs)
Introduction to CNN
Introduction to Deep Learning
Convolutional Neural Networks : Popular Architectures
Convolutional Neural Network and Its Applications
Convolution Neural Network (CNN)
Introduction to Deep learning
Machine Learning - Convolutional Neural Network
Intro to Neural Networks
Ad

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

PDF
PyTorch Deep Learning Framework | USDSI®
PDF
Top 8 Deep Learning Frameworks | Which Deep Learning Framework You Should Lea...
PDF
IRJET- Python Libraries and Packages for Deep Learning-A Survey
PDF
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
PDF
Pytorch A Detailed Overview Agladze Mikhail
PDF
“Quantum” Performance Effects: beyond the Core
PDF
Synthetic dialogue generation with Deep Learning
 
PPT
Enabling a hardware accelerated deep learning data science experience for Apa...
PPTX
B4UConference_machine learning_deeplearning
PDF
Best Data Science Deep Learning In Python in Bangalore
PDF
Kubernetes and AI - Beauty and the Beast - Tobias Schneck - DOAG 24 NUE - 20....
PDF
Containers & AI - Beauty and the Beast !?! @MLCon - 27.6.2024
PDF
Dog Breed Classification using PyTorch on Azure Machine Learning
PDF
OpenPOWER Workshop in Silicon Valley
PDF
Running Emerging AI Applications on Big Data Platforms with Ray On Apache Spark
PDF
Containers & AI - Beauty and the Beast!?!
PPTX
Data Science With Python | Python For Data Science | Python Data Science Cour...
PDF
Python Interview Questions And Answers 2019 | Edureka
PDF
Deep learning for FinTech
PPTX
Deep Learning Frameworks 2019 | Which Deep Learning Framework To Use | Deep L...
PyTorch Deep Learning Framework | USDSI®
Top 8 Deep Learning Frameworks | Which Deep Learning Framework You Should Lea...
IRJET- Python Libraries and Packages for Deep Learning-A Survey
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
Pytorch A Detailed Overview Agladze Mikhail
“Quantum” Performance Effects: beyond the Core
Synthetic dialogue generation with Deep Learning
 
Enabling a hardware accelerated deep learning data science experience for Apa...
B4UConference_machine learning_deeplearning
Best Data Science Deep Learning In Python in Bangalore
Kubernetes and AI - Beauty and the Beast - Tobias Schneck - DOAG 24 NUE - 20....
Containers & AI - Beauty and the Beast !?! @MLCon - 27.6.2024
Dog Breed Classification using PyTorch on Azure Machine Learning
OpenPOWER Workshop in Silicon Valley
Running Emerging AI Applications on Big Data Platforms with Ray On Apache Spark
Containers & AI - Beauty and the Beast!?!
Data Science With Python | Python For Data Science | Python Data Science Cour...
Python Interview Questions And Answers 2019 | Edureka
Deep learning for FinTech
Deep Learning Frameworks 2019 | Which Deep Learning Framework To Use | Deep L...
Ad

More from Edureka! (20)

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

Recently uploaded (20)

PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
DP Operators-handbook-extract for the Mautical Institute
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
Architecture types and enterprise applications.pdf
PPTX
The various Industrial Revolutions .pptx
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
August Patch Tuesday
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PPTX
observCloud-Native Containerability and monitoring.pptx
Getting started with AI Agents and Multi-Agent Systems
Hindi spoken digit analysis for native and non-native speakers
Enhancing emotion recognition model for a student engagement use case through...
A novel scalable deep ensemble learning framework for big data classification...
Chapter 5: Probability Theory and Statistics
O2C Customer Invoices to Receipt V15A.pptx
DP Operators-handbook-extract for the Mautical Institute
Module 1.ppt Iot fundamentals and Architecture
Architecture types and enterprise applications.pdf
The various Industrial Revolutions .pptx
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
Developing a website for English-speaking practice to English as a foreign la...
A contest of sentiment analysis: k-nearest neighbor versus neural network
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
August Patch Tuesday
TLE Review Electricity (Electricity).pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Web App vs Mobile App What Should You Build First.pdf
observCloud-Native Containerability and monitoring.pptx

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.