From f29bc22005c9256e053ca6ba80f4cf1f3082846d Mon Sep 17 00:00:00 2001 From: "ashishiva3@gmail.com" Date: Wed, 15 Jan 2020 19:01:01 +0530 Subject: [PATCH] Convolutional padding parsing modified --- modules/dnn/src/darknet/darknet_io.cpp | 7 ++++--- modules/dnn/test/test_darknet_importer.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/dnn/src/darknet/darknet_io.cpp b/modules/dnn/src/darknet/darknet_io.cpp index e9938ecbb9..713624f728 100644 --- a/modules/dnn/src/darknet/darknet_io.cpp +++ b/modules/dnn/src/darknet/darknet_io.cpp @@ -556,6 +556,7 @@ namespace cv { { int kernel_size = getParam(layer_params, "size", -1); int pad = getParam(layer_params, "pad", 0); + int padding = getParam(layer_params, "padding", 0); int stride = getParam(layer_params, "stride", 1); int filters = getParam(layer_params, "filters", -1); bool batch_normalize = getParam(layer_params, "batch_normalize", 0) == 1; @@ -563,13 +564,13 @@ namespace cv { if (flipped == 1) CV_Error(cv::Error::StsNotImplemented, "Transpose the convolutional weights is not implemented"); - // correct the strange value of pad=1 for kernel_size=1 in the Darknet cfg-file - if (kernel_size < 3) pad = 0; + if (pad) + padding = kernel_size / 2; CV_Assert(kernel_size > 0 && filters > 0); CV_Assert(current_channels > 0); - setParams.setConvolution(kernel_size, pad, stride, filters, current_channels, + setParams.setConvolution(kernel_size, padding, stride, filters, current_channels, batch_normalize); current_channels = filters; diff --git a/modules/dnn/test/test_darknet_importer.cpp b/modules/dnn/test/test_darknet_importer.cpp index 6c43622adb..44d12f4e0d 100644 --- a/modules/dnn/test/test_darknet_importer.cpp +++ b/modules/dnn/test/test_darknet_importer.cpp @@ -106,7 +106,7 @@ public: std::string cfg = findDataFile("dnn/darknet/" + name + ".cfg"); std::string model = ""; if (hasWeights) - model = findDataFile("dnn/darknet/" + name + ".weights", false); + model = findDataFile("dnn/darknet/" + name + ".weights"); checkBackend(&inp, &ref); @@ -528,6 +528,11 @@ TEST_P(Test_Darknet_layers, reorg) testDarknetLayer("reorg"); } +TEST_P(Test_Darknet_layers, convolutional ) +{ + testDarknetLayer("convolutional", true); +} + INSTANTIATE_TEST_CASE_P(/**/, Test_Darknet_layers, dnnBackendsAndTargets()); }} // namespace