SlideShare a Scribd company logo
1 of 26
Wednesday
10 November 2021
Rebeen Ali Hamad
What is PyTorch?
• PyTorch is an open source machine learning library that specializes in tensor
computations, automatic differentiation, and GPU acceleration. For those
reasons, PyTorch is one of the most popular deep learning libraries.
• PyTorch tends to be especially popular among the research community due to its
Pythonic nature and ease of extendability (i.e., implementing custom layer types,
network architectures, etc.).
Some important properties of PyTorch are:
• There’s a large and vibrant community at PyTorch.org community with excellent
documentation and tutorials. The forums are active and supportive.
• It’s written in Python and integrated with popular Python libraries like numpy
• It supports CPU, GPU
• Easy to debug using Pythons IDE and debugging tools.
• It supports cloud platforms
Getting Started with PyTorch
Via Anaconda
conda install -c pytorch pytorch
conda install -c anaconda pytorch-gpu
Via pip:
pip3 install torch
PyTorch Packages
PyTorch Basics: two level of abstraction
Tensor :
Tensors are similar to NumPy’s ndarrays, with the addition being that Tensors can also be
used on a GPU to accelerate computing. Common operations for creation and manipulation
of these Tensors are similar to those for ndarrays in NumPy. (rand, ones, zeros, indexing,
slicing, reshape, transpose, cross product, matrix product, element wise multiplication)
Module:
Base class for all neural network modules, a nueral network layer, may store all state or
learnable weights
Tensor Basics
If you have a one-element tensor, for
example by aggregating all values of a
tensor into one value, you can convert it to
a Python numerical value using item():
Tensor Basics
Tensor Basics
Squeeze only works if the size of a given
dimension is 1.
*If you want to remove a dimension of size > 1
then you need to use a function to do that
reduction like sum or max or mean.
Concatenation , Stack
if A and B are of shape (3, 4),
torch.cat([A, B], dim=0) will be of shape
(6, 4) and torch.stack([A, B], dim=0) will
be of shape (2, 3, 4)
Tensor Basics
Unsequeez
Returns a new tensor with a dimension of size one inserted at the specified position. [...]
torch.unsqueeze adds an additional dimension to the tensor. So let's say you have a tensor of shape (3), if
you add a dimension at the 0 position, it will be of shape (1,3), which means 1 row and 3 columns: If you
have a 2D tensor of shape (2,2) add add an extra dimension at the 0 position, this will result of the tensor
having a shape of (1,2,2), which means one channel, 2 rows and 2 columns. If you add at the 1 position, it
will be of shape (2,1,2), so it will have 2 channels, 1 row and 2 columns.
Tensor Basics
sequeez and unsequeez
Tensor Basics In-place operations
This store the result into the operand are called in-
place. They are denoted by a _ suffix. For example:
x.copy_(y), x.t_(), will change x
Numpy to Torch Bridge
Automatic differentiation package
Autograd is a PyTorch package for the differentiation for all
operations on Tensors. It performs
the backpropagation starting from a variable. In deep
learning, this variable often holds the value of the cost
function. Backward executes the backward pass
and computes all the backpropagation gradients
automatically.
Which tensors are going to be handled by the backward()
method applied to the loss?
[b,w,y_pred, loss]
-If a tensor in the list is used to compute another tensor, the
latter will also be included in the list.
-Tracking these dependencies is exactly what the dynamic
computation graph is doing
with torch.no_grad(): disabled gradient calculation.
Computational Graphs
• PyTorch uses a
dynamic graph, that
means the computational
graph is built up
dynamically, immediately
after we declare
variables. This graph is
thus rebuilt after each
iteration of training
https://algorithmia.com/blog/exploring-the-deep-learning-framework-pytorch
PyTorch Dataset and DataLoader
Dataset and DataLoader classes available in PyTorch for easy batching of training examples. The Dataset stores all your data,
and Dataloader is used to iterate through the data, manage batches, transform the data
__init__ This function is called when instantiating the object.
It's typically used to store some essential location like
file-paths and image transforms.
__len__ : This function returns the length of the dataset.
__getitem__ :This function is responsible for returning a sample
from the dataset based on the index provided.
PyTorch Dataset and DataLoader
The Dataset retrieves our dataset’s features and labels on
e sample at a time. While training a model, we typically w
ant to pass samples in 'minibatches', reshuffle the data at
every epoch to reduce model overfitting, and use Python’
s multiprocessing to speed up data retrieval.
DataLoader is an iterable that abstracts this complexity fo
r us in an easy API
from torch.utils.data import DataLoader
training_dataloader =DataLoader(training_dataset,
batch_size=32, shuffle=True)
Training a Model in PyTorch
Module in PyTorch
Module in PyTorch
Training a Model in PyTorch
Training a Model in PyTorch
In PyTorch, for every mini-batch during the training phase, we
typically want to explicitly set the gradients to zero before
starting to do backpropragation (i.e., updating
the Weights and biases) because PyTorch accumulates the
gradients on subsequent backward passes
The accumulation (i.e., sum) of gradients happens
when .backward() is called on the loss tensor
Module in PyTorch
Torchvision
References
• https://pytorch.org/assets/deep-learning/Deep-Learning-with-
PyTorch.pdf

More Related Content

Similar to Pytroch-basic.pptx

Mapreduce Algorithms
Mapreduce AlgorithmsMapreduce Algorithms
Mapreduce AlgorithmsAmund Tveit
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonRalf Gommers
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonCP-Union
 
PythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdfPythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdfdata2businessinsight
 
Machine learning Experiments report
Machine learning Experiments report Machine learning Experiments report
Machine learning Experiments report AlmkdadAli
 
Introduction to Chainer
Introduction to ChainerIntroduction to Chainer
Introduction to ChainerSeiya Tokui
 
Interview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdfInterview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdfExaminationSectionMR
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxSandeep Singh
 
Python for Data Analysis.pdf
Python for Data Analysis.pdfPython for Data Analysis.pdf
Python for Data Analysis.pdfJulioRecaldeLara1
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxtangadhurai
 
Python-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfPython-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfssuser598883
 
Lec16-CS110 Computational Engineering
Lec16-CS110 Computational EngineeringLec16-CS110 Computational Engineering
Lec16-CS110 Computational EngineeringSri Harsha Pamu
 
Python Libraries and Modules
Python Libraries and ModulesPython Libraries and Modules
Python Libraries and ModulesRaginiJain21
 
PyTorch Tutorial for NTU Machine Learing Course 2017
PyTorch Tutorial for NTU Machine Learing Course 2017PyTorch Tutorial for NTU Machine Learing Course 2017
PyTorch Tutorial for NTU Machine Learing Course 2017Yu-Hsun (lymanblue) Lin
 

Similar to Pytroch-basic.pptx (20)

Mapreduce Algorithms
Mapreduce AlgorithmsMapreduce Algorithms
Mapreduce Algorithms
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for Python
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 
PythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdfPythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdf
 
CPP homework help
CPP homework helpCPP homework help
CPP homework help
 
Python for data analysis
Python for data analysisPython for data analysis
Python for data analysis
 
Machine learning Experiments report
Machine learning Experiments report Machine learning Experiments report
Machine learning Experiments report
 
Introduction to Chainer
Introduction to ChainerIntroduction to Chainer
Introduction to Chainer
 
Interview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdfInterview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdf
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
Python for Data Analysis.pdf
Python for Data Analysis.pdfPython for Data Analysis.pdf
Python for Data Analysis.pdf
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
Python-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfPython-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdf
 
Lec16-CS110 Computational Engineering
Lec16-CS110 Computational EngineeringLec16-CS110 Computational Engineering
Lec16-CS110 Computational Engineering
 
Data Exploration in R.pptx
Data Exploration in R.pptxData Exploration in R.pptx
Data Exploration in R.pptx
 
Python Libraries and Modules
Python Libraries and ModulesPython Libraries and Modules
Python Libraries and Modules
 
PyCon Estonia 2019
PyCon Estonia 2019PyCon Estonia 2019
PyCon Estonia 2019
 
Python ml
Python mlPython ml
Python ml
 
Python for Beginners
Python  for BeginnersPython  for Beginners
Python for Beginners
 
PyTorch Tutorial for NTU Machine Learing Course 2017
PyTorch Tutorial for NTU Machine Learing Course 2017PyTorch Tutorial for NTU Machine Learing Course 2017
PyTorch Tutorial for NTU Machine Learing Course 2017
 

Recently uploaded

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Pytroch-basic.pptx

  • 2. What is PyTorch? • PyTorch is an open source machine learning library that specializes in tensor computations, automatic differentiation, and GPU acceleration. For those reasons, PyTorch is one of the most popular deep learning libraries. • PyTorch tends to be especially popular among the research community due to its Pythonic nature and ease of extendability (i.e., implementing custom layer types, network architectures, etc.).
  • 3. Some important properties of PyTorch are: • There’s a large and vibrant community at PyTorch.org community with excellent documentation and tutorials. The forums are active and supportive. • It’s written in Python and integrated with popular Python libraries like numpy • It supports CPU, GPU • Easy to debug using Pythons IDE and debugging tools. • It supports cloud platforms
  • 4. Getting Started with PyTorch Via Anaconda conda install -c pytorch pytorch conda install -c anaconda pytorch-gpu Via pip: pip3 install torch
  • 6. PyTorch Basics: two level of abstraction Tensor : Tensors are similar to NumPy’s ndarrays, with the addition being that Tensors can also be used on a GPU to accelerate computing. Common operations for creation and manipulation of these Tensors are similar to those for ndarrays in NumPy. (rand, ones, zeros, indexing, slicing, reshape, transpose, cross product, matrix product, element wise multiplication) Module: Base class for all neural network modules, a nueral network layer, may store all state or learnable weights
  • 7. Tensor Basics If you have a one-element tensor, for example by aggregating all values of a tensor into one value, you can convert it to a Python numerical value using item():
  • 9. Tensor Basics Squeeze only works if the size of a given dimension is 1. *If you want to remove a dimension of size > 1 then you need to use a function to do that reduction like sum or max or mean. Concatenation , Stack if A and B are of shape (3, 4), torch.cat([A, B], dim=0) will be of shape (6, 4) and torch.stack([A, B], dim=0) will be of shape (2, 3, 4)
  • 10. Tensor Basics Unsequeez Returns a new tensor with a dimension of size one inserted at the specified position. [...] torch.unsqueeze adds an additional dimension to the tensor. So let's say you have a tensor of shape (3), if you add a dimension at the 0 position, it will be of shape (1,3), which means 1 row and 3 columns: If you have a 2D tensor of shape (2,2) add add an extra dimension at the 0 position, this will result of the tensor having a shape of (1,2,2), which means one channel, 2 rows and 2 columns. If you add at the 1 position, it will be of shape (2,1,2), so it will have 2 channels, 1 row and 2 columns.
  • 12. Tensor Basics In-place operations This store the result into the operand are called in- place. They are denoted by a _ suffix. For example: x.copy_(y), x.t_(), will change x
  • 13. Numpy to Torch Bridge
  • 14. Automatic differentiation package Autograd is a PyTorch package for the differentiation for all operations on Tensors. It performs the backpropagation starting from a variable. In deep learning, this variable often holds the value of the cost function. Backward executes the backward pass and computes all the backpropagation gradients automatically. Which tensors are going to be handled by the backward() method applied to the loss? [b,w,y_pred, loss] -If a tensor in the list is used to compute another tensor, the latter will also be included in the list. -Tracking these dependencies is exactly what the dynamic computation graph is doing with torch.no_grad(): disabled gradient calculation.
  • 15. Computational Graphs • PyTorch uses a dynamic graph, that means the computational graph is built up dynamically, immediately after we declare variables. This graph is thus rebuilt after each iteration of training https://algorithmia.com/blog/exploring-the-deep-learning-framework-pytorch
  • 16. PyTorch Dataset and DataLoader Dataset and DataLoader classes available in PyTorch for easy batching of training examples. The Dataset stores all your data, and Dataloader is used to iterate through the data, manage batches, transform the data __init__ This function is called when instantiating the object. It's typically used to store some essential location like file-paths and image transforms. __len__ : This function returns the length of the dataset. __getitem__ :This function is responsible for returning a sample from the dataset based on the index provided.
  • 17. PyTorch Dataset and DataLoader The Dataset retrieves our dataset’s features and labels on e sample at a time. While training a model, we typically w ant to pass samples in 'minibatches', reshuffle the data at every epoch to reduce model overfitting, and use Python’ s multiprocessing to speed up data retrieval. DataLoader is an iterable that abstracts this complexity fo r us in an easy API from torch.utils.data import DataLoader training_dataloader =DataLoader(training_dataset, batch_size=32, shuffle=True)
  • 18. Training a Model in PyTorch
  • 21. Training a Model in PyTorch
  • 22. Training a Model in PyTorch In PyTorch, for every mini-batch during the training phase, we typically want to explicitly set the gradients to zero before starting to do backpropragation (i.e., updating the Weights and biases) because PyTorch accumulates the gradients on subsequent backward passes The accumulation (i.e., sum) of gradients happens when .backward() is called on the loss tensor
  • 24.