Antonio Sesto Antonio Sesto - 10 hours ago 2
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

#abcd$
, 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
v
, then passing
v
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
inner_concat
(or the two dense layers that are concatenated in
inner_concat
).

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

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

Answer

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