Skip to content

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

Closed
@brian8128

Description

@brian8128

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions