Pytorch 中正确的使用 softmax 的方法是什么?
source link: https://www.v2ex.com/t/816364
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
如题,初学者,看官网的 tutorials 中的 quick start ,它是定义了一个长相为这样的网络
self.linear_relu_stack = nn.Sequential(
nn.Linear(28*28, 512),
nn.ReLU(),
nn.Linear(512, 512),
nn.ReLU(),
nn.Linear(512, 10)
)
输出类别为 10 类,然后反向传播的代码是
pred = model(X)
loss = loss_fn(pred, y)
# Backpropagation
optimizer.zero_grad()
loss.backward()
optimizer.step()
loss_fn 是nn.CrossEntropyLoss()
交叉熵,那么这个输出类别似乎是没有通过 softmax 直接就输入交叉熵了吗?
如果要 softmax+交叉熵的话,是应该在定义网络的时候,在最后的 fc 后面再加一个 nn.Softmax(),还是说写成下面这样:
pred = nn.Softmax(model(X))
loss = loss_fn(pred, y)
这个样子?谢谢大家
Recommend
-
93
之前一直在学习回归和二分类, 今天记录一下多分类的情况。 Softmax 二分类和多分类其实没有多少区别。用的公式仍然是 y=wx + b。 但有一个非常大的区别是他们用的激活函数是不同的。 逻辑回归用的是 sigmoid,这个激活函数的除了给函...
-
24
-
47
-
38
有问题,上知乎。知乎,可信赖的问答社区,以让每个人高效获得可信赖的解答为使命。知乎凭借认真、专业和友善的社区氛围,结构化、易获得的优质内容,基于问答的内容生产方式和独特的社区机制,吸引、聚集了各行各业中大量的亲历者、内行人、领域专家、领域爱好者...
-
43
-
45
-
63
我爱计算机视觉 标星,更快获取CVML新技术 近期,人脸识别研究领域的主要进展之一集中在了 Softmax Loss 的改进之上;在本文中,旷视研究院(上海)(MEGVII Research Shanghai)从...
-
39
点击 我爱计算机视觉 标星,更快获取CVML新技术 本文转载自机器之心。 选自arxiv 作者: 杨植麟、Thang Luong等
-
22
©PaperWeekly 原创 · 作者|苏剑林 单位|追一科技 研究方向|NLP、神经网络 一般来说,在处理常规...
-
5
【转】交叉熵损失函数CrossEntropyLoss(),softmax()函数,与NLLLoss()函数在 PyTorch 中的区别与联系 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK