2
$\begingroup$

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.

$\endgroup$
3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – JarsOfJam-Scheduler Jul 25 at 22:57
  • 1
    $\begingroup$ 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. $\endgroup$ – Fatemeh Asgarinejad Jul 25 at 23:07
  • 1
    $\begingroup$ I mean, because we need them forthwith, it seems they should be stored in RAM. $\endgroup$ – Fatemeh Asgarinejad Jul 25 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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