issues
search
junxnone
/
aiwiki
AI Wiki
https://junxnone.github.io/aiwiki
18
stars
2
forks
source link
Tools Pytorch Pipeline
#173
Open
junxnone
opened
4 years ago
junxnone
commented
4 years ago
Reference
PyTorch中在反向传播前为什么要手动将梯度清零?
Gradient accumulation
Brief
Mode
Function
Description
Training
...
outputs = model(images)
输入图像和标签,通过infer计算得到预测值
...
loss = criterion(outputs, target)
计算损失函数
...
optimizer.zero_grad()
清空过往梯度
...
loss.backward()
反向传播,计算当前梯度
...
optimizer.step()
根据梯度更新网络参数
...
scheduler.step()
Learning Rate Scheduler
Validation
...
with torch.no_grad()
Validation Mode
...
outputs = model(images)
输入测试图像和标签,通过infer计算得到预测值
...
loss = criterion(outputs, target)
计算损失函数
junxnone
commented
4 years ago
junxnone/aiwiki#168
Reference
Brief
with torch.no_grad()