2016-04-20 3 views
4

J'essaie actuellement de visualiser la sortie d'une couche intermédiaire dans Keras 1.0 (ce que je pourrais faire avec Keras 0.3) mais cela ne marche plus.Keras 1.0: obtenir la sortie de la couche intermédiaire

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

Mais je reçois l'erreur suivante:

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) 

Avant Keras 1.0, avec mon modèle graphique, je pouvais faire:

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

Je soupçonne qu'il vienne de le paramètre "train = False" que je ne sais pas comment définir dans la nouvelle version.

Merci pour votre aide

+0

Veuillez noter que le modèle graphique n'est plus supporté avec Keras 1.0. Le modèle séquentiel a été étendu avec l'option Merge et le modèle Graph a été remplacé par Functional API. Je vous conseille de lire attentivement: http://keras.io/getting-started/functional-api-guide/ pour plus d'informations. –

Répondre

3

Ce fut vient de répondre par François Chollet sur github:

Your model apparently has a different behavior in training and test mode, and so needs to know what mode it should be using.

Use

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

and pass 1 or 0 as value for the learning phase, based on whether you want the model in training mode or test mode.

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

5

Essayez: Dans les déclarations d'importation d'abord donner

from keras import backend as K 
from theano import function 

puis

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]