Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lesson-21 / loss_acc_weights_grad.py #3

Closed
creater-zq opened this issue Dec 23, 2020 · 1 comment
Closed

lesson-21 / loss_acc_weights_grad.py #3

creater-zq opened this issue Dec 23, 2020 · 1 comment

Comments

@creater-zq
Copy link

  1. 在158行,因为valid_curve.append(loss.item())是在读取验证集的for循环的外面,所以最后的valid_curve列表里面只有一个损失值(最后一次读取验证集数据得到的损失)。
  2. 在159行打印loss_val时,打印的是一个epoch里,每次读取batch_size个验证集样本,来计算batch_size个样本损失的均值loss.item(),读多少次就计算多少个均值loss.item(),这里读取了2次,之后将2次的均值求和得到loss_val,这样打印的应该不是一个epoch的损失均值把,应该是loss_val/len(valid_loader)才对吧。
  3. 在163行,np.mean(valid_curve)只有一个数据,求均值还是最后一次读取的损失。
  4. 我的观点:在158行前面加上,loss_val_epoch=loss_val/len(valid_loader)。之后都用loss_val_epoch。
@TingsongYu
Copy link
Collaborator

TingsongYu commented Dec 24, 2020

https://github.com/JansonYuan/Pytorch-Camp/blob/master/hello%20pytorch/lesson/lesson-21/loss_acc_weights_grad.py#L158

对的,原来的loss统计有问题,你的建议不错,158行已经修改,多谢~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants