educative.io

Educative

The purpose of using the "custom_padding" function

Could someone describe the purpose of the “custom_padding” function?

I understand what the function do. It adds padding to each side of an image. I don’t understand the way it has been used in the “custom_conv2d” function and the logic behind this custom adding.

Assume that we have an image of size (24, 24, 3). In the initial convolution layer, we are using the kernel size of [7, 7] and stride size of 2. Since the stride is greater than 1, the function calls the “custom_padding”. Using the kernel of size 7, we end up with 3 padding on each side of the image, which we end up with an image of size (30, 30, 3). Then, we feed this padded image to a convolution layer with “valid” padding, the kernel size of [7, 7], and stride size of 2. The output of the convolution layer will have the size of [None, (30-7)/2+1, (30-7)/2+1, 64] = [None, 12, 12, 64].

In this case we are ending up with an output size which is not consistent with the other layers.


Type your question above this line.

Course: https://www.educative.io/collection/6083138522447872/5093907643760640
Lesson: https://www.educative.io/collection/page/6083138522447872/5093907643760640/5950519107387392