当前位置:网站首页>Deep Learning with Pytorch - autograd
Deep Learning with Pytorch - autograd
2022-06-30 09:14:00 【The man of Jike will never admit defeat】
Deep Learning with Pytorch: A 60 Minute Blitz
Autograd: automatic differentiation
Autograd: Automatic differentiation
stay Pytorch The center of all neural networks in is autograd package
Let's first take a brief look at , Then we will train our first neural network .
autograd Package provides Tensors Automatic differentiation of all operations on . This is a runtime defined framework , That is, your back propagation algorithm is defined by how your code works , Each iteration will be different .
Variable
autograd.variable Is the central class of this package . It's packed with a Tensor And support almost all definitions in Tensor The operating . Once you finish the calculation, you can call .backward() Make all your gradients automatically calculated
You can go through .data Feature access to any raw Tensor, About (w.r.t.with respect to) The gradient of this variable can be accumulated to .grad
h Another one is right autograd Implement very important classes Function
Variable and Function They are related to each other to build a cycle diagram , The graph encodes the entire history of the calculation . Every Variable There is one. .grad_fn characteristic , Point to creation Varaible Of Function ( except Varaibles Is created by the user , This is a grad_fn by None ).
If you want to calculate the derivative , It can be done to Variable call .backward(). If Variable It's a scalar , You don't need to be right backward() Indicate any parameters , But if Variable There are many elements , You have to specify a gradient parameter , This parameter is the tensor of the matching shape .
import torch
from torch.autograd import Variable
x = Varaible(torch.ones(2, 2), requires_grad=True); # Create a Variable
print(x)
y = x + 2
print(y)
# because y Created as a result of an operation , So it has grad_fn
print(y.grad_dn)
z = y * y * 3
out = z.mean()
print(z, mean)Gradient
Let us backprop, out.backward() Namely out.backward(torch.Tensor([1, 0])) # It is quite given here x The initial value of the , Is to calculate the derivation formula and bring it in x Calculated x Value out.backward(); print(x.grad)`
We should get a result that all elements are 4.5 Matrix ,
We call out by Variable”o”
O=14∑iZi O = 1 4 ∑ i Z i ;
Zi=3(xi+2)2 Z i = 3 ( x i + 2 ) 2 ;
Zi|xi=1=27 Z i | x i = 1 = 27 ;
dodx=32(xi+2) d o d x = 3 2 ( x i + 2 )
dodxi|xi=1=92=4.5 d o d x i | x i = 1 = 9 2 = 4.5
You can use it. autograd Do a lot of crazy things
x = torch.randn(3)
x = Variable(x, requires_grad=True)
y = x * 2
while y.data.norm() < 1000:
y = y * 2
print(y)
gradients = torch.FloatTensor([0.1, 1.0, 0.001])
y.backward(gradients)
# y Yes x The result of the derivation is 1024
print(x.grad)
# result:
# 102.4000
# 1024.0000
# 1.0240边栏推荐
- Alcohol tester scheme: what principle does the alcohol tester measure alcohol solubility based on?
- Row column (vertical and horizontal table) conversion of SQL
- c#获取当前的时间戳
- Rew acoustic test (II): offline test
- Treatment process record of Union Medical College Hospital (Dongdan hospital area)
- Opencv learning notes -day2 (implemented by the color space conversion function cvtcolar(), and imwrite image saving function imwrite())
- [JPEG] how to compile JPEG turbo library files on different platforms
- Talking about the difference between kotlin collaboration and thread
- Opencv learning notes -day8 (keyboard typing (waitkey()); Wait for typing) action: triggers some action when the appropriate character is typed using the keyboard)
- 127.0.0.1、0.0.0.0和localhost
猜你喜欢

The elegant combination of walle and Jianbao

Resnet50+fpn for mmdet line by line code interpretation

Talking about kotlin process exception handling mechanism

Flink Sql -- toAppendStream doesn‘t support consuming update and delete changes which
![[shutter] solve failed assertion: line 5142 POS 12: '_ debugLocked‘: is not true.](/img/77/eb66ec83b34c251e732d495fbaa951.jpg)
[shutter] solve failed assertion: line 5142 POS 12: '_ debugLocked‘: is not true.

Anchorgenerator for mmdet line by line interpretation

Rew acoustic test (III): generate test signal

Raspberry pie 4B no screen installation system and networking using VNC wireless projection function

C#访问MongoDB并执行CRUD操作

Talk about how the kotlin collaboration process establishes structured concurrency
随机推荐
[JPEG] how to compile JPEG turbo library files on different platforms
The elegant combination of walle and Jianbao
Based on svelte3 X desktop UI component library svelte UI
mysql基础入门 day3 动力节点[老杜]课堂笔记
Find the number that appears only once in the array
Raspberry pie 4B no screen installation system and networking using VNC wireless projection function
How can I get the discount for opening a securities account? Is online account opening safe?
icon资源
Comparaison de deux façons d'accéder à la base de données SQL Server (sqldatareader vs sqldataadapter)
C#访问SQL Server数据库两种方式的比较(SqlDataReader vs SqlDataAdapter)
Coredata acquisition in swift sorting, ascending, descending
挖财开户安全吗?怎么有人说不靠谱。
[untitled]
Esp32 things (II): sharpening the knife without mistaking firewood - make preparations before project development
Metasploit practice - SSH brute force cracking process
Rew acoustic test (V): equipment required for test
Detailed explanation of rect class
Deeply understand the working principle of kotlin collaboration suspend (beginners can also understand it)
Opencv learning notes-day14 drawing of image geometry (rect class rotatedrect class, rectangle drawing rectangle circle drawing circular function line drawing line function ellipse drawing elliptic fu
Rew acoustic test (III): generate test signal