2016-12-13 59 views
0

我是新来theano,谁能帮助我定义theano功能是这样的:定义与其他theano功能输出theano功能

基本上,我有一个网络模型是这样的:

y_hat, cost, mu, output_hiddens, cells = nn_f(x, y, in_size, out_size, hidden_size, layer_models, 'MDN', training=False) 

这里的输入x是一个张:

x = tensor.tensor3('features', dtype=theano.config.floatX) 

我要定义以后使用两种theano功能:

f_x_hidden = theano.function([x], [output_hiddens]) 

f_hidden_mu = theano.function([output_hiddens], [mu], on_unused_input = 'warn') 

第一个没问题。对于第二个问题,问题是输入和输出都是原始函数的输出。它给了我错误:

theano.gof.fg.MissingInputError: An input of the graph, used to compute Elemwise{identity}(features), was not provided and not given a value.

我的理解是,两者的[output_hiddens][mu]都涉及到输入[x],应该有他们之间的关系。我试图定义从[x]另一个theano功能[mu],如:

f_x_mu = theano.function([x], [mu]), 

然后

f_hidden_mu = theano.function(f_x_hidden, f_x_mu), 

,但它仍然无法正常工作。有人可以帮助我吗?谢谢。

回答

0

简单的答案是没有办法。在here

Because in Theano you first express everything symbolically and afterwards compile this expression to get functions, ...

因为它们已经编译图/功能无法使用的theano.function输出作为另一个theano.function输入/输出。

您应该传递符号变量,例如f_x_hidden的示例代码中的x,以构建模型。