Jun
Jun

Reputation: 1

define theano function with other theano function output

I am new to theano, can anyone help me defining a theano function like this:

Basically, I have a network model looks like this:

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

here the input x is a tensor:

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

I want to define two theano functions for later use:

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

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

the first one is fine. for the second one, the problem is both the input and the output are output of the original function. it gives me error:

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

my understanding is, both of [output_hiddens] and [mu] are related to the input [x], there should be an relation between them. I tried define another theano function from [x] to [mu] like:

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

then

f_hidden_mu = theano.function(f_x_hidden, f_x_mu), 

but it still does not work. Does anyone can help me? Thanks.

Upvotes: 0

Views: 189

Answers (1)

Patric
Patric

Reputation: 2131

The simple answer is NO WAY. In here

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

You can't use the output of theano.function as input/output for another theano.function since they are already a compiled graph/function.

You should pass the symbolic variables, such as x in your example code for f_x_hidden, to build the model.

Upvotes: 0

Related Questions