Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras: find out the number of layers

Tags:

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.

like image 975
user673592 Avatar asked Jan 15 '18 15:01

user673592


People also ask

How many layers does a model have?

The 7 layers of the OSI model. The layers are: Layer 1—Physical; Layer 2—Data Link; Layer 3—Network; Layer 4—Transport; Layer 5—Session; Layer 6—Presentation; Layer 7—Application.

How do you find number of parameters in Keras?

By applying this formula to the first Conv2D layer (i.e., conv2d ), we can calculate the number of parameters using 32 * (1 * 3 * 3 + 1) = 320, which is consistent with the model summary. The input channel number is 1, because the input data shape is 28 x 28 x 1 and the number 1 is the input channel.


1 Answers

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

like image 61
Maxim Avatar answered Oct 16 '22 02:10

Maxim