Keras: find out the number of layers

15,832

model.layers will give you the list of all layers. The number is consequently len(model.layers)

Share:
15,832

Related videos on Youtube

user673592
Author by

user673592

Updated on June 04, 2022

Comments

  • user673592
    user673592 over 1 year

    Is there a way to get the number of layers (not parameters) in a Keras model?

    model.summary() is very informative, but it is not straightforward to get the number of layers from it.

  • Nickolas
    Nickolas over 3 years
    len(model.layers) fails to count "sublayers", that is layers that exist within a model that's acting as a layer in your ubermodel.