How can I get the reference to the last layer (the layer before the output) of the sequential/functional model in Keras? All layers can be retrieved with model.layers
where the last layer is usually the last in the list but is there a guarantee that the last layer in the list is also the last layer in the network?
Asked
Active
Viewed 667 times
0

Primoz
- 1,324
- 2
- 16
- 34
1 Answers
0
You could try and visualize the network by doing the following:
from keras.utils import plot_model
plot_model(model, to_file='model.png')
This will give you an overview of the network that maps your input to the eventual output, as well as all the layers it traverses through to reach the output.

Menno Van Dijk
- 863
- 6
- 24
-
Thank you, `plot_model` shows the whole network but I actually need the reference to the last layer to do some things programmatically. – Primoz Jun 15 '18 at 05:16