SlideShare a Scribd company logo
43 Tanmay Borase 46 Aryan Kshatriya
44 Yash Kawdiya 47 Rajveersingh Naruka
45 Harshal Kolhe 48 Rugved Salunke
DY PATIL COLLEGE OF ENGINEERING
FIRST YEAR ENGINEERING DEPARTMENT
THE ACADEMIC YEAR 2022-23 SEMESTER 1
Presenters
Subject Teacher : Swati Suryawanshi Mam
PYTORCH
INTRODUCTION
Group 8 | Division H
CONTENT
OVERVIEW
1 / What is PyTorch
2 / Why PyTorch
3 / The PyTorch Explained
4 / The PyTorch Tensors
5 / Creating Tensors in PyTorch
6 / Restructuring Tensors in PyTorch
7 / Mathematical Operations on
Tensors in PyTorch
CONTENT
OVERVIEW
8 / PyTorch Modules
9 / PyTorch Vs TensorFlow
10 / Key Features of Using PyTorch
11 / PyTorch Benefits
12 / Members and Governing Board
13 / PyTorch Use Cases
WHAT IS
PYTORCH
PyTorch is an open-source
deep learning framework that’s
known for its flexibility and
ease-of-use. This is enabled in
part by its compatibility with
the popular Python high-level
programming language
favored by machine learning
developers and data scientists.
WHY PYTORCH
Image reference https://pytorch.org/features/
THE
PYTORCH
EXPLAINED
PyTorch is a fully featured
framework for building deep
learning models, which is a
type of machine learning that’s
commonly used in applications
like image recognition and
language processing.
PYTORCH TENSORS
The Pytorch is used to process the tensors. Tensors are multidimensional
arrays like n-dimensional NumPy array. However, tensors can be used in GPUs
as well, which is not in the case of NumPy array. PyTorch accelerates the
scientific computation of tensors as it has various inbuilt functions.
A vector is a one-dimensional tensor, and a matrix is a two-dimensional tensor.
One significant difference between the Tensor and multidimensional array used
in C, C++, and Java is tensors should have the same size of columns in all
dimensions. Also, the tensors can contain only numeric data types.
1.0 4.0 7.0
2.0 5.0 8.0
3.0 6.0 9.0
1.0
2.0
3.0
VECTOR
1
D
TENSOR
MATRIX
2
D
TENSOR
Code Output
The two fundamental attributes of a tensor are:
Shape refers to the dimensionality of array or matrix
Rank refers to the number of dimensions present in tensor
# importing torch
import torch
# creating a tensors
t1=torch.tensor([1, 2, 3, 4])
t2=torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
# printing the tensors:
print("Tensor t1: n", t1)
print("nTensor t2: n", t2)
# rank of tensors
print("nRank of t1: ", len(t1.shape))
print("Rank of t2: ", len(t2.shape))
# shape of tensors
print("nRank of t1: ", t1.shape)
print("Rank of t2: ", t2.shape)
Tensor t1:
tensor ([1, 2, 3, 4])
Tensor t2:
tensor([[1, 2, 3, 4], [5,6,7,8], [9,10,11,12]])
Rank of t1: 1
Rank of t2: 2
Rank of t1: torch.Size([4])
Rank of t2: torch.Size([3,4])
CREATING TENSOR IN PYTORCH
There are various methods to create a tensor in PyTorch. A tensor can
contain elements of a single data type. We can create a tensor using a
python list or NumPy array. The torch has 10 variants of tensors for
both GPU and CPU. Below are different ways of defining a tensor.
torch.Tensor()
It copies the data and creates its tensor. It is an alias for
torch.FloatTensor.
torch.tensor()
It also copies the data to create a tensor; however, it infers the data type
automatically.
torch.as_tensor()
The data is shared and not copied in this case while creating the data and
accepts any type of array for tensor creation.
torch.from_numpy()
It is similar to tensor.as_tensor() however it accepts only numpy array.
Code Output
# importing torch module
import torch
import numpy as np
# list of values to be stored as tensor
data1 = [1, 2, 3, 4, 5, 6]
data2 = np.array([1.5, 3.4, 6.8, 9.3, 7.0, 2.8])
# creating tensors and printing
t1 = torch.tensor(data1)
t2 = torch.Tensor(data1)
t3 = torch.as_tensor(data2)
t4 = torch.from_numpy(data2)
print("Tensor: ",t1, "Data type: ", t1.dtype,"n")
print("Tensor: ",t2, "Data type: ", t2.dtype,"n")
print("Tensor: ",t3, "Data type: ", t3.dtype,"n")
print("Tensor: ",t4, "Data type: ", t4.dtype,"n")
Tensor: tensor ([1, 2, 3, 4, 5, 6])
Data type: torch.int64
Tensor: tensor ([1., 2., 3., 4., 5., 6.])
Data type: torch.float32
Tensor: tensor([1.5000, 3.4000, 6.8000, 9.3000,
7.0000, 2.80e0], dtype=torch.float64)
Data type: torch. float64
Tensor: tensor ([1.5000, 3.4000, 6.8000, 9.3000,
7.0000, 2.800e], dtype=torch.float64)
Data type: torch. float64
RESTRUCTURING TENSORS IN PYTORCH
We can modify the shape and size of a tensor as desired in
PyTorch. We can also create a transpose of an n-d tensor.
Below are three common ways to change the structure of
your tensor as desired:
.reshape(a, b)
returns a new tensor with size a,b
.resize(a, b)
returns the same tensor with the size a,b
.transpose(a, b)
returns a tensor transposed in a and b dimension
1 4
2 5
3 6
1 2 3
4 5 6
1 2
3 4
5 6
Reshape
Transpose
Original
Reshape and Transpose Difference
A 2*3 matrix has been reshaped and transposed to 3*2. We can visualize the
change in the arrangement of the elements in the tensor in both cases.
Code Output
# import torch module
import torch
# defining tensor
t = torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
# reshaping the tensor
print("Reshaping")
print(t.reshape(6, 2))
# resizing the tensor
print("nResizing")
print(t.resize(2, 6))
# transposing the tensor
print("nTransposing")
print(t.transpose(1, 0))
Reshaping
tensor([[ 1, 2], [ 3, 4], [ 5, 6], [ 7, 8], [ 9, 10], [11, 12]])
Resizing
tensor ([[ 1, 2, 3, 4, 5, 6], [ 7, 8, 9, 10, 11, 12]])
Transposing
tensor([[1, 5, 9], [ 2, 6, 10], [ 3, 7, 11], [ 4, 8, 12]])
MATHEMATICAL OPERATIONS ON
TENSORS USING PYTORCH
We can perform various mathematical operations on tensors using Pytorch. The
code for performing Mathematical operations is the same as in the case with
NumPy arrays. Below is the code for performing the four basic operations in
tensors.
OUTPUT
CODE
# import torch module
import torch
# defining two tensors
t1 = torch.tensor([1, 2, 3, 4])
t2 = torch.tensor([5, 6, 7, 8])
# adding two tensors
print("tensor2 + tensor1")
print(torch.add(t2, t1))
# subtracting two tensor
print("ntensor2 - tensor1")
print(torch.sub(t2, t1))
# multiplying two tensors
print("ntensor2 * tensor1")
print(torch.mul(t2, t1))
# diving two tensors
print("ntensor2 / tensor1")
print(torch.div(t2, t1))
Tensor: tensor ([1, 2, 3, 4, 5, 6])
Data type: torch.int64
Tensor: tensor ([1., 2., 3., 4., 5., 6.])
Data type: torch.float32
Tensor: tensor([1.5000, 3.4000, 6.8000, 9.3000,
7.0000, 2.80e0], dtype=torch.float64)
Data type: torch. float64
Tensor: tensor ([1.5000, 3.4000, 6.8000, 9.3000,
7.0000, 2.800e], dtype=torch.float64)
Data type: torch. float64
PYTORCH MODULES
The PyTorch library modules are essential to create and train neural
networks. The three main library modules are Autograd, Optim, and nn.
# 1. Autograd Module
The autograd provides the functionality of easy calculation of gradients
without the explicitly manual implementation of forward and backward
pass for all layers. For training any neural network we perform
backpropagation to calculate the gradient. By calling the .backward()
function we can calculate every gradient from the root to the leaf.
# 2. Optim Module
PyTorch Optium Module which helps in the implementation of various
optimization algorithms. This package contains the most commonly used
algorithms like Adam, SGD, and RMS-Prop. To use torch.optim we first need
to construct an Optimizer object which will keep the parameters and update
it accordingly. First, we define the Optimizer by providing the optimizer
algorithm we want to use. We set the gradients to zero before
backpropagation. Then for updation of parameters the optimizer.step() is
called.
PYTORCH MODULES
# 3. nn Module
This package helps in the construction of neural networks. It is used to build
layers.
For creating a model with a single layer we can simply define it by using
nn.Sequential().
For the implementation of the model which is not in a single sequence, we
define a model by subclassing the nn.Module class.
PyTorch TensorFlow
PyTorch is closely related to the
lua-based Torch framework which
is actively used in Facebook.
TensorFlow is developed by
Google Brain and actively used at
Google.
PyTorch is relatively new
compared to other competitive
technologies.
TensorFlow is not new and is
considered as a to-go tool by
many researchers and industry
professionals.
PyTorch includes everything in
imperative and dynamic manner.
TensorFlow includes static and
dynamic graphs as a combination.
Computation graph in PyTorch is
defined during runtime.
TensorFlow do not include any
run time option.
PYTORCH VS TENSORFLOW
KEY FEATURES OF USING PYTORCH
TENSOR COMPUTATION TORCHSCRIPT AUTOMATIC
DIFFERENTIATION
Tensors are generic n-
dimensional arrays used for
arbitrary numeric
computation and are
accelerated by graphics
processing units. These
multidimensional structures
can be operated on and
manipulated with application
program interfaces (APIs).
This is the production
environment of
PyTorch that enables
users to seamlessly
transition between
modes. TorchScript
optimizes
functionality, speed,
ease of use and
flexibility.
This technique is used
for creating and
training neural
networks. It
numerically computes
the derivative of a
function by making
backward passes in
neural networks.
KEY FEATURES OF USING PYTORCH
DYNAMIC GRAPH
COMPUTATION
PYTHON SUPPORT
This feature lets users
change network
behavior on the fly,
rather than waiting for
all the code to be
executed.
Because PyTorch is
based on Python, it
can be used with
popular libraries and
packages such as
NumPy, SciPy, Numba
and Cynthon.
PYTORCH
BENIFITS
Offers developers an easy-to-learn,
simple-to-code structure that's based
on Python.
Enables easy debugging with popular
Python tools.
Offers scalability and is well-supported
on major cloud platforms.
Provides a small community focused
on open source.
Exports learning models to the Open
Neural Network Exchange (ONNX)
standard format.
Offers a user-friendly interface.
Provides a C++ front-end interface
option.
Includes a rich set of powerful APIs
that extend the PyTorch library.
MEMBERS AND GOVERNING BOARD
PYTORCH
USE CASES
Natural Language Processing (NLP): From Siri to
Google Translate, deep neural networks have
enabled breakthroughs in machine understanding
of natural language. Most of these models treat
language as a flat sequence of words or characters
and use a kind of model called a recurrent neural
network (RNN) to process this sequence. But
many linguists think that language is best
understood as a hierarchical tree of phrases, so a
significant amount of research has gone into deep
learning models known as recursive neural
networks that take this structure into account.
While these models are notoriously hard to
implement and inefficient to run, PyTorch makes
these and other complex natural language
processing models a lot easier. Salesforce is using
PyTorch for NLP and multi-task learning.
PYTORCH
USE CASES
Research: PyTorch is a popular
choice for research due to its
ease of use, flexibility and
rapid prototyping. Stanford
University is using PyTorch’s
flexibility to efficiently research
new algorithmic approaches.
Education: Udacity is educating
AI innovators using PyTorch.
THANKS FOR
YOUR TIME!

More Related Content

What's hot

Introduction to Deep Learning, Keras, and TensorFlow
Introduction to Deep Learning, Keras, and TensorFlowIntroduction to Deep Learning, Keras, and TensorFlow
Introduction to Deep Learning, Keras, and TensorFlow
Sri Ambati
 
Introduction To TensorFlow
Introduction To TensorFlowIntroduction To TensorFlow
Introduction To TensorFlow
Spotle.ai
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
Girish Khanzode
 
TensorFlow Tutorial | Deep Learning With TensorFlow | TensorFlow Tutorial For...
TensorFlow Tutorial | Deep Learning With TensorFlow | TensorFlow Tutorial For...TensorFlow Tutorial | Deep Learning With TensorFlow | TensorFlow Tutorial For...
TensorFlow Tutorial | Deep Learning With TensorFlow | TensorFlow Tutorial For...
Simplilearn
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
Phoenix
 
Introduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-LearnIntroduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-Learn
Benjamin Bengfort
 
Python pandas Library
Python pandas LibraryPython pandas Library
Python pandas Library
Md. Sohag Miah
 
Deep learning - A Visual Introduction
Deep learning - A Visual IntroductionDeep learning - A Visual Introduction
Deep learning - A Visual Introduction
Lukas Masuch
 
Deep neural networks
Deep neural networksDeep neural networks
Deep neural networks
Si Haem
 
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
Simplilearn
 
Tensorflow
TensorflowTensorflow
Tensorflow
marwa Ayad Mohamed
 
Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in Python
Marc Garcia
 
Cnn
CnnCnn
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
Devashish Kumar
 
Introduction to batch normalization
Introduction to batch normalizationIntroduction to batch normalization
Introduction to batch normalization
Jamie (Taka) Wang
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
Piyush rai
 
Notes from Coursera Deep Learning courses by Andrew Ng
Notes from Coursera Deep Learning courses by Andrew NgNotes from Coursera Deep Learning courses by Andrew Ng
Notes from Coursera Deep Learning courses by Andrew Ng
Tess Ferrandez
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
Edureka!
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Andrew Ferlitsch
 
Naive bayes
Naive bayesNaive bayes
Naive bayes
Ashraf Uddin
 

What's hot (20)

Introduction to Deep Learning, Keras, and TensorFlow
Introduction to Deep Learning, Keras, and TensorFlowIntroduction to Deep Learning, Keras, and TensorFlow
Introduction to Deep Learning, Keras, and TensorFlow
 
Introduction To TensorFlow
Introduction To TensorFlowIntroduction To TensorFlow
Introduction To TensorFlow
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
TensorFlow Tutorial | Deep Learning With TensorFlow | TensorFlow Tutorial For...
TensorFlow Tutorial | Deep Learning With TensorFlow | TensorFlow Tutorial For...TensorFlow Tutorial | Deep Learning With TensorFlow | TensorFlow Tutorial For...
TensorFlow Tutorial | Deep Learning With TensorFlow | TensorFlow Tutorial For...
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
 
Introduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-LearnIntroduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-Learn
 
Python pandas Library
Python pandas LibraryPython pandas Library
Python pandas Library
 
Deep learning - A Visual Introduction
Deep learning - A Visual IntroductionDeep learning - A Visual Introduction
Deep learning - A Visual Introduction
 
Deep neural networks
Deep neural networksDeep neural networks
Deep neural networks
 
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
 
Tensorflow
TensorflowTensorflow
Tensorflow
 
Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in Python
 
Cnn
CnnCnn
Cnn
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
 
Introduction to batch normalization
Introduction to batch normalizationIntroduction to batch normalization
Introduction to batch normalization
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
 
Notes from Coursera Deep Learning courses by Andrew Ng
Notes from Coursera Deep Learning courses by Andrew NgNotes from Coursera Deep Learning courses by Andrew Ng
Notes from Coursera Deep Learning courses by Andrew Ng
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
 
Naive bayes
Naive bayesNaive bayes
Naive bayes
 

Similar to PyTorch Introduction

Introduction To Using TensorFlow & Deep Learning
Introduction To Using TensorFlow & Deep LearningIntroduction To Using TensorFlow & Deep Learning
Introduction To Using TensorFlow & Deep Learning
ali alemi
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
Oswald Campesato
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
Oswald Campesato
 
Language translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlowLanguage translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlow
S N
 
On the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling LanguagesOn the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling Languages
Jose E. Rivera
 
TensorFlow Tutorial.pdf
TensorFlow Tutorial.pdfTensorFlow Tutorial.pdf
TensorFlow Tutorial.pdf
Antonio Espinosa
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
Asst.prof M.Gokilavani
 
Machine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowMachine Learning - Introduction to Tensorflow
Machine Learning - Introduction to Tensorflow
Andrew Ferlitsch
 
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
Databricks
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and Spark
Oswald Campesato
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and Keras
Oswald Campesato
 
reliability workshop
reliability workshopreliability workshop
reliability workshop
Gaurav Dixit
 
Introduction to TensorFlow
Introduction to TensorFlowIntroduction to TensorFlow
Introduction to TensorFlow
Babu Priyavrat
 
Tensorflow basics
Tensorflow basicsTensorflow basics
Tensorflow basics
IshaNemaCSPOcertifie
 
TensorFlow example for AI Ukraine2016
TensorFlow example  for AI Ukraine2016TensorFlow example  for AI Ukraine2016
TensorFlow example for AI Ukraine2016
Andrii Babii
 
Noise Contrastive Estimation-based Matching Framework for Low-Resource Securi...
Noise Contrastive Estimation-based Matching Framework for Low-Resource Securi...Noise Contrastive Estimation-based Matching Framework for Low-Resource Securi...
Noise Contrastive Estimation-based Matching Framework for Low-Resource Securi...
Tu Nguyen
 
Internship project presentation_final_upload
Internship project presentation_final_uploadInternship project presentation_final_upload
Internship project presentation_final_upload
Suraj Rathore
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study material
To Sum It Up
 
Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)
Oswald Campesato
 
PyTorch for Deep Learning Practitioners
PyTorch for Deep Learning PractitionersPyTorch for Deep Learning Practitioners
PyTorch for Deep Learning Practitioners
Bayu Aldi Yansyah
 

Similar to PyTorch Introduction (20)

Introduction To Using TensorFlow & Deep Learning
Introduction To Using TensorFlow & Deep LearningIntroduction To Using TensorFlow & Deep Learning
Introduction To Using TensorFlow & Deep Learning
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
 
Language translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlowLanguage translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlow
 
On the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling LanguagesOn the Semantics of Real-Time Domain Specific Modeling Languages
On the Semantics of Real-Time Domain Specific Modeling Languages
 
TensorFlow Tutorial.pdf
TensorFlow Tutorial.pdfTensorFlow Tutorial.pdf
TensorFlow Tutorial.pdf
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Machine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowMachine Learning - Introduction to Tensorflow
Machine Learning - Introduction to Tensorflow
 
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and Spark
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and Keras
 
reliability workshop
reliability workshopreliability workshop
reliability workshop
 
Introduction to TensorFlow
Introduction to TensorFlowIntroduction to TensorFlow
Introduction to TensorFlow
 
Tensorflow basics
Tensorflow basicsTensorflow basics
Tensorflow basics
 
TensorFlow example for AI Ukraine2016
TensorFlow example  for AI Ukraine2016TensorFlow example  for AI Ukraine2016
TensorFlow example for AI Ukraine2016
 
Noise Contrastive Estimation-based Matching Framework for Low-Resource Securi...
Noise Contrastive Estimation-based Matching Framework for Low-Resource Securi...Noise Contrastive Estimation-based Matching Framework for Low-Resource Securi...
Noise Contrastive Estimation-based Matching Framework for Low-Resource Securi...
 
Internship project presentation_final_upload
Internship project presentation_final_uploadInternship project presentation_final_upload
Internship project presentation_final_upload
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study material
 
Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)
 
PyTorch for Deep Learning Practitioners
PyTorch for Deep Learning PractitionersPyTorch for Deep Learning Practitioners
PyTorch for Deep Learning Practitioners
 

Recently uploaded

Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 

Recently uploaded (20)

Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 

PyTorch Introduction

  • 1. 43 Tanmay Borase 46 Aryan Kshatriya 44 Yash Kawdiya 47 Rajveersingh Naruka 45 Harshal Kolhe 48 Rugved Salunke DY PATIL COLLEGE OF ENGINEERING FIRST YEAR ENGINEERING DEPARTMENT THE ACADEMIC YEAR 2022-23 SEMESTER 1 Presenters Subject Teacher : Swati Suryawanshi Mam
  • 3. CONTENT OVERVIEW 1 / What is PyTorch 2 / Why PyTorch 3 / The PyTorch Explained 4 / The PyTorch Tensors 5 / Creating Tensors in PyTorch 6 / Restructuring Tensors in PyTorch 7 / Mathematical Operations on Tensors in PyTorch
  • 4. CONTENT OVERVIEW 8 / PyTorch Modules 9 / PyTorch Vs TensorFlow 10 / Key Features of Using PyTorch 11 / PyTorch Benefits 12 / Members and Governing Board 13 / PyTorch Use Cases
  • 5. WHAT IS PYTORCH PyTorch is an open-source deep learning framework that’s known for its flexibility and ease-of-use. This is enabled in part by its compatibility with the popular Python high-level programming language favored by machine learning developers and data scientists.
  • 6. WHY PYTORCH Image reference https://pytorch.org/features/
  • 7. THE PYTORCH EXPLAINED PyTorch is a fully featured framework for building deep learning models, which is a type of machine learning that’s commonly used in applications like image recognition and language processing.
  • 8. PYTORCH TENSORS The Pytorch is used to process the tensors. Tensors are multidimensional arrays like n-dimensional NumPy array. However, tensors can be used in GPUs as well, which is not in the case of NumPy array. PyTorch accelerates the scientific computation of tensors as it has various inbuilt functions. A vector is a one-dimensional tensor, and a matrix is a two-dimensional tensor. One significant difference between the Tensor and multidimensional array used in C, C++, and Java is tensors should have the same size of columns in all dimensions. Also, the tensors can contain only numeric data types. 1.0 4.0 7.0 2.0 5.0 8.0 3.0 6.0 9.0 1.0 2.0 3.0 VECTOR 1 D TENSOR MATRIX 2 D TENSOR
  • 9. Code Output The two fundamental attributes of a tensor are: Shape refers to the dimensionality of array or matrix Rank refers to the number of dimensions present in tensor # importing torch import torch # creating a tensors t1=torch.tensor([1, 2, 3, 4]) t2=torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) # printing the tensors: print("Tensor t1: n", t1) print("nTensor t2: n", t2) # rank of tensors print("nRank of t1: ", len(t1.shape)) print("Rank of t2: ", len(t2.shape)) # shape of tensors print("nRank of t1: ", t1.shape) print("Rank of t2: ", t2.shape) Tensor t1: tensor ([1, 2, 3, 4]) Tensor t2: tensor([[1, 2, 3, 4], [5,6,7,8], [9,10,11,12]]) Rank of t1: 1 Rank of t2: 2 Rank of t1: torch.Size([4]) Rank of t2: torch.Size([3,4])
  • 10. CREATING TENSOR IN PYTORCH There are various methods to create a tensor in PyTorch. A tensor can contain elements of a single data type. We can create a tensor using a python list or NumPy array. The torch has 10 variants of tensors for both GPU and CPU. Below are different ways of defining a tensor. torch.Tensor() It copies the data and creates its tensor. It is an alias for torch.FloatTensor. torch.tensor() It also copies the data to create a tensor; however, it infers the data type automatically. torch.as_tensor() The data is shared and not copied in this case while creating the data and accepts any type of array for tensor creation. torch.from_numpy() It is similar to tensor.as_tensor() however it accepts only numpy array.
  • 11. Code Output # importing torch module import torch import numpy as np # list of values to be stored as tensor data1 = [1, 2, 3, 4, 5, 6] data2 = np.array([1.5, 3.4, 6.8, 9.3, 7.0, 2.8]) # creating tensors and printing t1 = torch.tensor(data1) t2 = torch.Tensor(data1) t3 = torch.as_tensor(data2) t4 = torch.from_numpy(data2) print("Tensor: ",t1, "Data type: ", t1.dtype,"n") print("Tensor: ",t2, "Data type: ", t2.dtype,"n") print("Tensor: ",t3, "Data type: ", t3.dtype,"n") print("Tensor: ",t4, "Data type: ", t4.dtype,"n") Tensor: tensor ([1, 2, 3, 4, 5, 6]) Data type: torch.int64 Tensor: tensor ([1., 2., 3., 4., 5., 6.]) Data type: torch.float32 Tensor: tensor([1.5000, 3.4000, 6.8000, 9.3000, 7.0000, 2.80e0], dtype=torch.float64) Data type: torch. float64 Tensor: tensor ([1.5000, 3.4000, 6.8000, 9.3000, 7.0000, 2.800e], dtype=torch.float64) Data type: torch. float64
  • 12. RESTRUCTURING TENSORS IN PYTORCH We can modify the shape and size of a tensor as desired in PyTorch. We can also create a transpose of an n-d tensor. Below are three common ways to change the structure of your tensor as desired: .reshape(a, b) returns a new tensor with size a,b .resize(a, b) returns the same tensor with the size a,b .transpose(a, b) returns a tensor transposed in a and b dimension
  • 13. 1 4 2 5 3 6 1 2 3 4 5 6 1 2 3 4 5 6 Reshape Transpose Original Reshape and Transpose Difference A 2*3 matrix has been reshaped and transposed to 3*2. We can visualize the change in the arrangement of the elements in the tensor in both cases.
  • 14. Code Output # import torch module import torch # defining tensor t = torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) # reshaping the tensor print("Reshaping") print(t.reshape(6, 2)) # resizing the tensor print("nResizing") print(t.resize(2, 6)) # transposing the tensor print("nTransposing") print(t.transpose(1, 0)) Reshaping tensor([[ 1, 2], [ 3, 4], [ 5, 6], [ 7, 8], [ 9, 10], [11, 12]]) Resizing tensor ([[ 1, 2, 3, 4, 5, 6], [ 7, 8, 9, 10, 11, 12]]) Transposing tensor([[1, 5, 9], [ 2, 6, 10], [ 3, 7, 11], [ 4, 8, 12]])
  • 15. MATHEMATICAL OPERATIONS ON TENSORS USING PYTORCH We can perform various mathematical operations on tensors using Pytorch. The code for performing Mathematical operations is the same as in the case with NumPy arrays. Below is the code for performing the four basic operations in tensors. OUTPUT CODE # import torch module import torch # defining two tensors t1 = torch.tensor([1, 2, 3, 4]) t2 = torch.tensor([5, 6, 7, 8]) # adding two tensors print("tensor2 + tensor1") print(torch.add(t2, t1)) # subtracting two tensor print("ntensor2 - tensor1") print(torch.sub(t2, t1)) # multiplying two tensors print("ntensor2 * tensor1") print(torch.mul(t2, t1)) # diving two tensors print("ntensor2 / tensor1") print(torch.div(t2, t1)) Tensor: tensor ([1, 2, 3, 4, 5, 6]) Data type: torch.int64 Tensor: tensor ([1., 2., 3., 4., 5., 6.]) Data type: torch.float32 Tensor: tensor([1.5000, 3.4000, 6.8000, 9.3000, 7.0000, 2.80e0], dtype=torch.float64) Data type: torch. float64 Tensor: tensor ([1.5000, 3.4000, 6.8000, 9.3000, 7.0000, 2.800e], dtype=torch.float64) Data type: torch. float64
  • 16. PYTORCH MODULES The PyTorch library modules are essential to create and train neural networks. The three main library modules are Autograd, Optim, and nn. # 1. Autograd Module The autograd provides the functionality of easy calculation of gradients without the explicitly manual implementation of forward and backward pass for all layers. For training any neural network we perform backpropagation to calculate the gradient. By calling the .backward() function we can calculate every gradient from the root to the leaf. # 2. Optim Module PyTorch Optium Module which helps in the implementation of various optimization algorithms. This package contains the most commonly used algorithms like Adam, SGD, and RMS-Prop. To use torch.optim we first need to construct an Optimizer object which will keep the parameters and update it accordingly. First, we define the Optimizer by providing the optimizer algorithm we want to use. We set the gradients to zero before backpropagation. Then for updation of parameters the optimizer.step() is called.
  • 17. PYTORCH MODULES # 3. nn Module This package helps in the construction of neural networks. It is used to build layers. For creating a model with a single layer we can simply define it by using nn.Sequential(). For the implementation of the model which is not in a single sequence, we define a model by subclassing the nn.Module class.
  • 18. PyTorch TensorFlow PyTorch is closely related to the lua-based Torch framework which is actively used in Facebook. TensorFlow is developed by Google Brain and actively used at Google. PyTorch is relatively new compared to other competitive technologies. TensorFlow is not new and is considered as a to-go tool by many researchers and industry professionals. PyTorch includes everything in imperative and dynamic manner. TensorFlow includes static and dynamic graphs as a combination. Computation graph in PyTorch is defined during runtime. TensorFlow do not include any run time option. PYTORCH VS TENSORFLOW
  • 19. KEY FEATURES OF USING PYTORCH TENSOR COMPUTATION TORCHSCRIPT AUTOMATIC DIFFERENTIATION Tensors are generic n- dimensional arrays used for arbitrary numeric computation and are accelerated by graphics processing units. These multidimensional structures can be operated on and manipulated with application program interfaces (APIs). This is the production environment of PyTorch that enables users to seamlessly transition between modes. TorchScript optimizes functionality, speed, ease of use and flexibility. This technique is used for creating and training neural networks. It numerically computes the derivative of a function by making backward passes in neural networks.
  • 20. KEY FEATURES OF USING PYTORCH DYNAMIC GRAPH COMPUTATION PYTHON SUPPORT This feature lets users change network behavior on the fly, rather than waiting for all the code to be executed. Because PyTorch is based on Python, it can be used with popular libraries and packages such as NumPy, SciPy, Numba and Cynthon.
  • 21. PYTORCH BENIFITS Offers developers an easy-to-learn, simple-to-code structure that's based on Python. Enables easy debugging with popular Python tools. Offers scalability and is well-supported on major cloud platforms. Provides a small community focused on open source. Exports learning models to the Open Neural Network Exchange (ONNX) standard format. Offers a user-friendly interface. Provides a C++ front-end interface option. Includes a rich set of powerful APIs that extend the PyTorch library.
  • 23. PYTORCH USE CASES Natural Language Processing (NLP): From Siri to Google Translate, deep neural networks have enabled breakthroughs in machine understanding of natural language. Most of these models treat language as a flat sequence of words or characters and use a kind of model called a recurrent neural network (RNN) to process this sequence. But many linguists think that language is best understood as a hierarchical tree of phrases, so a significant amount of research has gone into deep learning models known as recursive neural networks that take this structure into account. While these models are notoriously hard to implement and inefficient to run, PyTorch makes these and other complex natural language processing models a lot easier. Salesforce is using PyTorch for NLP and multi-task learning.
  • 24. PYTORCH USE CASES Research: PyTorch is a popular choice for research due to its ease of use, flexibility and rapid prototyping. Stanford University is using PyTorch’s flexibility to efficiently research new algorithmic approaches. Education: Udacity is educating AI innovators using PyTorch.