Space to depth - refactor reference implementation (#6374)
* extract SpaceToDepth implementation from op class to reference file * move backend test from fused_op.in.cpp to space_to_depth.in.cpp * Cleanup reference implementation * Extend SpaceToDepth backend tests * add SpaceToDepth to verified ops
This commit is contained in:
committed by
GitHub
parent
f1af26dbaf
commit
d4c2b27100
@@ -287,6 +287,7 @@ set(SRC
|
||||
visitors/op/rnn_cell.cpp
|
||||
visitors/op/roi_pooling.cpp
|
||||
visitors/op/round.cpp
|
||||
visitors/op/space_to_depth.cpp
|
||||
visitors/op/selu.cpp
|
||||
visitors/op/shuffle_channels.cpp
|
||||
visitors/op/softmax.cpp
|
||||
@@ -464,6 +465,7 @@ set(MULTI_TEST_SRC
|
||||
backend/roll.in.cpp
|
||||
backend/round.in.cpp
|
||||
backend/scatter_nd_update.in.cpp
|
||||
backend/space_to_depth.in.cpp
|
||||
backend/select.in.cpp
|
||||
backend/selu.in.cpp
|
||||
backend/shape_of.in.cpp
|
||||
@@ -673,4 +675,3 @@ if (NGRAPH_PDPD_FRONTEND_ENABLE AND PDPD_PYTHON_OK)
|
||||
add_dependencies(unit-test pdpd_test_models)
|
||||
add_dependencies(unit-test paddlepaddle_ngraph_frontend)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -78,46 +78,6 @@ NGRAPH_TEST(${BACKEND_NAME}, hardsigmoid)
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_block_first)
|
||||
{
|
||||
auto A = make_shared<op::Parameter>(element::f32, Shape{1, 2, 4, 4});
|
||||
const auto mode = ngraph::op::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST;
|
||||
auto space_to_depth = make_shared<op::SpaceToDepth>(A, mode, 2);
|
||||
auto function = make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
test_case.add_input<float>({0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f,
|
||||
11.f, 12.f, 13.f, 14.f, 15.f, 16.f, 17.f, 18.f, 19.f, 20.f, 21.f,
|
||||
22.f, 23.f, 24.f, 25.f, 26.f, 27.f, 28.f, 29.f, 30.f, 31.f});
|
||||
test_case.add_expected_output<float>(Shape{1, 8, 2, 2},
|
||||
{
|
||||
0.f, 2.f, 8.f, 10.f, 16.f, 18.f, 24.f, 26.f,
|
||||
1.f, 3.f, 9.f, 11.f, 17.f, 19.f, 25.f, 27.f,
|
||||
4.f, 6.f, 12.f, 14.f, 20.f, 22.f, 28.f, 30.f,
|
||||
5.f, 7.f, 13.f, 15.f, 21.f, 23.f, 29.f, 31.f,
|
||||
});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_depth_first)
|
||||
{
|
||||
auto A = make_shared<op::Parameter>(element::f32, Shape{1, 2, 4, 4});
|
||||
const auto mode = ngraph::op::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST;
|
||||
auto space_to_depth = make_shared<op::SpaceToDepth>(A, mode, 2);
|
||||
auto function = make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
test_case.add_input<float>({0.f, 16.f, 2.f, 18.f, 1.f, 17.f, 3.f, 19.f, 8.f, 24.f, 10.f,
|
||||
26.f, 9.f, 25.f, 11.f, 27.f, 4.f, 20.f, 6.f, 22.f, 5.f, 21.f,
|
||||
7.f, 23.f, 12.f, 28.f, 14.f, 30.f, 13.f, 29.f, 15.f, 31.f});
|
||||
test_case.add_expected_output<float>(
|
||||
Shape{1, 8, 2, 2}, {0.f, 2.f, 8.f, 10.f, 16.f, 18.f, 24.f, 26.f, 1.f, 3.f, 9.f,
|
||||
11.f, 17.f, 19.f, 25.f, 27.f, 4.f, 6.f, 12.f, 14.f, 20.f, 22.f,
|
||||
28.f, 30.f, 5.f, 7.f, 13.f, 15.f, 21.f, 23.f, 29.f, 31.f});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
// TODO: Issue: 37521
|
||||
NGRAPH_TEST(${BACKEND_NAME}, DISABLED_normalize_across_chw_4d)
|
||||
{
|
||||
|
||||
120
ngraph/test/backend/space_to_depth.in.cpp
Normal file
120
ngraph/test/backend/space_to_depth.in.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "ngraph/op/space_to_depth.hpp"
|
||||
#include "util/engine/test_engines.hpp"
|
||||
#include "util/test_case.hpp"
|
||||
#include "util/test_control.hpp"
|
||||
|
||||
using namespace ngraph;
|
||||
|
||||
static std::string s_manifest = "${MANIFEST}";
|
||||
|
||||
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_block_first_K2_BS2)
|
||||
{
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 4, 4});
|
||||
const auto mode = op::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST;
|
||||
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 2);
|
||||
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
test_case.add_input<float>({0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f,
|
||||
11.f, 12.f, 13.f, 14.f, 15.f, 16.f, 17.f, 18.f, 19.f, 20.f, 21.f,
|
||||
22.f, 23.f, 24.f, 25.f, 26.f, 27.f, 28.f, 29.f, 30.f, 31.f});
|
||||
test_case.add_expected_output<float>(
|
||||
Shape{1, 8, 2, 2}, {0.f, 2.f, 8.f, 10.f, 16.f, 18.f, 24.f, 26.f, 1.f, 3.f, 9.f,
|
||||
11.f, 17.f, 19.f, 25.f, 27.f, 4.f, 6.f, 12.f, 14.f, 20.f, 22.f,
|
||||
28.f, 30.f, 5.f, 7.f, 13.f, 15.f, 21.f, 23.f, 29.f, 31.f});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_block_first_K2_BS3)
|
||||
{
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 6, 3});
|
||||
const auto mode = op::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST;
|
||||
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 3);
|
||||
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
test_case.add_input<float>({0.f, 4.f, 8.f, 12.f, 16.f, 20.f, 24.f, 28.f, 32.f,
|
||||
1.f, 5.f, 9.f, 13.f, 17.f, 21.f, 25.f, 29.f, 33.f,
|
||||
2.f, 6.f, 10.f, 14.f, 18.f, 22.f, 26.f, 30.f, 34.f,
|
||||
3.f, 7.f, 11.f, 15.f, 19.f, 23.f, 27.f, 31.f, 35.f});
|
||||
test_case.add_expected_output<float>(Shape{1, 18, 2, 1},
|
||||
{0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f,
|
||||
9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f, 16.f, 17.f,
|
||||
18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f, 25.f, 26.f,
|
||||
27.f, 28.f, 29.f, 30.f, 31.f, 32.f, 33.f, 34.f, 35.f});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_block_first_K1_BS3)
|
||||
{
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 6});
|
||||
const auto mode = op::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST;
|
||||
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 3);
|
||||
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
test_case.add_input<float>({0.f, 4.f, 8.f, 1.f, 5.f, 9.f, 2.f, 6.f, 10.f, 3.f, 7.f, 11.f});
|
||||
test_case.add_expected_output<float>(
|
||||
Shape{1, 6, 2}, {0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_depth_first_K2_BS2)
|
||||
{
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 4, 4});
|
||||
const auto mode = op::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST;
|
||||
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 2);
|
||||
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
test_case.add_input<float>({0.f, 16.f, 2.f, 18.f, 1.f, 17.f, 3.f, 19.f, 8.f, 24.f, 10.f,
|
||||
26.f, 9.f, 25.f, 11.f, 27.f, 4.f, 20.f, 6.f, 22.f, 5.f, 21.f,
|
||||
7.f, 23.f, 12.f, 28.f, 14.f, 30.f, 13.f, 29.f, 15.f, 31.f});
|
||||
test_case.add_expected_output<float>(
|
||||
Shape{1, 8, 2, 2}, {0.f, 2.f, 8.f, 10.f, 16.f, 18.f, 24.f, 26.f, 1.f, 3.f, 9.f,
|
||||
11.f, 17.f, 19.f, 25.f, 27.f, 4.f, 6.f, 12.f, 14.f, 20.f, 22.f,
|
||||
28.f, 30.f, 5.f, 7.f, 13.f, 15.f, 21.f, 23.f, 29.f, 31.f});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_depth_first_K2_BS3)
|
||||
{
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 6, 3});
|
||||
const auto mode = op::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST;
|
||||
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 3);
|
||||
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
test_case.add_input<float>({0.f, 2.f, 4.f, 6.f, 8.f, 10.f, 12.f, 14.f, 16.f,
|
||||
1.f, 3.f, 5.f, 7.f, 9.f, 11.f, 13.f, 15.f, 17.f,
|
||||
18.f, 20.f, 22.f, 24.f, 26.f, 28.f, 30.f, 32.f, 34.f,
|
||||
19.f, 21.f, 23.f, 25.f, 27.f, 29.f, 31.f, 33.f, 35.f});
|
||||
test_case.add_expected_output<float>(Shape{1, 18, 2, 1},
|
||||
{0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f,
|
||||
9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f, 16.f, 17.f,
|
||||
18.f, 19.f, 20.f, 21.f, 22.f, 23.f, 24.f, 25.f, 26.f,
|
||||
27.f, 28.f, 29.f, 30.f, 31.f, 32.f, 33.f, 34.f, 35.f});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, space_to_depth_depth_first_K1_BS3)
|
||||
{
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, Shape{1, 2, 6});
|
||||
const auto mode = op::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST;
|
||||
auto space_to_depth = std::make_shared<op::SpaceToDepth>(A, mode, 3);
|
||||
auto function = std::make_shared<Function>(NodeVector{space_to_depth}, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
test_case.add_input<float>({0.f, 2.f, 4.f, 1.f, 3.f, 5.f, 6.f, 8.f, 10.f, 7.f, 9.f, 11.f});
|
||||
test_case.add_expected_output<float>(
|
||||
Shape{1, 6, 2}, {0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f});
|
||||
test_case.run();
|
||||
}
|
||||
@@ -22,12 +22,19 @@ TEST(attributes, space_to_depth_op)
|
||||
{
|
||||
NodeBuilder::get_ops().register_factory<opset1::SpaceToDepth>();
|
||||
auto data = make_shared<op::Parameter>(element::i32, Shape{2, 3, 50, 50});
|
||||
|
||||
auto block_size = 2;
|
||||
auto mode = opset1::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST;
|
||||
|
||||
auto space_to_depth = make_shared<opset1::SpaceToDepth>(data, mode, block_size);
|
||||
NodeBuilder builder(space_to_depth);
|
||||
auto g_space_to_depth = as_type_ptr<opset1::SpaceToDepth>(builder.create());
|
||||
|
||||
// attribute count
|
||||
const auto expected_attr_count = 2;
|
||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
||||
|
||||
// space_to_depth attributes
|
||||
EXPECT_EQ(g_space_to_depth->get_block_size(), space_to_depth->get_block_size());
|
||||
EXPECT_EQ(g_space_to_depth->get_mode(), space_to_depth->get_mode());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user