pytorch-yolo-v3
pytorch-yolo-v3 copied to clipboard
Why the padding is caculated like this?
awsome work! but can you tell me?
In the file darknet.py and in the method create_modules , you calculate the pad like this
if padding: pad = (kernel_size - 1) // 2 else: pad = 0
, but why? Why not use the pad number in the cfg file?
Thanks for your reply!
I think the most obvious reason is that although the configuration file gives you the padding parameters, it is safer and redundant to compute it from the kernel size. This way if there is any error in the pad parameter from the cfg file, it would be corrected by this calculation.
Padding is calculated in this way to guarantee that every pixel will be the 'center' of the kernel (first subtract 1 which is the center of the kernel, then divide by 2 to get number of pixels needed from one side to calculate value for center pixel). But I'm not sure if it is correct for YOLOv3, I read here: https://github.com/pjreddie/darknet/issues/950 that YOLOv3 uses constant padding equal 1..