Keras 1.0: getting an intermediate level

I'm currently trying to visualize intermediate level output in Keras 1.0 (which I could do with Keras 0.3), but it no longer works.

x = model.input
y = model.layers[3].output
f = theano.function([x], y)

But I get the following error:

MissingInputError: ("An input of the graph, used to compute DimShuffle{x,x,x,x}(keras_learning_phase), was not provided and not given a value.Use the Theano flag exception_verbosity='high',for more information on this error.", keras_learning_phase)

Prior to Keras 1.0, with my graphics model, I could just do:

x = graph.inputs['input'].input
y = graph.nodes[layer].get_output(train=False)
f = theano.function([x], y, allow_input_downcast=True)

Therefore, I suspect that this came from the parameter "train = False", which I do not know how to install in the new version.

thanks for the help

+4
source share
2 answers

Try: In import statements, first specify

from keras import backend as K
from theano import function

then

f = K.function([model.layers[0].input, K.learning_phase()],
                              [model.layers[3].output])
# output in test mode = 0
layer_output = get_3rd_layer_output([X_test, 0])[0]

# output in train mode = 1
layer_output = get_3rd_layer_output([X_train, 1])[0]
+5
source

This was just answered by Francois Hall on github:

, -, , , .

iterate = K.function([input_img, K.learning_phase()], [loss, grads])

1 0 , , .

https://github.com/fchollet/keras/issues/2417

+3

All Articles