Keras: How to visualize the output of an intermediate layer when the model have multiple input?

Created on 20 Aug 2016  ·  6Comments  ·  Source: keras-team/keras

Please make sure that the boxes below are checked before you submit your issue. Thank you!

  • [ ] Check that you are up-to-date with the master branch of Keras. You can update with:
    pip install git+git://github.com/fchollet/keras.git --upgrade --no-deps
  • [ ] If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with:
    pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps
  • [ ] Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).

Most helpful comment

Thanks a lot!
I actually figured out that for my use case, with the new functional API, I could simply write:
model = Model(input=[input1, input2], output=[intermediate_layer, intermediate_layer2])

Thanks for the reply anyway!

All 6 comments

I am afraid, I don't fully understand what you mean by multiple inputs. If you're simply looking at getting the output of the intermediate layer, you can take a look at this.
https://keras.io/getting-started/faq/#how-can-i-visualize-the-output-of-an-intermediate-layer

@lqj1990 : Did you manage to get your answer? Could you please post it here.

@stillbreeze If you have multiple input, you can see the order of your input layer when you use model.summary() to print the structure of your network. Then you just need to pick up the order number of the input layer and use them in your code.

Let's suppose your input layer is the first and third layer, then you can use the code
get_3rd_layer_output = K.function([model.layers[0].input, model.layers[2].input, K.learning_phase()], [model.layers[3].output])
to get the intermediate layers output.

I hope I had make it clear. (●'◡'●)

Thanks a lot!
I actually figured out that for my use case, with the new functional API, I could simply write:
model = Model(input=[input1, input2], output=[intermediate_layer, intermediate_layer2])

Thanks for the reply anyway!

@stillbreeze
where did you made the changes. i have two model which are concatenated in the last layers . how can i get intermediate ourputs

More generally you can visualise the output/activations of every layer of your model. I wrote an example with MNIST to show how here:

https://github.com/philipperemy/keras-visualize-activations

So far it's the less painful I've seen.

Was this page helpful?
0 / 5 - 0 ratings