使用 Pytorch 使用 MNIST 数据库时无法在输出中获取图像

Unable to get an image in the output when using MNIST Database using Pytorch

iter_test = 0

对于图像,test_loader 中的标签:

iter_test += 1

images = images.view(-1, 28*28)

outputs = model(images)
_, predicted = torch.max(outputs.data, 1)

if iter_test == 1:
    print('PREDICTION')
    print(predicted[0])

    print('LABEL SIZE')
    print(labels.size())

    print('LABEL FOR IMAGE 0')
    print(labels[0])

我得到这段代码的输出如下:

PREDICTION

tensor(7)

LABEL SIZE

torch.Size([100])

LABEL FOR IMAGE 0

tensor(7)

代码完美运行。我想知道我是否可以将 "MNIST" 之类的图像与预测一起作为输出?

是的:)。

您可以使用 pyplot 并显示 test_loader 加载的图像。

勾选 https://www.oreilly.com/learning/not-another-mnist-tutorial-with-tensorflow

希望对您有所帮助!