Discussions>keras model get layer's output>

keras model get layer's output

I'm using keras 2.1 and I created an end to end model for classification. How can I get the values for each layer? 

1 votesJW326.00
1 Answers

You need to create a keras backend function for every layer you want and define the input and output. It's done like this

from keras import backend as K

inp = model.input
layer = get_my_layer() # get layer by name or by index
output = layer.output
layer_func = K.function([inp, K.learning_phase()], [output]) # Make sure you put there learning_phase

After that you can just call the function, passing 2 arguments input and learning phase respectively.

result = layer_func([x_input, 1])
Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?