I am applying CNN model on my dataset for predictions. After reshaping the dimensions, the input_shape of my model1 becomes:

model1.input_shape: (None, 1, 3, 4)

then i apply CNN ist input layer defined below:

model1.add(Convolution2D(128, (2,2), border_mode= 'valid' , input_shape=(1, 3, 4), activation= 'relu'))

here above 1 is number of channel, 3,4 represents my nodes means 12 input nodes or features, now wehn i check the output_shape of model1, it is:

model1.output_shape: (None, 128, 2, 3)

here 128 are number of neurons i specified in my input layer. My question is what does the elements 2,3 shows here?

The output shape in a 2D convolutional layer depends on :

  • The input size W, H
  • The filter size F
  • The padding P
  • The stride S
  • The number of filters or depth D

Here, in your model, W=3, H=4, F=2, P=0 (default padding in Keras), S=1 (default stride in Keras), D=128 as you defined it.

The transformation is defined by the mathematical convolution operation, giving you an output shape as:

$\frac{W−F+2P}{S} + 1$

This output shape shows how your input reacts (in terms of size) when convolved with your 128 filters one by one.

  • Your answer is really helpful. However, if W=3, then why H=4 not considered here as total features/nodes are WxH=12. Sorry if my question is not according to the standard. M new to data science. – shahzeb haider Dec 3 at 16:48
  • Well, you don't need to flatten your input as WxH vector, 2D convolutions take that into account. As your filter is in 2D, it operates on the two dimensions of your input. – Elliot Dec 3 at 17:00
  • nicely explained (y) – shahzeb haider Dec 3 at 17:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.