当前位置:网站首页>Hands on deep learning pytorch version exercise solution-3.3 simple implementation of linear regression
Hands on deep learning pytorch version exercise solution-3.3 simple implementation of linear regression
2022-07-03 10:20:00 【Innocent^_^】
- If the total loss of small batch is replaced by the average loss of small batch , How do you need to change the learning rate ?
Explain : The default is actually the average (mean squared), The question is wrong , Do the opposite . The learning rate is divided by batch_size that will do - View the deep learning framework ⽂ files , What loss functions and initializations do they provide ⽅ Law ?⽤Huber The loss replaces the original loss , namely

Provided loss As shown in the figure below , If you need specific understanding, you can use help(torch.nn.xxxLoss) Or Baidu query
# huber Loss correspondence Pytorch Of SmoothL1 Loss
loss = nn.SmoothL1Loss(beta=0.5)
num_epochs = 3
for epoch in range(num_epochs):
for X, y in data_iter:
l = loss(net(X), y)
# Start calculating the gradient
trainer.zero_grad()
l.backward()
trainer.step() # Update all parameters
print("epoch: {}, loss:{}".format(epoch + 1, l))
# Start with 1 when loss The larger , Change to 0.5 Run again to reduce , It may be related to the number of iterations
''' epoch: 1, loss:0.00011211777746211737 epoch: 2, loss:0.00013505184324458241 epoch: 3, loss:4.4465217797551304e-05 '''
- How do you access the gradient of linear regression ?
net[0].weight.grad,net[0].bias.grad
''' (tensor([[-0.0040, 0.0027]]), tensor([0.0015])) '''
For observability , This time, in addition to highlighting loss Of , The code output of other problems is put into the code block .
边栏推荐
- Basic use and actual combat sharing of crash tool
- LeetCode - 715. Range 模块(TreeSet) *****
- Leetcode - 460 LFU cache (Design - hash table + bidirectional linked hash table + balanced binary tree (TreeSet))*
- Tensorflow2.0 save model
- LeetCode - 933 最近的请求次数
- 『快速入门electron』之实现窗口拖拽
- Flutter 退出当前操作二次确认怎么做才更优雅?
- Step 1: teach you to trace the IP address of [phishing email]
- ECMAScript--》 ES6语法规范 ## Day1
- Rewrite Boston house price forecast task (using paddlepaddlepaddle)
猜你喜欢

Neural Network Fundamentals (1)

LeetCode - 1172 餐盘栈 (设计 - List + 小顶堆 + 栈))
![[LZY learning notes dive into deep learning] 3.4 3.6 3.7 softmax principle and Implementation](/img/02/35e73a43c4ad26fee9ecf180593464.jpg)
[LZY learning notes dive into deep learning] 3.4 3.6 3.7 softmax principle and Implementation

Opencv+dlib to change the face of Mona Lisa

Opencv feature extraction sift

LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)

CV learning notes - deep learning

Opencv notes 17 template matching

Leetcode - 5 longest palindrome substring

LeetCode - 715. Range module (TreeSet)*****
随机推荐
20220531数学:快乐数
LeetCode - 1670 設計前中後隊列(設計 - 兩個雙端隊列)
What did I read in order to understand the to do list
Leetcode - 1670 design front, middle and rear queues (Design - two double ended queues)
Leetcode 300 longest ascending subsequence
Implementation of "quick start electronic" window dragging
Notes - regular expressions
20220601数学:阶乘后的零
使用密钥对的形式连接阿里云服务器
Opencv+dlib to change the face of Mona Lisa
Leetcode-404:左叶子之和
20220605数学:两数相除
Leetcode - 706 design hash mapping (Design)*
Qcombox style settings
Leetcode-112:路径总和
20220610 other: Task Scheduler
20220604数学:x的平方根
Inverse code of string (Jilin University postgraduate entrance examination question)
Leetcode-100: same tree
20220608 other: evaluation of inverse Polish expression