Understanding the values of summary() (Output Shape, Param#)?

混江龙づ霸主 提交于 2020-12-12 09:10:30

问题


I'm checking the output of summary function and don't understand all the printed values.

For example, look on this simple code:

x = [1, 2, 3, 4, 5]
y = [1.2, 1.8, 3.5, 3.7, 5.3]
model = Sequential()
model.add(Dense(10, input_dim=1, activation='relu'))
model.add(Dense(30, input_dim=1, activation='relu'))
model.add(Dense(10, input_dim=1, activation='relu'))
model.add(Dense(1))
model.summary()

The output:

Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense (Dense)                (None, 10)                20        
_________________________________________________________________
dense_1 (Dense)              (None, 30)                330       
_________________________________________________________________
dense_2 (Dense)              (None, 10)                310       
_________________________________________________________________
dense_3 (Dense)              (None, 1)                 11        
=================================================================
Total params: 671
Trainable params: 671
Non-trainable params: 0
_________________________________________________________________
  1. Why is the meaning of None value , under the column Output Shape? what the None mean here?
  2. Which network will not show None in the summary?
  3. Why is the meaning of the Params # column ? How this value is calculated ?

回答1:


  1. The None is just a placeholder saying that the network can input more than one sample at the time. None means this dimension is variable. The first dimension in a keras model is always the batch size. ... That's why this dimension is often ignored when you define your model. For instance, when you define input_shape=(100,200) , actually you're ignoring the batch size and defining the shape of "each sample".

  2. None won't show If you set a fixed batch. As an example, if you would send in a batch of 10 images your shape would be (10, 64, 64, 3) and if you changed it to 25 you would have (25, 64, 64, 3)

  3. For the dense_1st layer , number of params is 20. This is obtained as : 10 (input values) + 10 (bias values)

    For dense_2nd layer, number of params is 330. This is obtained as : 10 (input values) * 30 (neurons in the second layer) + 30 (bias values for neurons in the second layer)

    For dense_3rd layer, number of params is 310. This is obtained as : 30 (input values) * 10 (neurons in the third layer) + 10 (bias values for neurons in the third layer)

    For final layer, number of params is 11. This is obtained as : 10 (input values) * 1 (neurons in the second layer) + 1 (bias values for neurons in the final layer)

    total params = 20+330+310+11 = 671



来源:https://stackoverflow.com/questions/64844529/understanding-the-values-of-summary-output-shape-param

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!