【发布时间】:2018-07-03 07:55:00
【问题描述】:
我使用 MNIST 数据集训练了一个 CNN 模型,现在想要预测图像的分类,其中包含数字 3。
但是当我尝试使用这个 CNN 进行预测时,pytorch 给了我这个错误:
TypeError: 'collections.OrderedDict' object is not callable
这是我写的:
cnn = torch.load("/usr/prakt/w153/Desktop/score_detector.pkl")
img = scipy.ndimage.imread("/usr/prakt/w153/Desktop/resize_num_three.png")
test_x = Variable(torch.unsqueeze(torch.FloatTensor(img), dim=1), volatile=True).type(torch.FloatTensor).cuda()
test_output, last_layer = cnn(test_x)
pred = torch.max(test_output, 1)[1].cuda().data.squeeze()
print(pred)
这里有一些解释:
img 是要预测的图像,大小为 28*28 score_detector.pkl 是训练好的 CNN 模型
任何帮助将不胜感激!
【问题讨论】:
-
我遇到了类似的问题,我收到了
TypeError: 'dict' object is not callable,我什至没有尝试使用 GPU。
标签: python tensorflow pytorch