Merge pull request #25071 from Abdurrahheem:ash/1D-scatter

1D Scatter Layer Test #25071

This PR introduces parametrized test for `Scatter` layer to test its functionality for 1D arrays


### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
pull/25369/head
Abduragim Shtanchaev 10 months ago committed by GitHub
parent 2e784bc7e6
commit 22b1b1edac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 50
      modules/dnn/test/test_layers_1d.cpp

@ -430,4 +430,54 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Softmax_Test, Combine(
testing::Values(0, 1)
));
typedef testing::TestWithParam<tuple<std::vector<int>, std::string>> Layer_Scatter_Test;
TEST_P(Layer_Scatter_Test, Accuracy1D) {
std::vector<int> input_shape = get<0>(GetParam());
std::string opr = get<1>(GetParam());
LayerParams lp;
lp.type = "Scatter";
lp.name = "addLayer";
lp.set("axis", 0);
lp.set("reduction", opr);
Ptr<ScatterLayer> layer = ScatterLayer::create(lp);
cv::Mat input = cv::Mat(input_shape.size(), input_shape.data(), CV_32F);
cv::randn(input, 0.0, 1.0);
int indices[] = {3, 2, 1, 0};
cv::Mat indices_mat(input_shape.size(), input_shape.data(), CV_32S, indices);
cv::Mat output(input_shape.size(), input_shape.data(), CV_32F, 0.0);
// create reference output
cv::Mat output_ref(input_shape, CV_32F, 0.0);
for (int i = 0; i < input_shape[0]; i++){
output_ref.at<float>(indices[i]) = input.at<float>(i);
}
if (opr == "add"){
output_ref += output;
} else if (opr == "mul"){
output_ref = output.mul(output_ref);
} else if (opr == "max"){
cv::max(output_ref, output, output_ref);
} else if (opr == "min"){
cv::min(output_ref, output, output_ref);
}
std::vector<Mat> inputs{output, indices_mat, input};
std::vector<Mat> outputs;
runLayer(layer, inputs, outputs);
ASSERT_EQ(outputs.size(), 1);
ASSERT_EQ(shape(output_ref), shape(outputs[0]));
}
INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine(
/*input blob shape*/ testing::Values(std::vector<int>{4},
std::vector<int>{1, 4}),
/*reduce*/ Values("none", "add", "mul", "max", "min")
));
}}

Loading…
Cancel
Save