当前位置:网站首页>Deep Learning with Pytorch- A 60 Minute Blitz
Deep Learning with Pytorch- A 60 Minute Blitz
2022-06-30 09:14:00 【The man of Jike will never admit defeat】
Deep Learning with Pytorch: A 60 Minute Blitz
Blitz : Air raids with Blitzkrieg
The goal of this document
- Understand at a higher level Pytorch Of Tensor Libraries and neural networks
- Train a small-scale neural network to classify images
This article assumes that you are basically familiar with numpy
What is? Pytorch
Pytorch It is based on scientific computing package Python, Target two groups of people
1. To make use of GPU The ability to replace NumPy
2. Provide the maximum flexibility and speed of deep learning research platform
Start
Tensors
Tensors Be similar to Numpy Of narrays, It's just Tensors have access to GPU Accelerate Computing from __future__ import print_functionimport torch
Construct a 5*3 Uninitialized matrix x = torch.Tensor(5, 3)
Build a random initialization matrix x = torch.rand(5, 3)
Get the size of the matrix print(x.size())Out: torch.Size([5, 3]) ; Output result
operation
Pytorch There are many syntax for operations . In the following example, we will see the addition operation y = torch.rand(5, 3)print(x + y)
perhaps , Additive grammar ② torch.add(x, y)
Add : Provide an output tensor As a parameter result = torch.Tensor(5, 3)torch.add(x, y, out=result)print(result)
In situ ( in-place ) Add y.add_(x)
Note : Anything that makes one Tensor Operations that change locally should be followed by a ’_’
You can also use things like NumPy The same index means print(x[:, 1])
Change the size : If you want to resize perhaps reshape tensor, have access to torch.view x = torch.randn(4, 4)y = x.view(16)z = x.view(-1, 8); -1 The value of is derived from another dimension print(x.size(), y.size(), z.size())
Out: torch.Size([4, 4]), torch.Size([16]), torch.Size([2, 8])
also 100+ In the operation , see here
Numpy Bridge
Will a Torch Tensor convert to NumPy array Or the reverse is a very easy thing
Torch Tensor and NumPy array Will share hidden memory addresses , So changing one will change both
Will a Torch Tensor convert to NumPy array
a = torch.ones(5);b = a.numpy()
to glance at NumPy array How to change the value a.add_(1)
Will a NumPy array convert to Torch Tensor
See how to automatically NumPy array convert to Torch Tensor a = np.ones(5)b = torch.from_numpy(a)np.add(a, 1, out=a)
CUDA Tensors
Tensors have access to .cuda Method transferred to GPU operation
appendix : And that 100+ Middle operation ….
Tensors
torch.is_tensor(obj)
return True If obj It's a Pytorch tensor torch.is_storage(obj)
return True If obj yes pytorch Store the object torch.set_default_tensor_type()torch.numel(input)
Return to input Tensor The total number of elements in torch.set_printoptions(precesion=None, threshold=None, edgeitems=None, linewidth=None, profile=None)
Creation Ops
torch.eye(n, m=None, out=None)
return 2-D Divide the diagonal by 1 For all other 0 Matrix torch.from_numpy(ndarray)
from numpy.ndarray To create a Tensor torch.linspace(start, end, steps=100, out=None)
Return to one dimension Tensor,steps Divide equally from start To end torch.logspace(start, end, steps=100, out=None)
Return to one dimension tensor,steps Divide equally from 10^start To 10^end torch.ones(*size,out=None)
Returns that all elements are scalars 1 Of tensor, from size decision shape torch.ones_like(input, out=None)
Return and input Of size All the same elements are 1 Of tensor torch.arange(start=0, end, step=1, out=None)
Return to one dimension tensor, Size is (end-start)/step, [start, end), The difference between every two adjacent elements step torch.range(start, end, step=1, out=None)
It's more than arange One more. end Elements
Warning : This function is due to arange Has been abandoned torch.zeros(*size, out=None)
Returns that all elements are 0 Of Tensor, from size decision shape torch.zeros_like(input, out=None)
Refer to the above ones_like
Indexes , section , union , Rotation operation
torch.cat(seq, dim=0, out=None)
cat for concatenate ( String ) Link
Will be given Tensor Sequences are linked on a given dimension , In addition to the cat dimension , all Tensor must size identical x = torch.randn(2, 3)y = torch.Tensoe(2, 3)torch.cat((x, y), dim=1)
torch.chunk(tensor, chunks, dim=0)
Will a Tensor Decompose into a given number of blocks
To be continued…
torch.gather(input, dim, index, out=None)
边栏推荐
- Set, map and modularity
- Introduction to MySQL basics day3 power node [Lao Du] class notes
- Installation, use and explanation of vulnerability scanning tool OpenVAS
- Opencv learning notes-day5 (arithmetic operation of image pixels, add() addition function, subtract() subtraction function, divide() division function, multiply() multiplication function
- Esp32 things (I): Preface
- Understanding of MVVM and MVC
- 127.0.0.1、0.0.0.0和localhost
- Esp32 (4): overview of the overall code architecture
- Opencv learning notes -day10 logical operation of image pixels (usage of rectangle function and rect function and bit related operation in openCV)
- Flink Sql -- toAppendStream doesn‘t support consuming update and delete changes which
猜你喜欢

Concatapter tutorial

Opencv learning notes -day 11 (split() channel separation function and merge() channel merge function)

ES6 learning path (III) deconstruction assignment

Flink Exception -- No ExecutorFactory found to execute the application

Resnet50+fpn for mmdet line by line code interpretation

Opencv learning notes-day6-7 (scroll bar operation demonstration is used to adjust image brightness and contrast, and createtrackbar() creates a scroll bar function)

Handwriting sorter component

技术管理进阶——管理者如何进行梯队设计及建设

So the toolbar can still be used like this? The toolbar uses the most complete parsing. Netizen: finally, you don't have to always customize the title bar!

100 lines of code and a voice conversation assistant
随机推荐
Script summary
JPA naming rules
Small program learning path 1 - getting to know small programs
Opencv learning notes-day5 (arithmetic operation of image pixels, add() addition function, subtract() subtraction function, divide() division function, multiply() multiplication function
[untitled]
Dart asynchronous task
Introduction to MySQL basics day4 power node [Lao Du] class notes
Harmonyos actual combat - ten thousand words long article understanding service card development process
About Lombok's @data annotation
Esp32 things (VIII): music playing function of function development
[untitled]
Introduction to MySQL basics day3 power node [Lao Du] class notes
Qt连接神通数据库
CUDA implements matrix replication
Introduction to the runner of mmcv
Pytorch BERT
Influencing factors of echo cancellation for smart speakers
Using appbarlayout to realize secondary ceiling function
Coredata acquisition in swift sorting, ascending, descending
Comparison of two ways for C to access SQL Server database (SqlDataReader vs SqlDataAdapter)