Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating size of output of a Conv layer in CNN model

Tags:

In convolutional Neural Networks, How to know the output of a specific conv layer? (I am using keras to build a CNN model)

For example if I am using one dimensional conv layer, where number_of_filters=20, kernel_size=10, and input_shape(500,1)

 cnn.add(Conv1D(20,kernel_size=10,strides=1, padding="same",activation="sigmoid",input_shape=(Dimension_of_input,1)))

and if I am using two dimensional conv layer, where number_of_filters=64, kernal_size=(5,100), input_shape= (5,720,1) (height,width,channel)

 Conv2D(64, (5, 100),
       padding="same",
       activation="sigmoid",
       data_format="channels_last",
       input_shape=(5,720,1)

what is the number of output in the above two conv layers? Is there any equation that can be used to know the number of outputs of a conv layer in convolution neural network?

like image 973
ryh12 Avatar asked Apr 20 '17 01:04

ryh12


People also ask

What is the output of a convolutional layer?

We usually add the Dense layers at the top of the Convolution layer to classify the images. However input data to the dense layer 2D array of shape (batch_size, units). And the output of the convolution layer is a 4D array.

What is the output size of a convolution layer if we use ten 5x5 filters with stride 1 and Pad 2 on an input with volume 32x32x3?

Example: Input volumn of 32x32x3, what is the output size if we're to apply 10 5x5 filters with stride 1 and pad 2. And what is the total number of weights for this layer? The output width and the height will be ( 32 - 5 + 2 * 2 ) / 1 + 1 = 32 and the depth will be 10.

How do you calculate the output of a flatten layer?

Flatten also has no params. The third layer is a fully-connected layer with 120 units. So the number of params is 400*120+120=48120. It can be calculated in the same way for the fourth layer and get 120*84+84=10164.


1 Answers

Yes, there are equations for it, you can find them in the CS231N course website. But as this is a programming site, Keras provides an easy way to get this information programmaticaly, by using the summary function of a Model.

model = Sequential()
fill model with layers
model.summary()

This will print in terminal/console all the layer information, such as input shapes, output shapes, and number of parameters for each layer.

like image 103
Dr. Snoopy Avatar answered Sep 21 '22 11:09

Dr. Snoopy