Keras: Misunderstanding the Conv2D's param “filters”?

From https://keras.io/layers/convolutional/ (Conv2D):

keras.layers.Conv2D(filters, kernel_size, strides=(1, 1), padding='valid',
data_format=None, dilation_rate=(1, 1), activation=None,
use_bias=True, kernel_initializer='glorot_uniform',
bias_initializer='zeros', kernel_regularizer=None,
bias_regularizer=None, activity_regularizer=None,
kernel_constraint=None, bias_constraint=None)


filters: Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution).

Why is it possible to indicate the number of features maps (results of the scalar product between the kernel and the input), since we specify the kernel's size and the input?

Indeed, if we know the kernel's size (width and height) and the input's size (width and height), thus we know the number of features maps.

filters are the numbers of kernels or feature detectors that we choose for the convolutional layer to learn. in the end, the number of feature maps that we get equals to this number of filters that we have declared here.

Now, what are these feature detectors? these are matrixes usually smaller (much smaller) than the input images. It's occasionally $$3by3$$, $$5 by 5$$ or like the one in Alexnet $$7by7$$.

In the convolution layer, a convolution operation is done using each of these filters, each time we take a filter and our input image, then we put the filter on the left top corner of the input image and multiply each matching cells, then we would sum up the results and put that in the very first cell of our output (feature map) matrix. Then we move this filter on the image and do the same,... till we fill the whole feature map (stride defines how many cells we move in the image). Once we have our feature map number one that is a result of applying filter number one on the input image, we take another filter and do the same and so on and so forth.

Obviously, the outputted feature maps are smaller than the input, the amount by with the input size is reduced depends on the stride that we choose, moreover, we have kinda aggregated features in our feature map (also called convolution/convolved map)

Why is it possible to indicate the number of features maps (results of the scalar product between the kernel and the input), since we specify the kernel's size and the input?

Indeed, if we know the kernel's size (width and height) and the input's size (width and height), thus we know the number of features maps.

The thing is if we just know the input size and the size of the kernel, we don't know the stride, then setting a stride of 2 or 1 or anything else would give us different results. If you assume your stride to be a specific number, then you would know how many filters should be used.

• Perfect answer! Just a question, if we have 3 filters tensors, then we have 3 features tensors. What do Keras do of these 3 features tensors? Are they just stored in RAM? Or is there any math operation between them? – JarsOfJam-Scheduler Jul 25 '19 at 22:57
• Well, each time the kernel gets one of the filters and does the operation between the input image and the filter to get the output, the operation is an element wise multiplication of the two matrixes and then sum up the results. But I'm not sure whether the features are stored in RAM or not. – Fatemeh Asgarinejad Jul 25 '19 at 23:07
• I mean, because we need them forthwith, it seems they should be stored in RAM. – Fatemeh Asgarinejad Jul 25 '19 at 23:14