简体   繁体   中英

Why does my keras model have so many parameters?

model = ke.Sequential()

model.add(Convolution2D(32,kernel_size=(2,2),activation='relu',input_shape=(360,720,1)))
model.add(Convolution2D(32, 2, 2, activation='relu'))
model.add(MaxPooling2D(pool_size = (3,3)))
model.add(Dropout(.3))


model.add(Flatten())
model.add(Dense(2, activation='softmax'))

the above is currently the architecture for my CNN. However, it says it has 1.8m trainable parameters. Why is this so? I thought the first layer gives (32*4 = 128 params), but then how do I find how many params are in the rest of the model?

My understanding was that the CNN architecture should only depend on the filtering and max-pooling since they are shared weights. Why then do I have so many parameters? How should I go about reducing the number?

I am not asking how to find the number of params using "summary". I am asking why my model has so many parameters and how I can reduce that number. I do not understand intuitively why this model should have 1.8million trainable parameters.

Use the summary to confirm the following (trust me, there will be an answer :D ):

  • After the second conv you've got a shape like (None, 358,718,32)
  • The Pooling then gives you something very near (None, 120, 240, 32)
  • And the Flatten layer gave you (None, 120*240*32) which is (None, 921600) !!!!

This is the reason of so many parameters!

The dense layer will have 2 weights for each input, plus 2 biases, totaling 1843202 parameters just for the Dense layer.

You need more Convs + Poolings to gradually reduce the size before throwing that huge amount into a Dense layer.

大幅降低这些参数的一个好方法是在该Flatten层上方的所有卷积层中添加: subsample=(2, 2) (小心会降低图像/数据的分辨率),如果子采样不起作用,则stride=(2, 2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM