You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
darknet importer: padding is parsed incorrectly for convolutional layers #16259
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).
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.
The fix is to replicate these three lines from darknet:
int pad = option_find_int_quiet(options, "pad",0);
int padding = option_find_int_quiet(options, "padding",0);
if(pad) padding = size/2;
You have to read the padding value from the configuration file using int padding = getParam<int>(layer_params, "padding", 0). If pad is one, you have to set padding to kernel_size / 2. You have to pass padding instead of pad as the argument to setConvolution.
Activity
dkurt commentedon Dec 30, 2019
Nice catch! You may use https://github.com/opencv/opencv_extra/blob/master/testdata/dnn/darknet/generate_darknet_models.py to generate a test sample.
anshu0612 commentedon Jan 2, 2020
I would be like to take up the issue @dkurt
dkurt commentedon Jan 2, 2020
@anshu0612, feel free to open a PR
ashishkrshrivastava commentedon Jan 9, 2020
@anshu0612 , have you started working on this issue ? I would like to take this issue if you haven't because I think I already got the solution.
anshu0612 commentedon Jan 9, 2020
hi! @ashishkrshrivastava I am already working on it after going the code base and i’m near the solution.
In case of need I’ll inform you. Thanks
YashasSamaga commentedon Jan 13, 2020
@anshu0612 any news?
All the changes that need to be made are here I think:
opencv/modules/dnn/src/darknet/darknet_io.cpp
Lines 555 to 576 in 4cc458e
The fix is to replicate these three lines from darknet:
You have to read the
paddingvalue from the configuration file usingint padding = getParam<int>(layer_params, "padding", 0). Ifpadis one, you have to setpaddingtokernel_size / 2. You have to passpaddinginstead ofpadas the argument tosetConvolution.anshu0612 commentedon Jan 13, 2020
I apologize for the delay.
@ashishkrshrivastava Please go ahead and open a PR since I am stuck with other work.
ashishkrshrivastava commentedon Jan 13, 2020
Thankyou @anshu0612, @YashasSamaga I have already made your suggested changes. I will push PR soon.