【发布时间】:2017-06-27 04:34:06
【问题描述】:
我是深度学习的新手,但遇到了问题。 我正在使用 Theano 进行图像识别,并且我想使用经过训练的模型创建一个预测系统。 我引用了 LeNet5 Convolutional Neural Networks (LeNet) 并训练了自己的数据,现在我想使用训练后的模型来预测新图像。 在Classifying MNIST digits using Logistic Regression 中,它描述了腌制训练模型的方法,但这只是逻辑回归,而不是多层 CNN。以同样的方式我保存了每一层,但我不能用它来预测。 请帮我! 这是我的代码:
def predict():
"""
An example of how to load a trained model and use it
to predict labels.
"""
# load the saved model
#x = Data
x = T.matrix('x')
Data = x.reshape((1, 1, 32, 32))
layer0
layer1
layer2_input = layer1.output.flatten(2)
layer2
layer3
# compile a predictor function
predict_model = theano.function([layer0.input],
layer0.output)
#inputs=[layer0.input],
#outputs=layer3.y_pred)
# We can test it on some examples from test test
#dataset='facedata_cross_6_2_6.pkl.gz'
#datasets = load_data(dataset)
#test_set_x, test_set_y = datasets[2]
#test_set_x = test_set_x.get_value()
#reshape=np.reshape(test_set_x[26],(28,28))
#plt.imshow(reshape)
predicted_values = predict_model(Data)
print("Predicted values for the first 10 examples in test set:")
print(predicted_values)
【问题讨论】:
标签: deep-learning theano conv-neural-network image-recognition