python - 深度 Q 学习 : torch. nn.functional.softmax 崩溃

标签 python pytorch softmax

我正在学习一个教程,但是当我使用它时 softmax 函数崩溃了。

newSignals = [0.5, 0., 0., -0.7911, 0.7911]
newState = torch.Tensor(newSignals).float().unsqueeze(0)
probs = F.softmax(self.model(newState), dim=1)

self.model是一个神经网络(torch.nn.module),它返回一个像

这样的张量

tensor([[ 0.2699, -0.2176, 0.0333]], grad_fn=<AddmmBackward>)

因此,probs = F.softmax(self.model(newState), dim=1) 行使程序崩溃,但是当dim=0它有效,但效果不佳。

最佳答案

免责声明:很抱歉,这可能应该是评论,但我不能在评论中写下所有内容。

你确定这是问题所在吗?下面的代码片段对我有用。

import torch
a = torch.tensor([[ 0.2699, -0.2176,  0.0333]]) 
a.softmax(dim=1)
> tensor([[0.4161, 0.2555, 0.3284]])
a.softmax(dim=0)
> tensor([[1., 1., 1.]])

关于python - 深度 Q 学习 : torch. nn.functional.softmax 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53800842/

相关文章:

python - Pytorch几何: RuntimeError: expected scalar type Long but found Float

deep-learning - 使用 PyTorch 将训练数据集拆分为 CIFAR10 的训练集和验证集后,如何扩充数据?

python - Tensorflow tf.nn.softmax() 函数比手写的 softmax 性能好很多

python - Pytorch 中 [-1,0] 的维度范围是多少?

python - win10外接GPU安装pytorch失败

java - 将 Logistic 回归损失函数转换为 Softmax

python - 是否可以重复循环的迭代?

python - Python依赖 hell : A compromise between virtualenv and global dependencies?

python - Tkinter 新窗口

python - 如何在元组中复制元素 n 次