当前位置:网站首页>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 .
边栏推荐
- LeetCode - 508. Sum of subtree elements with the most occurrences (traversal of binary tree)
- Dynamic layout management
- LeetCode - 673. Number of longest increasing subsequences
- Leetcode - 933 number of recent requests
- pycharm 无法引入自定义包
- Inverse code of string (Jilin University postgraduate entrance examination question)
- Anaconda installation package reported an error packagesnotfounderror: the following packages are not available from current channels:
- Basic use and actual combat sharing of crash tool
- 20220609 other: most elements
- Opencv note 21 frequency domain filtering
猜你喜欢
Configure opencv in QT Creator
Cases of OpenCV image enhancement
Label Semantic Aware Pre-training for Few-shot Text Classification
CV learning notes - reasoning and training
[LZY learning notes -dive into deep learning] math preparation 2.5-2.7
Opencv notes 20 PCA
3.1 Monte Carlo Methods & case study: Blackjack of on-Policy Evaluation
CV learning notes - edge extraction
LeetCode - 673. Number of longest increasing subsequences
LeetCode - 900. RLE 迭代器
随机推荐
Mise en œuvre d'OpenCV + dlib pour changer le visage de Mona Lisa
Leetcode-513: find the lower left corner value of the tree
LeetCode - 508. 出现次数最多的子树元素和 (二叉树的遍历)
Anaconda安装包 报错packagesNotFoundError: The following packages are not available from current channels:
[LZY learning notes -dive into deep learning] math preparation 2.1-2.4
波士顿房价预测(TensorFlow2.9实践)
Label Semantic Aware Pre-training for Few-shot Text Classification
Dictionary tree prefix tree trie
Wireshark use
Rewrite Boston house price forecast task (using paddlepaddlepaddle)
2.2 DP: Value Iteration & Gambler‘s Problem
Opencv image rotation
Opencv note 21 frequency domain filtering
LeetCode - 895 最大频率栈(设计- 哈希表+优先队列 哈希表 + 栈) *
重写波士顿房价预测任务(使用飞桨paddlepaddle)
20220606数学:分数到小数
[combinatorics] combinatorial existence theorem (three combinatorial existence theorems | finite poset decomposition theorem | Ramsey theorem | existence theorem of different representative systems |
20220609其他:多数元素
Judging the connectivity of undirected graphs by the method of similar Union and set search
Problems encountered when MySQL saves CSV files