Python 千层面/茶卷,装载腌制模型时出现问题

Python 千层面/茶卷,装载腌制模型时出现问题,python,deep-learning,theano,conv-neural-network,lasagne,Python,Deep Learning,Theano,Conv Neural Network,Lasagne,我想我现在正在失去理智 我在用千层面做一个小的卷积神经网络。它训练得很好,我也可以计算训练集和验证集上的错误,但我无法将训练过的模型保存在磁盘上。更好的是,我可以保存并加载它,但我不能用它来预测新数据 这是我训练后做的 model = {'network': network, 'params': get_all_params(network), 'params_values': get_all_param_values(network)} pickle.dump(model, open('mod

我想我现在正在失去理智

我在用千层面做一个小的卷积神经网络。它训练得很好,我也可以计算训练集和验证集上的错误,但我无法将训练过的模型保存在磁盘上。更好的是,我可以保存并加载它,但我不能用它来预测新数据

这是我训练后做的

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'.
我试着在_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.

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

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

我想你忘了把T_输入到network@malioboro像网络(T_输入)?但是应该已经为该类型的输入设置了对象网络。也许我应该尝试初始化一个新的网络,然后设置参数值。我明天就试试。