烤宽面条/ Theano,加载腌制模型的问题

时间:2016-10-19 16:40:01

标签: python deep-learning theano conv-neural-network lasagne

我想我现在正在失去理智。

我正在使用Lasagne进行小型卷积神经网络。它训练完美,我也可以计算训练和验证集的错误,但我无法将训练好的模型保存在磁盘上。更好,我可以保存并加载它,但我不能用它来预测新数据。

这是我在训练后所做的事情

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.

1 个答案:

答案 0 :(得分:0)

问题是你的T_input没有绑定到输入层,因此theano无法编译它

T_input = lasagne.layers.get_all_layers(network)[0].input_var