From d188319b82570aa3845f00b9dec07f5871b0d70d Mon Sep 17 00:00:00 2001 From: Abduragim Shtanchaev <44877829+Abdurrahheem@users.noreply.github.com> Date: Fri, 22 Mar 2024 04:59:08 +0400 Subject: [PATCH] 0D test for Reshape layer (#25206) * reshape test for 0D * fix comments according to PR --- modules/dnn/test/test_layers_1d.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/dnn/test/test_layers_1d.cpp b/modules/dnn/test/test_layers_1d.cpp index c789d1fd10..114900abaf 100644 --- a/modules/dnn/test/test_layers_1d.cpp +++ b/modules/dnn/test/test_layers_1d.cpp @@ -245,4 +245,30 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Elemwise_1d_Test, Combine( /*operation*/ Values("div", "prod", "max", "min", "sum") )); +TEST(Layer_Reshape_Test, Accuracy) +{ + LayerParams lp; + lp.type = "Reshape"; + lp.name = "ReshapeLayer"; + lp.set("axis", 0); // Set axis to 0 to start reshaping from the first dimension + lp.set("num_axes", -1); // Set num_axes to -1 to indicate all following axes are included in the reshape + int newShape[] = {1}; + lp.set("dim", DictValue::arrayInt(newShape, 1)); + + Ptr layer = ReshapeLayer::create(lp); + + std::vector input_shape = {0}; + + Mat input(0, input_shape.data(), CV_32F); + randn(input, 0.0, 1.0); + Mat output_ref(1, newShape, CV_32F, input.data); + + std::vector inputs{input}; + std::vector outputs; + + runLayer(layer, inputs, outputs); + ASSERT_EQ(shape(output_ref), shape(outputs[0])); + normAssert(output_ref, outputs[0]); +} + }}