2

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?

Antonio Sesto
  • 2,868
  • 5
  • 33
  • 51

1 Answers1

2

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

Flomp
  • 524
  • 4
  • 17
  • Thanks! Is there any way to get the value of the node `net` (how it was called once upon a time), i.e. output = lambda net. activation(net). Furtuermore, is there any mapping between layer names and layer indexes? Do I need to print the summary of the network and count the layers? – Antonio Sesto Jul 17 '17 at 12:26
  • You can get a layer by name via `model.get_layer(name='layername')` – Flomp Jul 17 '17 at 12:47
  • It is not that easy as `.output`. I have read the thread you linked, but could not understand how to specify the various inputs my network has. Do you have an idea? – Antonio Sesto Jul 20 '17 at 11:56