Skip to content

darknet importer: padding is parsed incorrectly for convolutional layers #16259

@YashasSamaga

Description

@YashasSamaga

System information (version)

  • OpenCV => 4.2.0
  • Operating System / Platform => Ubuntu 18.04
  • Compiler => g++ 7.4
Detailed description

It appears that the pad value in darknet configuration files indicates the padding mode and not the padding value itself. I think pad being one implies same padding and pad being zero implies manual padding (which is specified in the padding parameter).

https://github.com/AlexeyAB/darknet/blob/dcfeea30f195e0ca1210d580cac8b91b6beaf3f7/src/parser.c#L180-L182

The OpenCV darknet parser treats the pad value as the actual padding value. There is also a comment which shows that the original author of the parser was stunned by the weird pad=1 and sets it to zero. It's actually zero because pad=1 would imply a padding of kernel_size//2 which would anyway give zero.

// correct the strange value of pad=1 for kernel_size=1 in the Darknet cfg-file
if (kernel_size < 3) pad = 0;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions