SlideShare a Scribd company logo
Getting Started with PyTorch
For Implementing Deep Learning
Supervised by Professor Shohreh Kasaei <pkasaei@gmail.com>
Written by Nader Karimi Bavandpour <nader.karimi.b@gmail.com>
Image Processing Lab, Sharif University of Technology
Outline
● Prerequisite
● PyTorch Crash Course
● Useful Links About PyTorch
● How to Use a Remote Linux Server
2
Prerequisite
● Virtual envs, conda, pypi, etc
● Installing PyTorch:
○ Go to pytorch.org and let them redefine the simplicity for you
3
Prerequisite (cont.)
● We have prepared some Jupyter notebooks for you to play with in the rest. If
you install Anaconda, you will already have Jupyter notebook available on
your system.
● To use it with a specific virtual-env, first activate that env, and then enter this
command: python -m ipykernel install --user --name=my-kernel-name. Then activate the defined
kernel your jupyter notebook. (my new kernel name is tiramisu_ipk).
See here for more information.
● Type jupyter notebook launch Jupyter
4
Prerequisite (cont.)
●
5
Prerequisite (cont.)
● If you are not interested in using Jupyter notebook, you can turn the notebook
into a .py file easily.
6
PyTorch Crash Course
7
What Is PyTorch?
8
But What Is Numpy?
● Adds support for large, multi-dimensional arrays and matrices, along with a
large collection of high-level mathematical functions to operate on these
arrays to python
● It’s ancestor project was started in 1995
● Written in C language
● Open source
9
But What Is Numpy?
● How numpy.org website defines it:
● Take a look here to see how comprehensive it is
● Try to skim this tutorial so that you can come back to it later
10
Numpy and torch.Tensor Are Similar
● Let’s play with ‘numpy_tensor.ipynb’ notebook together
11
The Tensor Class
● Indexing, creating, in place, item(), cpu and gpu, autograd…. Squeeze, numpy
bridge, variable class
● Please see here for more information
12
Autograd: Automatic Differentiation
● Some highlights from pytorch.org:
13
Autograd: Automatic Differentiation (cont.)
● Some important methods and statements we need to be familiar with:
○ Tensor.requires_grad: Returns a Boolean that shows if we are tracking gradient for a specific
Tensor
○ Tesor.requires_grad_(Boolean): Changes requires_grad in place.
○ Tensor.backward(): Computes gradients and accumulates them in Tensor.grad variable
○ with torch.no_grad(): To prevent tracking history and evaluating a model
● Let’s play with the notebook ‘autograd_tutorial.ipynb’ together
14
Neural Networks: Intro
● We use the package ‘torch.nn’ to construct a neural network
15
Neural Networks: torch.nn
● Class torch.nn.Parameter:
○ A subclass of the Tensor class
○ It is special: When assigned as Module attributes they are automatically added to the list of its
parameters, and will appear e.g. in parameters() iterator
● Why do you think it’s better to have a separate Parameter class?
● Let’s check PyTorch’s convolution source code:
16
Neural Networks: torch.nn (cont.)
● Torch.nn is base class for all neural network modules
● Your models should also subclass this class
● Useful methods and classes that you should be familiar with:
○ add_module(name, module)
○ apply(fn)
○ cpu()
○ cuda(device=None)
○ eval(): Sets the module in evaluation mode. Some modules, like dropout and batch-norm
change behaviour in eval mode.
○ modules(): Returns an iterator over all modules in the network
○ parameters(recurse=True): Returns an iterator over module parameters
○ ModuleList class
17
Neural Networks: torch.nn (cont.)
● Let’s play with the notebook ‘neural_networks_tutorial’ together
● You can check Neural Transfer example at pytorch.org, which is, well,
wonderful
● Check more neural network examples here
18
TensorboardX
● A professional logging technology
● It’s github page which is here which contains installation instructions
● It’s documentation page is here
● Usage example in ‘cifar10_tutorial.ipynb’ notebook
19
Useful Links About PyTorch
● Pytorch.org is a very good source of learning
○ List of tutorials is here
○ ‘DEEP LEARNING WITH PYTORCH: A 60 MINUTE BLITZ’ is the base of our PyTorch crash
course!
● PyTorch’s forum is here
● Here is a wonderful set of slides that teach deep learning theory and
implementation using PyTorch
20
How to Use a Remote Linux Server
21
Typical Operations You Will Probably Need
● Copying your source code to the server
● Copying your files, e.g., datasets to the server
● Copying result files from server back to your machine
● Install needed libraries, start running your code
● Check if some piece of server’s hardware is available
● ...
22
Some Useful Linux Commands
23
Command Task Options ([.] means optional)
cd Change Directory
pwd Print Working Directory
ls List contents of a directory [path], [-{a,l,h,...}]
touch Create a file [parent_directory/] filename
nano Simple text editor filename
cat See content of a file filename
head See some of lines from top filename
tail See some of last lines filename
Some Useful Linux Commands (cont.)
● Watch -n1 {command-name}. Example: watch -n1 gpustat, shows result of a
command with periodic refresh
● Screen {[-x screen-name], [list]}: Use this so that your program keeps running
while you are far far away
○ Examples:
■ Screen: create a new screen and go to it
■ Screen list: list all of available screens (attached or detached)
■ Screen -x screen-name: attach to an available screen
● gpustat: install by pip install gpustat
○ Watch -n1 gpustat is a useful combination
24
Some Useful Linux Commands (cont.)
● Create a new conda virtualenv
○ conda create -n yourenvname python=x.x anaconda
■ Example: conda create -n myenv python=3.6 anaconda
● Activate a conda virtualenv
○ Source activate yourenvname
● Deactivate a conda virtualenv
○ Source deactivate
● Install packages on a specific virtualenv:
○ First activate that env, then proceed like normal
25
Some Useful Linux Commands (cont.)
● To run your code:
● ‘tee’ command clones standard output
26
Some Useful Linux Commands (cont.)
● To run tensorboardX:
○ Tensorboard --logdir {log-directory}
● Set which GPU you want to use:
○ export CUDA_VISIBLE_DEVICES=0 (or =1)
● Use scp (secure copy) to copy files between server and your machine
27
Some applications that will make your life easier
● FTP (SFTP) client: FileZilla is free and available for most of the platforms.
Although, you may want to spend money and install a fancier one, like
Transmit and Forklift for MAC OS
● SSH client: Termius makes it easier to enter commands to a remote server
● PyCharm: An integrated development environment that supports local
programming and remote debugging
● Git: It has a relatively steep learning curve, but it is totally worth it when you
find yourself among a lot of versions of your research codes
28
How to Configure PyCharm
● Fill this fields. Then right-click on your server’s name and click set as default
29
How to Configure PyCharm (cont.)
● Fill this fields. Then right-click on your server’s name and click set as default
30
How to Configure PyCharm (cont.)
● You should also set the remote interpreter in your IDE
31
How to Configure PyCharm (cont.)
● How to find your interpreter’s path at the server:
32

More Related Content

What's hot

Introduction to Chainer 11 may,2018
Introduction to Chainer 11 may,2018Introduction to Chainer 11 may,2018
Introduction to Chainer 11 may,2018
Preferred Networks
 
Chainer v3
Chainer v3Chainer v3
Chainer v3
Seiya Tokui
 
Chainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereportChainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereport
Preferred Networks
 
Overview of Chainer and Its Features
Overview of Chainer and Its FeaturesOverview of Chainer and Its Features
Overview of Chainer and Its Features
Seiya Tokui
 
Introduction to Chainer
Introduction to ChainerIntroduction to Chainer
Introduction to Chainer
Preferred Networks
 
Dive Into PyTorch
Dive Into PyTorchDive Into PyTorch
Dive Into PyTorch
Illarion Khlestov
 
Chainer Update v1.8.0 -> v1.10.0+
Chainer Update v1.8.0 -> v1.10.0+Chainer Update v1.8.0 -> v1.10.0+
Chainer Update v1.8.0 -> v1.10.0+
Seiya Tokui
 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internal
Hyunghun Cho
 
Introduction to Chainer
Introduction to ChainerIntroduction to Chainer
Introduction to Chainer
Shunta Saito
 
Chainer v4 and v5
Chainer v4 and v5Chainer v4 and v5
Chainer v4 and v5
Preferred Networks
 
Comparison of deep learning frameworks from a viewpoint of double backpropaga...
Comparison of deep learning frameworks from a viewpoint of double backpropaga...Comparison of deep learning frameworks from a viewpoint of double backpropaga...
Comparison of deep learning frameworks from a viewpoint of double backpropaga...
Kenta Oono
 
CuPy: A NumPy-compatible Library for GPU
CuPy: A NumPy-compatible Library for GPUCuPy: A NumPy-compatible Library for GPU
CuPy: A NumPy-compatible Library for GPU
Shohei Hido
 
PyTorch 튜토리얼 (Touch to PyTorch)
PyTorch 튜토리얼 (Touch to PyTorch)PyTorch 튜토리얼 (Touch to PyTorch)
PyTorch 튜토리얼 (Touch to PyTorch)
Hansol Kang
 
Introduction to Chainer
Introduction to ChainerIntroduction to Chainer
Introduction to Chainer
Seiya Tokui
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0
Databricks
 
TensorFlow Dev Summit 2017 요약
TensorFlow Dev Summit 2017 요약TensorFlow Dev Summit 2017 요약
TensorFlow Dev Summit 2017 요약
Jin Joong Kim
 
[Pycon 2015] 오늘 당장 딥러닝 실험하기 제출용
[Pycon 2015] 오늘 당장 딥러닝 실험하기 제출용[Pycon 2015] 오늘 당장 딥러닝 실험하기 제출용
[Pycon 2015] 오늘 당장 딥러닝 실험하기 제출용
현호 김
 
Deep Learning with TensorFlow: Understanding Tensors, Computations Graphs, Im...
Deep Learning with TensorFlow: Understanding Tensors, Computations Graphs, Im...Deep Learning with TensorFlow: Understanding Tensors, Computations Graphs, Im...
Deep Learning with TensorFlow: Understanding Tensors, Computations Graphs, Im...
Altoros
 
CuPy v4 and v5 roadmap
CuPy v4 and v5 roadmapCuPy v4 and v5 roadmap
CuPy v4 and v5 roadmap
Preferred Networks
 
OpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon ValleyOpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon Valley
Ganesan Narayanasamy
 

What's hot (20)

Introduction to Chainer 11 may,2018
Introduction to Chainer 11 may,2018Introduction to Chainer 11 may,2018
Introduction to Chainer 11 may,2018
 
Chainer v3
Chainer v3Chainer v3
Chainer v3
 
Chainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereportChainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereport
 
Overview of Chainer and Its Features
Overview of Chainer and Its FeaturesOverview of Chainer and Its Features
Overview of Chainer and Its Features
 
Introduction to Chainer
Introduction to ChainerIntroduction to Chainer
Introduction to Chainer
 
Dive Into PyTorch
Dive Into PyTorchDive Into PyTorch
Dive Into PyTorch
 
Chainer Update v1.8.0 -> v1.10.0+
Chainer Update v1.8.0 -> v1.10.0+Chainer Update v1.8.0 -> v1.10.0+
Chainer Update v1.8.0 -> v1.10.0+
 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internal
 
Introduction to Chainer
Introduction to ChainerIntroduction to Chainer
Introduction to Chainer
 
Chainer v4 and v5
Chainer v4 and v5Chainer v4 and v5
Chainer v4 and v5
 
Comparison of deep learning frameworks from a viewpoint of double backpropaga...
Comparison of deep learning frameworks from a viewpoint of double backpropaga...Comparison of deep learning frameworks from a viewpoint of double backpropaga...
Comparison of deep learning frameworks from a viewpoint of double backpropaga...
 
CuPy: A NumPy-compatible Library for GPU
CuPy: A NumPy-compatible Library for GPUCuPy: A NumPy-compatible Library for GPU
CuPy: A NumPy-compatible Library for GPU
 
PyTorch 튜토리얼 (Touch to PyTorch)
PyTorch 튜토리얼 (Touch to PyTorch)PyTorch 튜토리얼 (Touch to PyTorch)
PyTorch 튜토리얼 (Touch to PyTorch)
 
Introduction to Chainer
Introduction to ChainerIntroduction to Chainer
Introduction to Chainer
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0
 
TensorFlow Dev Summit 2017 요약
TensorFlow Dev Summit 2017 요약TensorFlow Dev Summit 2017 요약
TensorFlow Dev Summit 2017 요약
 
[Pycon 2015] 오늘 당장 딥러닝 실험하기 제출용
[Pycon 2015] 오늘 당장 딥러닝 실험하기 제출용[Pycon 2015] 오늘 당장 딥러닝 실험하기 제출용
[Pycon 2015] 오늘 당장 딥러닝 실험하기 제출용
 
Deep Learning with TensorFlow: Understanding Tensors, Computations Graphs, Im...
Deep Learning with TensorFlow: Understanding Tensors, Computations Graphs, Im...Deep Learning with TensorFlow: Understanding Tensors, Computations Graphs, Im...
Deep Learning with TensorFlow: Understanding Tensors, Computations Graphs, Im...
 
CuPy v4 and v5 roadmap
CuPy v4 and v5 roadmapCuPy v4 and v5 roadmap
CuPy v4 and v5 roadmap
 
OpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon ValleyOpenPOWER Workshop in Silicon Valley
OpenPOWER Workshop in Silicon Valley
 

Similar to PyTorch crash course

Designate Install and Operate Workshop
Designate Install and Operate WorkshopDesignate Install and Operate Workshop
Designate Install and Operate Workshop
Graham Hayes
 
Cinder Project On-Boarding - OpenInfra Summit Denver 2019
Cinder Project On-Boarding - OpenInfra Summit Denver 2019Cinder Project On-Boarding - OpenInfra Summit Denver 2019
Cinder Project On-Boarding - OpenInfra Summit Denver 2019
Jay Bryant
 
From Zero to Hero - All you need to do serious deep learning stuff in R
From Zero to Hero - All you need to do serious deep learning stuff in R From Zero to Hero - All you need to do serious deep learning stuff in R
From Zero to Hero - All you need to do serious deep learning stuff in R
Kai Lichtenberg
 
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
Jay Bryant
 
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
Jay Bryant
 
Mastering Terraform and the Provider for OCI
Mastering Terraform and the Provider for OCIMastering Terraform and the Provider for OCI
Mastering Terraform and the Provider for OCI
Gregory GUILLOU
 
Paris.py
Paris.pyParis.py
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Valeriy Kravchuk
 
Cinder On-boarding Room - Berlin (11-13-2018)
Cinder On-boarding Room - Berlin (11-13-2018)Cinder On-boarding Room - Berlin (11-13-2018)
Cinder On-boarding Room - Berlin (11-13-2018)
Jay Bryant
 
Introduction to containers
Introduction to containersIntroduction to containers
Introduction to containers
Nitish Jadia
 
Customize and Secure the Runtime and Dependencies of Your Procedural Language...
Customize and Secure the Runtime and Dependencies of Your Procedural Language...Customize and Secure the Runtime and Dependencies of Your Procedural Language...
Customize and Secure the Runtime and Dependencies of Your Procedural Language...
VMware Tanzu
 
Troubleshooting .net core on linux
Troubleshooting .net core on linuxTroubleshooting .net core on linux
Troubleshooting .net core on linux
Pavel Klimiankou
 
Socket Programming with Python
Socket Programming with PythonSocket Programming with Python
Socket Programming with Python
GLC Networks
 
ApacheCloudStack
ApacheCloudStackApacheCloudStack
ApacheCloudStack
Puppet
 
Infrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStackInfrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStack
ke4qqq
 
PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...
PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...
PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...
Puppet
 
Integrating Puppet and Gitolite for sysadmins cooperations
Integrating Puppet and Gitolite for sysadmins cooperationsIntegrating Puppet and Gitolite for sysadmins cooperations
Integrating Puppet and Gitolite for sysadmins cooperations
Luca Mazzaferro
 
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdf
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdfGetting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdf
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdf
ssuser348b1c
 
Testing Django APIs
Testing Django APIsTesting Django APIs
Testing Django APIs
tyomo4ka
 
Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)
Giovanni Toraldo
 

Similar to PyTorch crash course (20)

Designate Install and Operate Workshop
Designate Install and Operate WorkshopDesignate Install and Operate Workshop
Designate Install and Operate Workshop
 
Cinder Project On-Boarding - OpenInfra Summit Denver 2019
Cinder Project On-Boarding - OpenInfra Summit Denver 2019Cinder Project On-Boarding - OpenInfra Summit Denver 2019
Cinder Project On-Boarding - OpenInfra Summit Denver 2019
 
From Zero to Hero - All you need to do serious deep learning stuff in R
From Zero to Hero - All you need to do serious deep learning stuff in R From Zero to Hero - All you need to do serious deep learning stuff in R
From Zero to Hero - All you need to do serious deep learning stuff in R
 
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
 
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
 
Mastering Terraform and the Provider for OCI
Mastering Terraform and the Provider for OCIMastering Terraform and the Provider for OCI
Mastering Terraform and the Provider for OCI
 
Paris.py
Paris.pyParis.py
Paris.py
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
 
Cinder On-boarding Room - Berlin (11-13-2018)
Cinder On-boarding Room - Berlin (11-13-2018)Cinder On-boarding Room - Berlin (11-13-2018)
Cinder On-boarding Room - Berlin (11-13-2018)
 
Introduction to containers
Introduction to containersIntroduction to containers
Introduction to containers
 
Customize and Secure the Runtime and Dependencies of Your Procedural Language...
Customize and Secure the Runtime and Dependencies of Your Procedural Language...Customize and Secure the Runtime and Dependencies of Your Procedural Language...
Customize and Secure the Runtime and Dependencies of Your Procedural Language...
 
Troubleshooting .net core on linux
Troubleshooting .net core on linuxTroubleshooting .net core on linux
Troubleshooting .net core on linux
 
Socket Programming with Python
Socket Programming with PythonSocket Programming with Python
Socket Programming with Python
 
ApacheCloudStack
ApacheCloudStackApacheCloudStack
ApacheCloudStack
 
Infrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStackInfrastructure as code with Puppet and Apache CloudStack
Infrastructure as code with Puppet and Apache CloudStack
 
PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...
PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...
PuppetConf 2016: Why Network Automation Matters, and What You Can Do About It...
 
Integrating Puppet and Gitolite for sysadmins cooperations
Integrating Puppet and Gitolite for sysadmins cooperationsIntegrating Puppet and Gitolite for sysadmins cooperations
Integrating Puppet and Gitolite for sysadmins cooperations
 
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdf
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdfGetting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdf
Getting-Started-with-Containers-and-Kubernetes_-March-2020-CNCF-Webinar.pdf
 
Testing Django APIs
Testing Django APIsTesting Django APIs
Testing Django APIs
 
Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)
 

Recently uploaded

Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
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
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLESINTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
anfaltahir1010
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Peter Caitens
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
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
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 

Recently uploaded (20)

Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
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
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLESINTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
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
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 

PyTorch crash course

  • 1. Getting Started with PyTorch For Implementing Deep Learning Supervised by Professor Shohreh Kasaei <pkasaei@gmail.com> Written by Nader Karimi Bavandpour <nader.karimi.b@gmail.com> Image Processing Lab, Sharif University of Technology
  • 2. Outline ● Prerequisite ● PyTorch Crash Course ● Useful Links About PyTorch ● How to Use a Remote Linux Server 2
  • 3. Prerequisite ● Virtual envs, conda, pypi, etc ● Installing PyTorch: ○ Go to pytorch.org and let them redefine the simplicity for you 3
  • 4. Prerequisite (cont.) ● We have prepared some Jupyter notebooks for you to play with in the rest. If you install Anaconda, you will already have Jupyter notebook available on your system. ● To use it with a specific virtual-env, first activate that env, and then enter this command: python -m ipykernel install --user --name=my-kernel-name. Then activate the defined kernel your jupyter notebook. (my new kernel name is tiramisu_ipk). See here for more information. ● Type jupyter notebook launch Jupyter 4
  • 6. Prerequisite (cont.) ● If you are not interested in using Jupyter notebook, you can turn the notebook into a .py file easily. 6
  • 9. But What Is Numpy? ● Adds support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays to python ● It’s ancestor project was started in 1995 ● Written in C language ● Open source 9
  • 10. But What Is Numpy? ● How numpy.org website defines it: ● Take a look here to see how comprehensive it is ● Try to skim this tutorial so that you can come back to it later 10
  • 11. Numpy and torch.Tensor Are Similar ● Let’s play with ‘numpy_tensor.ipynb’ notebook together 11
  • 12. The Tensor Class ● Indexing, creating, in place, item(), cpu and gpu, autograd…. Squeeze, numpy bridge, variable class ● Please see here for more information 12
  • 13. Autograd: Automatic Differentiation ● Some highlights from pytorch.org: 13
  • 14. Autograd: Automatic Differentiation (cont.) ● Some important methods and statements we need to be familiar with: ○ Tensor.requires_grad: Returns a Boolean that shows if we are tracking gradient for a specific Tensor ○ Tesor.requires_grad_(Boolean): Changes requires_grad in place. ○ Tensor.backward(): Computes gradients and accumulates them in Tensor.grad variable ○ with torch.no_grad(): To prevent tracking history and evaluating a model ● Let’s play with the notebook ‘autograd_tutorial.ipynb’ together 14
  • 15. Neural Networks: Intro ● We use the package ‘torch.nn’ to construct a neural network 15
  • 16. Neural Networks: torch.nn ● Class torch.nn.Parameter: ○ A subclass of the Tensor class ○ It is special: When assigned as Module attributes they are automatically added to the list of its parameters, and will appear e.g. in parameters() iterator ● Why do you think it’s better to have a separate Parameter class? ● Let’s check PyTorch’s convolution source code: 16
  • 17. Neural Networks: torch.nn (cont.) ● Torch.nn is base class for all neural network modules ● Your models should also subclass this class ● Useful methods and classes that you should be familiar with: ○ add_module(name, module) ○ apply(fn) ○ cpu() ○ cuda(device=None) ○ eval(): Sets the module in evaluation mode. Some modules, like dropout and batch-norm change behaviour in eval mode. ○ modules(): Returns an iterator over all modules in the network ○ parameters(recurse=True): Returns an iterator over module parameters ○ ModuleList class 17
  • 18. Neural Networks: torch.nn (cont.) ● Let’s play with the notebook ‘neural_networks_tutorial’ together ● You can check Neural Transfer example at pytorch.org, which is, well, wonderful ● Check more neural network examples here 18
  • 19. TensorboardX ● A professional logging technology ● It’s github page which is here which contains installation instructions ● It’s documentation page is here ● Usage example in ‘cifar10_tutorial.ipynb’ notebook 19
  • 20. Useful Links About PyTorch ● Pytorch.org is a very good source of learning ○ List of tutorials is here ○ ‘DEEP LEARNING WITH PYTORCH: A 60 MINUTE BLITZ’ is the base of our PyTorch crash course! ● PyTorch’s forum is here ● Here is a wonderful set of slides that teach deep learning theory and implementation using PyTorch 20
  • 21. How to Use a Remote Linux Server 21
  • 22. Typical Operations You Will Probably Need ● Copying your source code to the server ● Copying your files, e.g., datasets to the server ● Copying result files from server back to your machine ● Install needed libraries, start running your code ● Check if some piece of server’s hardware is available ● ... 22
  • 23. Some Useful Linux Commands 23 Command Task Options ([.] means optional) cd Change Directory pwd Print Working Directory ls List contents of a directory [path], [-{a,l,h,...}] touch Create a file [parent_directory/] filename nano Simple text editor filename cat See content of a file filename head See some of lines from top filename tail See some of last lines filename
  • 24. Some Useful Linux Commands (cont.) ● Watch -n1 {command-name}. Example: watch -n1 gpustat, shows result of a command with periodic refresh ● Screen {[-x screen-name], [list]}: Use this so that your program keeps running while you are far far away ○ Examples: ■ Screen: create a new screen and go to it ■ Screen list: list all of available screens (attached or detached) ■ Screen -x screen-name: attach to an available screen ● gpustat: install by pip install gpustat ○ Watch -n1 gpustat is a useful combination 24
  • 25. Some Useful Linux Commands (cont.) ● Create a new conda virtualenv ○ conda create -n yourenvname python=x.x anaconda ■ Example: conda create -n myenv python=3.6 anaconda ● Activate a conda virtualenv ○ Source activate yourenvname ● Deactivate a conda virtualenv ○ Source deactivate ● Install packages on a specific virtualenv: ○ First activate that env, then proceed like normal 25
  • 26. Some Useful Linux Commands (cont.) ● To run your code: ● ‘tee’ command clones standard output 26
  • 27. Some Useful Linux Commands (cont.) ● To run tensorboardX: ○ Tensorboard --logdir {log-directory} ● Set which GPU you want to use: ○ export CUDA_VISIBLE_DEVICES=0 (or =1) ● Use scp (secure copy) to copy files between server and your machine 27
  • 28. Some applications that will make your life easier ● FTP (SFTP) client: FileZilla is free and available for most of the platforms. Although, you may want to spend money and install a fancier one, like Transmit and Forklift for MAC OS ● SSH client: Termius makes it easier to enter commands to a remote server ● PyCharm: An integrated development environment that supports local programming and remote debugging ● Git: It has a relatively steep learning curve, but it is totally worth it when you find yourself among a lot of versions of your research codes 28
  • 29. How to Configure PyCharm ● Fill this fields. Then right-click on your server’s name and click set as default 29
  • 30. How to Configure PyCharm (cont.) ● Fill this fields. Then right-click on your server’s name and click set as default 30
  • 31. How to Configure PyCharm (cont.) ● You should also set the remote interpreter in your IDE 31
  • 32. How to Configure PyCharm (cont.) ● How to find your interpreter’s path at the server: 32