无法预测使用pytorch [MNIST]

问题描述 投票:1回答:1

pytorch noob在这里,试图学习。

链接到我的笔记本:https://gist.github.com/jagadeesh-kotra/412f371632278a4d9f6cb31a33dfcfeb

我的验证准确率达到95%。

我使用以下内容来预测:

m.eval()

testset_predictions = []
for batch_id,image in enumerate(test_dataloader):
    image = torch.autograd.Variable(image[0])
    output = m(image)
    _, predictated = torch.max(output.data,1)
    for prediction in predicted:
        testset_predictions.append(prediction.item())

len(testset_predictions)

问题是,当我将结果提交给参与竞争时,我只获得10%的准确率,这与随机预测一样好。我无法弄清楚我做错了什么。

请帮忙 :)

machine-learning deep-learning pytorch prediction mnist
1个回答
3
投票

很可能是因为拼写错误;当你想使用新创建的predictated结果时,你实际上使用predicted

_, predictated = torch.max(output.data,1)
    for prediction in predicted:

哪个predicted来自您之前的链接代码,它包含来自验证集而不是您的测试集的预测:

#validation

# ...

for batch_idx, (data, target) in enumerate(val_dataloader):

    data, target = Variable(data), Variable(target)

    output = m.forward(data)

    _, predicted = torch.max(output.data,1)

所以,你甚至没有得到错误信息,因为predicted确实存在 - 它只是你真正想要使用的...你最终提交验证集而不是测试集的结果(它肯定不会帮助两者都包含10,000个样本),因此您可以获得~10%的随机猜测准确度......

© www.soinside.com 2019 - 2024. All rights reserved.