Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Get Layer Output if Model has Dropout - Keras 1.0 #2430

Closed
brian8128 opened this issue Apr 20, 2016 · 1 comment
Closed

Unable to Get Layer Output if Model has Dropout - Keras 1.0 #2430

brian8128 opened this issue Apr 20, 2016 · 1 comment

Comments

@brian8128
Copy link

brian8128 commented Apr 20, 2016

In this example https://github.com/julienr/ipynb_playground/blob/master/keras/convmnist/keras_cnn_mnist_v1.ipynb the author is able to build a backend function to get the output of a specific layer of a NN. If I modify the example to include dropout, for instance making the following change to cell 7, it no longer works.

model = Sequential()

model.add(Convolution2D(32, 3, 3, border_mode='valid', input_shape=X_train.shape[1:]))
model.add(Dropout(0.01)) # This breaks it
convout1 = Activation('relu')
model.add(convout1)
model.add(Convolution2D(32, 3, 3))

I get the following error message:

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)

The error makes sense - the dropout layer needs to know whether it's training time or test time in order to decide whether or not to do dropout - but I don't know how to pass in the learning phase parameter.

@fchollet
Copy link
Member

but I don't know how to pass in the learning phase parameter.

You add K.learning_phase() as an input to your function, and when calling the function you pass 1 or 0 as value for the learning phase. This is covered in the FAQ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants