[英]Deep Q-Learning : torch.nn.functional.softmax crash
I am following a tutorial, and the function softmax crashes when I use it. 我正在学习一个教程,当我使用它时,函数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
is a neural network ( torch.nn.module
), which return a Tensor like self.model
是一个神经网络( torch.nn.module
),返回Tensor之类的
tensor([[ 0.2699, -0.2176, 0.0333]], grad_fn=<AddmmBackward>)
So, the line probs = F.softmax(self.model(newState), dim=1)
crash the program but when dim=0
it works but it is not good. 因此,线
probs = F.softmax(self.model(newState), dim=1)
使程序崩溃但是当dim=0
它可以工作,但它不好。
Disclaimer: I am sorry this probably should have been a comment but I can't write all the below in a comment. 免责声明:对不起,这可能应该是评论,但我不能在评论中写下以下所有内容。
Are you sure this is the problem? 你确定这是问题吗? Below snippet just worked for me.
下面的片段对我来说很有用。
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.]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.