在我的神经网络末尾,我有一个softmax函数。我想要的概率是,我使用的是torch.tensor(nn.softmax(x))
,得到的是torch.tensor.For RuntimeError: Could not infer dtype of Softmax
。
我可以知道我做错了什么吗?或者有其他方法可以做到这一点。
发布于 2020-07-30 21:21:47
nn.Softmax
是一个类。你可以这样使用它:
import torch
x = torch.tensor([10., 3., 8.])
softmax = torch.nn.Softmax(dim=0)
probs = softmax(x)
或者,您可以使用函数式API torch.nn.functional.softmax
import torch
x = torch.tensor([10., 3., 8.])
probs = torch.nn.functional.softmax(x, dim=0)
它们是等效的。在这两种情况下,您都可以检查type(probs)
是否为<class 'torch.Tensor'>
。
https://stackoverflow.com/questions/63174079
复制相似问题