# YOLO layers size

According to the original paper, the input size of the YOLO network layer is 448x448x3 and after the filter (7x7x64-s-2) is applied the output shape is to be 221x221x192 as I suppose. Some sources assert that the output shape is 224x224x192 but how is it possible if we don't use the kernel (2x2x64-s-2)?

And I want to implement it using keras. But my code doesn't allow to obtain correct size of the next layer it gives (None, 221, 221, 64)

model = Sequential()
# The 1st layer
strides=2, input_shape=(448,448,3)))

• 224x224 is because of the stride of the convolution which is 2 (I think in the paper, that's why the convolutional layer is 7x7x64-s-2. I guess it uses padding to have size 224x224 and not 221x221 Nov 13, 2018 at 13:52
• @JérémyBlain, but but when the 7x7 kernels with stride=2 moves over the 448x448 image it yields the 221x221 image, then the maxpool layer gives the 110x110 image. Am I wrong? Nov 13, 2018 at 13:59
• if you don't apply padding in your image, I think yes. usually we apply this padding, that way, activation maps have the same size as the inputs. Look at this for padding (it's an arugment for Conv2d object) : keras.io/layers/convolutional Nov 13, 2018 at 14:02
• maybe look at this video to understand padding : fr.coursera.org/lecture/convolutional-neural-networks/… Nov 13, 2018 at 14:06
• Oh, thanks I didn't know there is the same padding in the paper Nov 13, 2018 at 14:10

Usually, when we use a CNN, we apply padding with convolution, that way, activation maps have the same size as the inputs.

Look at this video to understand how padding works : Andrew Ng course on Coursera about padding (you need an account to watch the full video )

In Keras, Conv2D layer have an argument called 'padding', here is a link to the documentation : Convolutional layer documentation of Keras

Be aware because they say that setting padding to 'same' when using a stride different than 1 (it's your case here) can be inconsistent depending on the backends you use. I let you try to see if the second layers have the right shape.

That way, your conv layer output should be 224x224 like in the paper (and 112x112 after the maxpool layer)

Note : Be careful with your filters number. You set the number of filters to 64, but in the paper, the filters number is 192 (I guess it's 64*3 as there are 3 channels ?)

You will have to look into the sources. From below, if pad != 0 then padding = size/2 = 7/2 = 3. If pad = 0, then whatever padding was passed through cfg/yolov1.cfg. Phew!

Breakpoint 1, parse_convolutional (options=0x5555557f18c0, params=...) at ./src/parser.c:180
180 {
(gdb) n
181     int n = option_find_int(options, "filters",1);
(gdb) n
182     int size = option_find_int(options, "size",1);
(gdb) n
183     int stride = option_find_int(options, "stride",1);
(gdb) n
$1 = 1 (gdb) print padding$2 = 1436698242
$3 = 0 (gdb) n 187 if(pad) padding = size/2; (gdb) n 189 char *activation_s = option_find_str(options, "activation", "logistic"); (gdb) print padding$4 = 3