问题
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
_________________________________________________________________
- Why is the meaning of None value , under the column
Output Shape
? what the None mean here? - Which network will not show None in the summary?
- Why is the meaning of the
Params #
column ? How this value is calculated ?
回答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".
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)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