# Last layers of YOLO

I would like if someone could explain to me something. The architecture in YOLO from the Figure 3 in your YOLO paper https://pjreddie.com/media/files/papers/yolo.pdf is like this:

(448,448,3), (112,112,192), (56,56,256), (28,28,512), (14,14,1024),(7,7,1024),(7,7,1024), Dense(4096), (7,7,30)

I don't understand how to implement the last three parts, bolded ones If it is not the problem, I would appreciate if you help me understand that part. I use Keras and everything is OK for me to implement except those parts. I really don't know how to pass from (7,7,1024) to (7,7,1024) and also from Dense to (7,7,30).

You can use the Flatten and Reshape layers to go to Dense and back to HWC format. The last layers in keras would look like this:

7_7_1024_1 = ...  # The first (7,7,1024)
x = keras.layers.Flatten()(x)
x = keras.layers.Dense(4096)(x)
x = keras.layers.Dense(7 * 7 * 30)(x)
x = keras.layers.Reshape((7, 7, 30))(x)

• Thank you very much for answer. There is only one thing I really don't understand. Input shape is (448,448,3) and then they got (112,112,192). I don't understand how they got that with 64 kernels of size (7,7) and stride = 2.
– Alem
Jun 26, 2018 at 18:41
• The first layer contains a conv stride 2 and max pool (2, 2) stride 2 which results in a 4x spatial reduction. Jun 27, 2018 at 5:35
• When we use conv stride = 2, shouldn't we get (448-7+2*0)/2 + 1 = 221.5 output dimension, instead of 224? This is what I didn't understand. I uderstand that from 224 with maxpooling we get 112, but I don't understand how we get 224.
– Alem
Jun 27, 2018 at 10:53
• I think I understand now. Padding is used here different from zero. Somewhere 1, somewhere 3. Fix me if I'm wrong. I used to code in Keras something like: model.add(something). Is there a way you could write your code in that way?
– Alem
Jun 27, 2018 at 12:58