【发布时间】:2019-06-02 18:22:09
【问题描述】:
我正在执行类似 MNIST 的任务,输入是 10 类图像,预期输出是图像的预测类别。
但现在output 类似于 [-2.3274, -2.2723, ...],其长度为 batch_size。而target 是 [4., 2., 2., 8., ...]
Error message: RuntimeError: 标量类型 Long 的预期对象,但参数 #2 'target' 的标量类型浮点数
class Net(nn.Module):
...
...
def forward(self, x):
...
...
return F.log_softmax(x, dim = 1)
criterion = torch.nn.NLLLoss()
谁能给我一些建议?谢谢。
【问题讨论】:
标签: python machine-learning deep-learning computer-vision pytorch