#45 Task 04:关于softmax问题

Open
created 1 year ago by Yanger · 1 comments
Yanger commented 1 year ago
<!-- 需要按照模板,填写每一项内容,请勿改动 --> ### 问题所属任务编号(Task 01-05) Task 04 第一个问题: nn.Sequential里面没有softmax层,是不是计算交叉熵的时候包含了,也就是nn.CrossEntropyLoss()封装了softmax层? 第二个问题: ``` def evaluate_accuracy(net, data_iter): #@save if isinstance(net, torch.nn.Module): net.eval() metric = Accumulator(2) with torch.no_grad(): for X,y in data_iter: metric.add(accuracy(net(X),y),y.numel()) return metric[0]/metric[1] ``` 在评估测试集正确率的时候,我们已经进入了net.eval()评估模式,不在更新参数,为什么还要with torch.no_grad():,是否必须加
anine09 commented 1 year ago
Collaborator
- 关于第一个问题请参考 https://openi.pcl.ac.cn/Datawhale/d2l/issues/39 - 第二个问题其实也在 [Pytorch 官方文档](https://pytorch.org/docs/stable/notes/autograd.html#locally-disable-grad-doc) 中有详细说明 我们推荐将每个问题分为独立的 issue 进行讨论,也请仔细阅读 **学习者手册中的提问部分**,RTFM
anine09 added the
Task 04
label 1 year ago
anine09 added the
程序问题
label 1 year ago
anine09 added this to the 助教解答过 milestone 1 year ago
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.