期待 FloatTensors 但在类似 MNIST 的任务中得到 LongTensors

我正在执行类似 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()

谁能给我一些建议?谢谢。


潇湘沐
浏览 290回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python