Reputation: 13
When I run the following code (which is from this IPython notebook), I get an error:
import theano
def get_submodel(model, start, end):
return theano.function([model.layers[start].input],
model.layers[end].get_output(train=False),
allow_input_downcast=True)
def get_encoder(ae):
return get_submodel(ae, 0, (len(ae.layers) // 2) - 1)
ae_encoder = get_encoder(ae)
This is the error message:
Traceback (most recent call last):
File "Parametric t-SNE (Keras).py", line 432, in <module>
ae_encoder = get_encoder(ae)
File "Parametric t-SNE (Keras).py", line 424, in get_encoder
return get_submodel(ae, 0, (len(ae.layers) // 2) - 1)
File "Parametric t-SNE (Keras).py", line 422, in get_submodel
allow_input_downcast=True)
File "/usr/lib64/python3.4/site-packages/theano/compile/function.py", line 326, in function
output_keys=output_keys)
File "/usr/lib64/python3.4/site-packages/theano/compile/pfunc.py", line 397, in pfunc
for p in params]
File "/usr/lib64/python3.4/site-packages/theano/compile/pfunc.py", line 397, in <listcomp>
for p in params]
File "/usr/lib64/python3.4/site-packages/theano/compile/pfunc.py", line 496, in _pfunc_param_to_in
raise TypeError('Unknown parameter type: %s' % type(param))
TypeError: Unknown parameter type: <class 'tensorflow.python.framework.ops.Tensor'>
For reference, here is where ae
is defined:
n = X_train.shape[1]
ae = Sequential()
ae.add(Dense(500, activation='relu', weights=encoder.layers[0].get_weights(), input_shape=(n,)))
ae.add(Dense(500, activation='relu', weights=encoder.layers[1].get_weights()))
ae.add(Dense(2000, activation='relu', weights=encoder.layers[2].get_weights()))
ae.add(Dense(2, weights=encoder.layers[3].get_weights()))
ae.add(Dense(2000, activation='relu', weights=decoder.layers[0].get_weights()))
ae.add(Dense(500, activation='relu', weights=decoder.layers[1].get_weights()))
ae.add(Dense(500, activation='relu', weights=decoder.layers[2].get_weights()))
ae.add(Dense(n, weights=decoder.layers[3].get_weights()))
ae.compile(loss='mse', optimizer='rmsprop')
ae.fit(X_train, X_train, nb_epoch=100, verbose=2, batch_size=32)
Based on the answer to a similar question, I suspect that get_submodel
may need to be modified to use a symbolic variable instead of a tensor/matrix. However, I am not sure how to do this, and why it would even give an error since the IPython notebook on GitHub did not seem to contain any error messages. I have not been able to find more specific advice about the tensorflow.python.framework.ops.Tensor
error message.
Upvotes: 1
Views: 2414
Reputation: 40516
It seems that you have a tensorflow
backend - not a theano
one. That's why using theano.function
generates an error. Try using keras.backend.function
.
Upvotes: 1