From 5319772a565228f5d25a55d607b5f52102f960ae Mon Sep 17 00:00:00 2001 From: Abduragim Shtanchaev <44877829+Abdurrahheem@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:13:41 +0400 Subject: [PATCH] Merge pull request #25205 from Abdurrahheem:ash/0D-split-test 0D test for split layer #25205 This PR introduces parametrized `0/1D` input support test for `Split` layer. ### 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 --- modules/dnn/test/test_layers_1d.cpp | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/modules/dnn/test/test_layers_1d.cpp b/modules/dnn/test/test_layers_1d.cpp index 114900abaf..3f734a53a6 100644 --- a/modules/dnn/test/test_layers_1d.cpp +++ b/modules/dnn/test/test_layers_1d.cpp @@ -271,4 +271,40 @@ TEST(Layer_Reshape_Test, Accuracy) normAssert(output_ref, outputs[0]); } +typedef testing::TestWithParam>> Layer_Split_Test; +TEST_P(Layer_Split_Test, Accuracy_01D) +{ + LayerParams lp; + lp.type = "Split"; + lp.name = "SplitLayer"; + int top_count = 2; // 2 is for simplicity + lp.set("top_count", top_count); + Ptr layer = SplitLayer::create(lp); + + std::vector input_shape = std::get<0>(GetParam()); + + Mat input(input_shape.size(), input_shape.data(), CV_32F); + cv::randn(input, 0.0, 1.0); + + Mat output_ref = Mat(input_shape.size(), input_shape.data(), CV_32F, input.data); + + std::vector inputs{input}; + std::vector outputs; + runLayer(layer, inputs, outputs); + for (int i = 0; i < top_count; i++) + { + ASSERT_EQ(shape(output_ref), shape(outputs[i])); + normAssert(output_ref, outputs[i]); + } +} +INSTANTIATE_TEST_CASE_P(/*nothting*/, Layer_Split_Test, + testing::Values( + std::vector({}), + std::vector({1}), + std::vector({1, 4}), + std::vector({1, 5}), + std::vector({4, 1}), + std::vector({4, 5}) +)); + }}