我想我在这一点上已经失去理智了。
我在用千层面做一个小的卷积神经网络。它训练得很好,我也可以计算训练集和验证集的误差,但我不能将训练好的模型保存在磁盘上。更好的是,我可以保存并加载它,但我不能使用它来预测新数据。
这就是我在训练后做的事情
model = {'network': network, 'params': get_all_params(network), 'params_values': get_all_param_values(network)}
pickle.dump(model, open('models/model_1.pkl', 'wb'), protocol=pickle.HIGHEST_PROTOCOL)这是我用来加载模型的方法
with open('models/model.pkl', 'rb') as pickle_file:
model = pickle.load(pickle_file)
network = model['network']
values = model['params_values']
set_all_param_values(network, values)
T_input = T.tensor4('input', dtype='float32')
T_target = T.ivector('target')
predictions = get_output(network, deterministic=True)
loss = (cross_entropy(predictions, T_target)).mean()
acc = T.mean(T.eq(T.argmax(predictions, axis=1), T_target), dtype=config.floatX)
test_fn = function([T_input, T_target], [loss, acc])我甚至不能传递实际的numpy输入,因为我得到了这个错误
theano.compile.function_module.UnusedInputError: theano.function was asked to create a
function computing outputs given certain inputs, but the provided input variable at index 0
is not part of the computational graph needed to compute the outputs: input.
To make this error into a warning, you can pass the parameter
on_unused_input='warn' to theano.function. To disable it completely, use
on_unused_input='ignore'.然后我尝试设置参数on_unused_input='warn‘,结果如下
theano.gof.fg.MissingInputError: An input of the graph, used to compute (..)
was not provided and not given a value.Use the Theano flag
exception_verbosity='high',for more information on this error.发布于 2017-01-05 07:46:39
问题是您的T_input没有绑定到输入层,因此theano无法对其进行编译
T_input = lasagne.layers.get_all_layers(network)[0].input_varhttps://stackoverflow.com/questions/40137113
复制相似问题