Keras CNN model parameters calculation

后端 未结 2 1610
被撕碎了的回忆
被撕碎了的回忆 2020-12-09 04:51

My cnn model, which is created using Keras 1.1.1, has two convolution-pooling layers followed by two dense layers, and dropout is added following the second convolution-pool

2条回答
  •  执念已碎
    2020-12-09 05:26

    Its a rather simple calculation with basic concept.And by looking at your code and model summary this were my steps.

    Step 1: Formula to calculate parameters

    total_params =
    (filter_height * filter_width * input_image_channels + 1) * number_of_filters

    Step 2: Calculate parameters for first layer

    filter_height = 5,
    filter_weight = 5,
    input_image_channels = 1
    number_of_filters = 32
    Though you havent provided us with imput image channels, but i figured it out from by your parameters value.

    Now we will calculate the number of parameters for first conv layer.

    total_param = (5*5*1 + 1)*32 = 832

    Step 3: Similarly we can calculate for 2nd conv layer. Note that number of filters from previous layer become the number of channels for current layer's input image.

    filter_height = 5,
    filter_weight = 5,
    input_image_channels = 32
    number_of_filters = 64

    Now we will calculate the number of parameters for 2nd conv layer.

    total_param = (5*5*32 + 1)*64 = 51264

提交回复
热议问题