From 64c778d08d3c1493725cd0d96de527584c2ee648 Mon Sep 17 00:00:00 2001 From: Abdurrahheem Date: Wed, 8 May 2024 18:50:06 +0400 Subject: [PATCH] fix padding layer test --- modules/dnn/src/layers/padding_layer.cpp | 8 +---- modules/dnn/test/test_common.impl.hpp | 1 - modules/dnn/test/test_layers_1d.cpp | 44 +++++++++++++++--------- modules/ts/src/ts_func.cpp | 4 --- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/modules/dnn/src/layers/padding_layer.cpp b/modules/dnn/src/layers/padding_layer.cpp index a3f9eb8d562f..a79fff633065 100644 --- a/modules/dnn/src/layers/padding_layer.cpp +++ b/modules/dnn/src/layers/padding_layer.cpp @@ -40,7 +40,6 @@ class PaddingLayerImpl CV_FINAL : public PaddingLayer CV_Assert(params.has("paddings")); const DictValue& paddingsParam = params.get("paddings"); - std::cout << (paddingsParam.size() & 1) << std::endl; CV_Assert((paddingsParam.size() & 1) == 0); paddings.resize(paddingsParam.size() / 2); @@ -58,14 +57,9 @@ class PaddingLayerImpl CV_FINAL : public PaddingLayer std::vector &internals) const CV_OVERRIDE { CV_Assert(inputs.size() == 1); - std::cout << "inputs.size() = " << inputs.size() << std::endl; const MatShape& inpShape = inputs[0]; - std::cout << "inpShape.size() = " << inpShape << std::endl; - // std::cout << "paddings: " << paddings << std::endl; if (inpShape.empty()){ - std::cout << "in the new branch" << std::endl; - outputs.resize(1, MatShape(1, paddings.size() + 1)); - std::cout << "outputs: " << outputs[0] << std::endl; + outputs.resize(1, MatShape(1, paddings.size() * 2 + 1)); return false; } CV_Assert(inpShape.size() >= paddings.size()); diff --git a/modules/dnn/test/test_common.impl.hpp b/modules/dnn/test/test_common.impl.hpp index 0dddc850f4c0..70e1505f69c1 100644 --- a/modules/dnn/test/test_common.impl.hpp +++ b/modules/dnn/test/test_common.impl.hpp @@ -79,7 +79,6 @@ void normAssert( cv::InputArray ref, cv::InputArray test, const char *comment /*= ""*/, double l1 /*= 0.00001*/, double lInf /*= 0.0001*/) { - std::cout << "ref size: " << ref.size() << std::endl; double normL1 = cvtest::norm(ref, test, cv::NORM_L1) / ref.getMat().total(); EXPECT_LE(normL1, l1) << comment << " |ref| = " << cvtest::norm(ref, cv::NORM_INF); diff --git a/modules/dnn/test/test_layers_1d.cpp b/modules/dnn/test/test_layers_1d.cpp index 589929c83c16..5dfce4997332 100644 --- a/modules/dnn/test/test_layers_1d.cpp +++ b/modules/dnn/test/test_layers_1d.cpp @@ -585,28 +585,38 @@ TEST_P(Layer_Padding_Test, Accuracy_01D){ cv::Mat input(input_shape.size(), input_shape.data(), CV_32F); cv::randn(input, 0.0, 1.0); - // create a refence - cv::Mat output_ref; - cv::copyMakeBorder(input, output_ref, 0, 0, 1, 1, 0, (Scalar) pad_value); - if (input_shape.size() == 0 || input_shape.size() == 1){ - std::cout << "shape output_ref: " << shape(output_ref) << std::endl; - std::cout << "total: " << output_ref.total() << std::endl; - std::cout << "output_ref: " << output_ref.size() << std::endl; - output_ref = output_ref.reshape(1, (int)output_ref.total()); - output_ref.dims = 1; - std::cout << "output_ref: " << output_ref.size() << std::endl; + + // Fill in the padding values manually + // Create output ref shape depending on the input shape and input_dims + std::vector output_shape; + if (input_shape.size() == 0){ + output_shape = {1 + paddings[0] + paddings[1]}; + } else if (input_shape.size() == 1){ + output_shape = {input_shape[0] + paddings[0] + paddings[1]}; + } else { + output_shape = {input_shape[0], input_shape[1] + paddings[0] + paddings[1]}; + } + + cv::Mat output_ref(output_shape.size(), output_shape.data(), CV_32F, pad_value); + + if (input_shape.size() == 0){ + output_ref.at(1) = input.at(0); + } else if (input_shape.size() == 1){ + for (int i = 0; i < input_shape[0]; ++i){ + output_ref.at(i + 1) = input.at(i); + } + } else { + for (int i = 0; i < input_shape[0]; ++i){ + for (int j = 0; j < input_shape[1]; ++j){ + output_ref.at(i, j + 1) = input.at(i, j); + } + } } - std::cout << "shape output_ref: " << shape(output_ref) << std::endl; std::vector inputs{input}; std::vector outputs; - runLayer(layer, inputs, outputs); - std::cout << "output[0]: " << outputs[0] << std::endl; - std::cout << "output[0] shape: " << shape(outputs[0]) << std::endl; - std::cout << "output_ref: " << output_ref.size() << std::endl; - std::cout << "output[0]: " << outputs[0].size() << std::endl; - ASSERT_EQ(outputs.size(), 1); + ASSERT_EQ(1, outputs.size()); ASSERT_EQ(shape(output_ref), shape(outputs[0])); normAssert(output_ref, outputs[0]); } diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 90eff960fc8b..ad320e98bb9d 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -1465,8 +1465,6 @@ double norm(InputArray _src, int normType, InputArray _mask) double norm(InputArray _src1, InputArray _src2, int normType, InputArray _mask) { Mat src1 = _src1.getMat(), src2 = _src2.getMat(), mask = _mask.getMat(); - std::cout << "scr1 size: " << src1.size << std::endl; - std::cout << "scr2 size: " << src2.size << std::endl; if( src1.depth() == CV_16F || src1.depth() == CV_16BF ) { Mat src1_32f, src2_32f; @@ -1504,8 +1502,6 @@ double norm(InputArray _src1, InputArray _src2, int normType, InputArray _mask) normType = normType == NORM_L2SQR ? NORM_L2 : normType; CV_CheckTypeEQ(src1.type(), src2.type(), ""); - std::cout << "scr1 size: " << src1.size << std::endl; - std::cout << "scr2 size: " << src2.size << std::endl; CV_Assert(src1.size == src2.size); CV_Assert( mask.empty() || (src1.size == mask.size && mask.type() == CV_8U) ); CV_Assert( normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 );