Antonio Sesto Antonio Sesto - 9 months ago 47
Python Question

Accessing output values of inner layers

I have a Keras neural network shown in the attached picture

Keras model.

I train this network with certain sequences of the form

, plus the other inputs which stay fixed for the entire sequence.

The prediction starts with passing to the network the first symbol
(plus the other inputs), decoding its output into the vector
, then passing
as the new input (till the network generates the symbol

For each prediction (on the test set), I need to access the output values of the hidden layers, in particular of the layer
(or the two dense layers that are concatenated in

From the documentation and from the debugger (looking into the Keras model) I cannot understand how I can access those values after a

Is there anyone who can help me or provide a pointer to the documentation?

Answer Source

You can view the output of a layer simply by model.layers[idx].output. For a more detailed answer see here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download