当前位置:网站首页>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 .
边栏推荐
- 20220604 Mathematics: square root of X
- 20220603数学:Pow(x,n)
- CV learning notes ransca & image similarity comparison hash
- 20220610 other: Task Scheduler
- [combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)
- 20220602 Mathematics: Excel table column serial number
- YOLO_ V1 summary
- 20220610其他:任务调度器
- Opencv histogram equalization
- [LZY learning notes dive into deep learning] 3.4 3.6 3.7 softmax principle and Implementation
猜你喜欢

CV learning notes alexnet

LeetCode - 1172 餐盘栈 (设计 - List + 小顶堆 + 栈))

3.1 Monte Carlo Methods & case study: Blackjack of on-Policy Evaluation

Rewrite Boston house price forecast task (using paddlepaddlepaddle)

What can I do to exit the current operation and confirm it twice?

CV learning notes - BP neural network training example (including detailed calculation process and formula derivation)

2.1 Dynamic programming and case study: Jack‘s car rental

CV learning notes - scale invariant feature transformation (SIFT)

LeetCode - 1670 设计前中后队列(设计 - 两个双端队列)

Leetcode 300 longest ascending subsequence
随机推荐
20220604 Mathematics: square root of X
2.1 Dynamic programming and case study: Jack‘s car rental
20220604数学:x的平方根
LeetCode - 673. Number of longest increasing subsequences
[LZY learning notes -dive into deep learning] math preparation 2.5-2.7
Secure in mysql8.0 under Windows_ file_ Priv is null solution
使用sed替换文件夹下文件
One click generate traffic password (exaggerated advertisement title)
LeetCode - 715. Range 模块(TreeSet) *****
Leetcode - the k-th element in 703 data flow (design priority queue)
. DLL and Differences between lib files
QT self drawing button with bubbles
LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)
Toolbutton property settings
Opencv feature extraction sift
RESNET code details
openCV+dlib实现给蒙娜丽莎换脸
20220601数学:阶乘后的零
20220608 other: evaluation of inverse Polish expression
一步教你溯源【钓鱼邮件】的IP地址