当前位置:网站首页>1.5 nn. Module neural network (III)
1.5 nn. Module neural network (III)
2022-07-29 03:22:00 【smiling0927】
1. Optimizer
1.1 After the gradient of all parameters is calculated by back propagation , We also need to use optimization methods to update the weights and parameters of the network . for example , Random gradient descent method (SGD) The update strategy is as follows :
weight= weight-learning_rate*gradientManual implementation is as follows :
learning_rate=0.01
for f in net.parameters():
f.data.sub_(f.grad_data*learning_rate)#inplace Subtraction 1.2. torch.optim It realizes most optimization methods in deep learning , for example :RMSProp、Adam、SGD etc. , Easier to use , Therefore, there is usually no need to write the above code manually .
import torch.optim as optim
optimizer = optim.SGD(net.parameters(), lr=0.01)
# In the training process, first clear the gradient ( And net.zero_grad() The effect is the same )
optimizer.zero_grad()
# Calculate the loss
output=net(input)
criterion = nn.MSELoss()
loss = criterion(output,target)
# Back propagation
loss.backward()
# Update parameters
optimizer.step()2. Data loading and preprocessing
torchvision The commonly used image data loading function is realized , for example Imagenet、CIFAR10、MNIST etc. , And common data conversion operations , Greatly facilitates data loading .
边栏推荐
- Several methods of converting object to string
- Redis配置缓存过期监听事件触发
- LeetCode 1331 数组序号转换[Map] HERODING的LeetCode之路
- HDU多校第二场 1011 DOS Card
- 带你来浅聊一下,单商户功能模块汇总
- Minesweeping simple version
- Score addition and subtraction of force deduction and brushing questions (one question per day 7/27)
- 西瓜书学习第六章---SVM
- How close can QA be to business code Direct exposure of defects through codediff
- Digital image processing Chapter 10 - image segmentation
猜你喜欢

Watermelon book learning Chapter 6 -- SVM

Alibaba Sentinel - 工作流程及原理解析

Summarize the knowledge points of the ten JVM modules. If you don't believe it, you still don't understand it

「PHP基础知识」输出圆周率的近似值

A case of gradually analyzing the splitting of classes -- colorful ball collisions

Hangao database best practice configuration tool Hg_ BP log collection content

Mathematical modeling -- analytic hierarchy process model

Let's talk about the summary of single merchant function modules

年内首个“三连跌” 95号汽油回归“8元时代“

During the year, the first "three consecutive falls" of No. 95 gasoline returned to the "8 Yuan era"“
随机推荐
Hangao database best practice configuration tool Hg_ BP log collection content
C traps and defects Chapter 3 semantic "traps" 3.3 array declaration as parameters
带你来浅聊一下,单商户功能模块汇总
力扣刷题之分数加减运算(每日一题7/27)
生产部署zabbix5.0笔记
【科技1】
MYCAT read / write separation configuration
MySQL流程控制之while、repeat、loop循环实例分析
Introduction and advanced MySQL (13)
01-sdram: Code of initialization module
Flask的创建的流程day05-06之创建项目
Data truncation and estimation
MySQL operation database data error: fatal error encoded during command execution
What if MySQL forgets the password
Calculation of array serial number of force deduction questions (daily question 7/28)
ShardingSphere之水平分表实战(三)
3D advanced renderer: artlandis studio 2021.2 Chinese version
Rongyun IM & RTC capabilities on new sites
Score addition and subtraction of force deduction and brushing questions (one question per day 7/27)
Design of smoke temperature, humidity and formaldehyde monitoring based on single chip microcomputer