ELEG5491: Introduction to Deep Learning PyTorchBasics Tutorial

ELEG5491: Introduction to Deep Learning PyTorch Basics Tutorial

GUO Xiaoyang 4 Feb 2021

PyTorch Installation

? Installation:

? Pip: pip install torch torchvision torchaudio ? Conda: conda install pytorch torchvision torchaudio -c pytorch

? Google CoLab: a jupyter notebook like environment (free gpu to use)

? ?

Tensors

A torch.Tensor is a multi-dimensional matrix containing elements of a single data type.

# How to construct a new tensor? # see: (see%20Creation%20Ops).

# Construct a 2x3 matrix, uninitialized x1 = torch.empty(2, 3) # Construct a randomly initialized matrix x2 = torch.rand(2, 3) # Construct a matrix filled zeros and of dtype long x3 = torch.zeros(3, 2, dtype=torch.long) # Construct a tensor directly from data x4 = torch.tensor([5.5, 3]) # Construct a tensor directly from numpy array x5 = torch.from_numpy(np.array([5.5, 3], dtype=np.float32))

Computational Graph

Image from

Basic operations

# Point wise Ops abs, acos, add, asin, bitwise_or/and/not, ceil, clamp, exp ...

# Reduction Ops argmax/min, mean, median, unique, prod, norm ...

# Comparison Ops allclose, argsort, equal, greater, isnan, isfinite, topk ...

# BLAS Ops dot, eig, det, matmul, qr, svd

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download