Reputation: 41
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.
Upvotes: 3
Views: 3866
Reputation: 131
A good method to drastically lower these parameters is to add:
subsample=(2, 2)
(careful it lowers the resolution of images/data) in all the Convolutional layers above that Flatten layer,
if subsample doesn't work then it is stride=(2, 2)
.
Upvotes: 0
Reputation: 86640
Use the summary to confirm the following (trust me, there will be an answer :D ):
(None, 358,718,32)
(None, 120, 240, 32)
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.
Upvotes: 3