1
votes

The input shape in the first Conv2D layer is supposed to be (100, 100, 1) however the output is (None, 98, 98, 200). I understand what 200 and None determine but I'm not sure about 98 as the parameter. Also, adding to this, I randomly selected 200 as the number of filters in Conv2D for my model. How should I determine a suitable number of filters for my model. Is it based on trial and error? Please help. Thanks!!

from keras.models import Sequential
from keras.layers import Dense, Activation, Flatten, Dropout
from keras.layers import Conv2D, MaxPooling2D
from keras.callbacks import ModelCheckpoint

print(data.shape[1:])
model = Sequential()
model.add(Conv2D(200, (3,3), input_shape = data.shape[1:]))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size = (2,2)))

model.add(Conv2D(100,(3,3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(50, activation = 'relu'))
model.add(Dense(2, activation = 'softmax'))

model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
model.summary()

(100, 100, 1) Model: "sequential_3"


Layer (type) Output Shape Param #

conv2d_5 (Conv2D) (None, 98, 98, 200) 2000


activation_5 (Activation) (None, 98, 98, 200) 0


max_pooling2d_5 (MaxPooling2 (None, 49, 49, 200) 0


conv2d_6 (Conv2D) (None, 47, 47, 100) 180100


activation_6 (Activation) (None, 47, 47, 100) 0


max_pooling2d_6 (MaxPooling2 (None, 23, 23, 100) 0


flatten_3 (Flatten) (None, 52900) 0


dropout_3 (Dropout) (None, 52900) 0


dense_5 (Dense) (None, 50) 2645050


dense_6 (Dense) (None, 2) 102

Total params: 2,827,252 Trainable params: 2,827,252 Non-trainable params: 0


1

1 Answers

3
votes

add padding="same" as parameter to conv2d and the output dimension will be the same as the input dimension.

The default setting is padding="valid" and since you use a 3x3 filter and a step size of 1, you end up with 98x98 dimension because your 3x3 filter fits in 100x100 98 times.