Skip to content

Commit

Permalink
fix padding layer test
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdurrahheem committed May 8, 2024
1 parent 988111b commit 64c778d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
8 changes: 1 addition & 7 deletions modules/dnn/src/layers/padding_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -58,14 +57,9 @@ class PaddingLayerImpl CV_FINAL : public PaddingLayer
std::vector<MatShape> &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());
Expand Down
1 change: 0 additions & 1 deletion modules/dnn/test/test_common.impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
44 changes: 27 additions & 17 deletions modules/dnn/test/test_layers_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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<float>(1) = input.at<float>(0);
} else if (input_shape.size() == 1){
for (int i = 0; i < input_shape[0]; ++i){
output_ref.at<float>(i + 1) = input.at<float>(i);
}
} else {
for (int i = 0; i < input_shape[0]; ++i){
for (int j = 0; j < input_shape[1]; ++j){
output_ref.at<float>(i, j + 1) = input.at<float>(i, j);
}
}
}
std::cout << "shape output_ref: " << shape(output_ref) << std::endl;

std::vector<Mat> inputs{input};
std::vector<Mat> 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]);
}
Expand Down
4 changes: 0 additions & 4 deletions modules/ts/src/ts_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 64c778d

Please sign in to comment.