Split, SpaceToDepth, SpaceToBatch layer tests to API2.0 (#19973)

* `SplitLayerTest` to API2.0

* `SpaceToDepthLayerTest` to API2.0

* `SpaceToBatchLayerTest` to API2.0
This commit is contained in:
Vitaliy Urusovskij 2023-09-21 16:29:30 +04:00 committed by GitHub
parent e277d48535
commit fc9dedfd6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 398 additions and 82 deletions

View File

@ -4,71 +4,65 @@
#include <vector>
#include "single_layer_tests/space_to_batch.hpp"
#include "single_op_tests/space_to_batch.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using ov::test::SpaceToBatchLayerTest;
namespace {
const std::vector<std::vector<int64_t >> blockShapes4D {
const std::vector<std::vector<int64_t>> block_shapes_4D {
{1, 1, 2, 2}
};
const std::vector<std::vector<int64_t >> padsBegins4D {
const std::vector<std::vector<int64_t>> pads_begins_4D {
{0, 0, 0, 0}, {0, 0, 0, 2}
};
const std::vector<std::vector<int64_t >> padsEnds4D {
const std::vector<std::vector<int64_t>> pads_ends_4D {
{0, 0, 0, 0}, {0, 0, 0, 2}
};
const std::vector<std::vector<size_t >> dataShapes4D {
{1, 1, 2, 2}, {1, 3, 2, 2}, {1, 1, 4, 4}, {2, 1, 2, 4}
};
const auto data_shapes_4D = ov::test::static_shapes_to_test_representation(
std::vector<std::vector<ov::Shape>>{
{{1, 1, 2, 2}}, {{1, 3, 2, 2}}, {{1, 1, 4, 4}}, {{2, 1, 2, 4}}
});
const auto SpaceToBatch4D = ::testing::Combine(
::testing::ValuesIn(blockShapes4D),
::testing::ValuesIn(padsBegins4D),
::testing::ValuesIn(padsEnds4D),
::testing::ValuesIn(dataShapes4D),
::testing::Values(InferenceEngine::Precision::FP32),
::testing::Values(InferenceEngine::Precision::FP32),
::testing::Values(InferenceEngine::Precision::FP32),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
const auto space_to_batch_4D = ::testing::Combine(
::testing::ValuesIn(block_shapes_4D),
::testing::ValuesIn(pads_begins_4D),
::testing::ValuesIn(pads_ends_4D),
::testing::ValuesIn(data_shapes_4D),
::testing::Values(ov::element::f32),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
INSTANTIATE_TEST_SUITE_P(
smoke_spacetobatch4D, SpaceToBatchLayerTest, SpaceToBatch4D,
smoke_spacetobatch4D, SpaceToBatchLayerTest, space_to_batch_4D,
SpaceToBatchLayerTest::getTestCaseName);
const std::vector<std::vector<int64_t >> blockShapes5D {
const std::vector<std::vector<int64_t>> block_shapes_5D {
{1, 1, 3, 2, 2}
};
const std::vector<std::vector<int64_t >> padsBegins5D {
const std::vector<std::vector<int64_t>> pads_begins_5D {
{0, 0, 1, 0, 3}
};
const std::vector<std::vector<int64_t >> padsEnds5D {
const std::vector<std::vector<int64_t>> pads_ends_5D {
{0, 0, 2, 0, 0}
};
const std::vector<std::vector<size_t >> dataShapes5D {
{1, 1, 3, 2, 1}
};
const auto data_shapes_5D = ov::test::static_shapes_to_test_representation(
std::vector<std::vector<ov::Shape>>{
{{1, 1, 3, 2, 1}}
});
const auto SpaceToBatch5D = ::testing::Combine(
::testing::ValuesIn(blockShapes5D),
::testing::ValuesIn(padsBegins5D),
::testing::ValuesIn(padsEnds5D),
::testing::ValuesIn(dataShapes5D),
::testing::Values(InferenceEngine::Precision::FP32),
::testing::Values(InferenceEngine::Precision::FP32),
::testing::Values(InferenceEngine::Precision::FP32),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
const auto space_to_batch_5D = ::testing::Combine(
::testing::ValuesIn(block_shapes_5D),
::testing::ValuesIn(pads_begins_5D),
::testing::ValuesIn(pads_ends_5D),
::testing::ValuesIn(data_shapes_5D),
::testing::Values(ov::element::f32),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
INSTANTIATE_TEST_SUITE_P(
smoke_spacetobatch5D, SpaceToBatchLayerTest, SpaceToBatch5D,
smoke_spacetobatch5D, SpaceToBatchLayerTest, space_to_batch_5D,
SpaceToBatchLayerTest::getTestCaseName);
} // namespace

View File

@ -3,54 +3,52 @@
//
#include <vector>
#include <ngraph/opsets/opset3.hpp>
#include "single_layer_tests/space_to_depth.hpp"
#include "single_op_tests/space_to_depth.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using namespace ngraph::opset3;
using ov::test::SpaceToDepthLayerTest;
namespace {
const std::vector<InferenceEngine::Precision> inputPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::U8,
InferenceEngine::Precision::I16,
const std::vector<ov::element::Type> model_types = {
ov::element::f32,
ov::element::u8,
ov::element::i16,
};
const std::vector<SpaceToDepth::SpaceToDepthMode> modes = {
SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST,
SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST
const std::vector<ov::op::v0::SpaceToDepth::SpaceToDepthMode> modes = {
ov::op::v0::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST,
ov::op::v0::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST
};
const std::vector<std::vector<size_t >> inputShapesBS2 = {
{1, 1, 2, 2}, {1, 1, 4, 4}, {1, 1, 6, 6}, {2, 8, 6, 6}, {2, 4, 10, 8},
{1, 1, 2, 2, 2}, {1, 1, 4, 4, 4}, {1, 1, 6, 6, 6}, {2, 8, 6, 6, 6}, {2, 4, 10, 8, 12}
};
const auto input_shapes_BS2 = ov::test::static_shapes_to_test_representation(std::vector<std::vector<ov::Shape>>{
{{1, 1, 2, 2}}, {{1, 1, 4, 4}}, {{1, 1, 6, 6}}, {{2, 8, 6, 6}}, {{2, 4, 10, 8}},
{{1, 1, 2, 2, 2}}, {{1, 1, 4, 4, 4}}, {{1, 1, 6, 6, 6}}, {{2, 8, 6, 6, 6}}, {{2, 4, 10, 8, 12}}
});
const auto SpaceToDepthBS2 = ::testing::Combine(
::testing::ValuesIn(inputShapesBS2),
::testing::ValuesIn(inputPrecisions),
const auto space_to_depth_BS2 = ::testing::Combine(
::testing::ValuesIn(input_shapes_BS2),
::testing::ValuesIn(model_types),
::testing::ValuesIn(modes),
::testing::Values(1, 2),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
INSTANTIATE_TEST_SUITE_P(smoke_SpaceToDepthBS2, SpaceToDepthLayerTest, SpaceToDepthBS2, SpaceToDepthLayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_SpaceToDepthBS2, SpaceToDepthLayerTest, space_to_depth_BS2, SpaceToDepthLayerTest::getTestCaseName);
const std::vector<std::vector<size_t >> inputShapesBS3 = {
{1, 1, 3, 3}, {1, 1, 6, 6}, {1, 1, 9, 9}, {2, 4, 9, 9}, {2, 3, 15, 12},
{1, 1, 3, 3, 3}, {1, 1, 6, 6, 6}, {1, 1, 9, 9, 9}, {2, 4, 9, 9, 9}, {2, 3, 15, 12, 18}
};
const auto input_shapes_BS3 = ov::test::static_shapes_to_test_representation(std::vector<std::vector<ov::Shape>>{
{{1, 1, 3, 3}}, {{1, 1, 6, 6}}, {{1, 1, 9, 9}}, {{2, 4, 9, 9}}, {{2, 3, 15, 12}},
{{1, 1, 3, 3, 3}}, {{1, 1, 6, 6, 6}}, {{1, 1, 9, 9, 9}}, {{2, 4, 9, 9, 9}}, {{2, 3, 15, 12, 18}}
});
const auto SpaceToDepthBS3 = ::testing::Combine(
::testing::ValuesIn(inputShapesBS3),
::testing::ValuesIn(inputPrecisions),
const auto space_to_depth_BS3 = ::testing::Combine(
::testing::ValuesIn(input_shapes_BS3),
::testing::ValuesIn(model_types),
::testing::ValuesIn(modes),
::testing::Values(1, 3),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
INSTANTIATE_TEST_SUITE_P(smoke_SpaceToDepthBS3, SpaceToDepthLayerTest, SpaceToDepthBS3, SpaceToDepthLayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_SpaceToDepthBS3, SpaceToDepthLayerTest, space_to_depth_BS3, SpaceToDepthLayerTest::getTestCaseName);
} // namespace

View File

@ -4,30 +4,26 @@
#include <vector>
#include "single_layer_tests/split.hpp"
#include "single_op_tests/split.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using ov::test::SplitLayerTest;
namespace {
const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I32,
InferenceEngine::Precision::U8
const std::vector<ov::element::Type> model_types = {
ov::element::f32,
ov::element::f16,
ov::element::i32,
ov::element::u8
};
INSTANTIATE_TEST_SUITE_P(smoke_NumSplitsCheck, SplitLayerTest,
::testing::Combine(
::testing::Values(1, 2, 3, 5),
::testing::Values(0, 1, 2, 3),
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(std::vector<size_t>({30, 30, 30, 30})),
::testing::ValuesIn(model_types),
::testing::Values(ov::test::static_shapes_to_test_representation({{30, 30, 30, 30}})),
::testing::Values(std::vector<size_t>({})),
::testing::Values(ov::test::utils::DEVICE_CPU)),
SplitLayerTest::getTestCaseName);
@ -36,12 +32,8 @@ INSTANTIATE_TEST_SUITE_P(smoke_splitWithUnusedOutputsTest, SplitLayerTest,
::testing::Combine(
::testing::Values(5),
::testing::Values(0),
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(std::vector<size_t>({30, 30, 30, 30})),
::testing::ValuesIn(model_types),
::testing::Values(ov::test::static_shapes_to_test_representation({{30, 30, 30, 30}})),
::testing::Values(std::vector<size_t>({0, 3})),
::testing::Values(ov::test::utils::DEVICE_CPU)),
SplitLayerTest::getTestCaseName);

View File

@ -0,0 +1,15 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "shared_test_classes/single_op/space_to_batch.hpp"
namespace ov {
namespace test {
TEST_P(SpaceToBatchLayerTest, Inference) {
run();
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,15 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "shared_test_classes/single_op/space_to_depth.hpp"
namespace ov {
namespace test {
TEST_P(SpaceToDepthLayerTest, Inference) {
run();
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,15 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "shared_test_classes/single_op/split.hpp"
namespace ov {
namespace test {
TEST_P(SplitLayerTest, Inference) {
run();
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,33 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <memory>
#include <string>
#include <tuple>
#include <vector>
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace ov {
namespace test {
using spaceToBatchParamsTuple = typename std::tuple<
std::vector<int64_t>, // block_shape
std::vector<int64_t>, // pads_begin
std::vector<int64_t>, // pads_end
std::vector<InputShape>, // Input shapes
ov::element::Type, // Model type
std::string>; // Device name
class SpaceToBatchLayerTest : public testing::WithParamInterface<spaceToBatchParamsTuple>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<spaceToBatchParamsTuple> &obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,32 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <memory>
#include <string>
#include <tuple>
#include <vector>
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace ov {
namespace test {
using spaceToDepthParamsTuple = typename std::tuple<
std::vector<InputShape>, // Input shape
ov::element::Type, // Model type
ov::op::v0::SpaceToDepth::SpaceToDepthMode, // Mode
std::size_t, // Block size
std::string>; // Device name
class SpaceToDepthLayerTest : public testing::WithParamInterface<spaceToDepthParamsTuple>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<spaceToDepthParamsTuple> &obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,34 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <tuple>
#include <string>
#include <vector>
#include <memory>
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace ov {
namespace test {
typedef std::tuple<
size_t, // Num splits
int64_t, // Axis
ov::element::Type, // Model type
std::vector<InputShape>, // Input shapes
std::vector<size_t>, // Used outputs indices
std::string // Target device name
> splitParams;
class SplitLayerTest : public testing::WithParamInterface<splitParams>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<splitParams>& obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,59 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/space_to_batch.hpp"
namespace ov {
namespace test {
std::string SpaceToBatchLayerTest::getTestCaseName(const testing::TestParamInfo<spaceToBatchParamsTuple> &obj) {
std::vector<InputShape> input_shapes;
std::vector<int64_t> block_shapes, pads_begin, pads_end;
ov::element::Type model_type;
std::string target_device;
std::tie(block_shapes, pads_begin, pads_end, input_shapes, model_type, target_device) = obj.param;
std::ostringstream result;
result << "IS=(";
for (size_t i = 0lu; i < input_shapes.size(); i++) {
result << ov::test::utils::partialShape2str({input_shapes[i].first})
<< (i < input_shapes.size() - 1lu ? "_" : "");
}
result << ")_TS=";
for (size_t i = 0lu; i < input_shapes.front().second.size(); i++) {
result << "{";
for (size_t j = 0lu; j < input_shapes.size(); j++) {
result << ov::test::utils::vec2str(input_shapes[j].second[i]) << (j < input_shapes.size() - 1lu ? "_" : "");
}
result << "}_";
}
result << "modelType=" << model_type.to_string() << "_";
result << "BS=" << ov::test::utils::vec2str(block_shapes) << "_";
result << "PB=" << ov::test::utils::vec2str(pads_begin) << "_";
result << "PE=" << ov::test::utils::vec2str(pads_end) << "_";
result << "trgDev=" << target_device;
return result.str();
}
void SpaceToBatchLayerTest::SetUp() {
std::vector<InputShape> input_shapes;
std::vector<int64_t> block_shapes, pads_begin, pads_end;
ov::element::Type model_type;
std::tie(block_shapes, pads_begin, pads_end, input_shapes, model_type, targetDevice) = this->GetParam();
init_input_shapes(input_shapes);
auto param = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes.front());
ov::Shape const_shape = {param->get_partial_shape().size()};
ASSERT_EQ(shape_size(const_shape), block_shapes.size());
ASSERT_EQ(shape_size(const_shape), pads_begin.size());
ASSERT_EQ(shape_size(const_shape), pads_end.size());
auto block_shapes_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, block_shapes.data());
auto pads_begin_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, pads_begin.data());
auto pads_end_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, pads_end.data());
auto s2b = std::make_shared<ov::op::v1::SpaceToBatch>(param, block_shapes_node, pads_begin_node, pads_end_node);
function = std::make_shared<ov::Model>(s2b->outputs(), ov::ParameterVector{param}, "SpaceToBatch");
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,67 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/space_to_depth.hpp"
namespace ov {
namespace test {
using ov::op::v0::SpaceToDepth;
static inline std::string SpaceToDepthModeToString(const SpaceToDepth::SpaceToDepthMode& mode) {
static std::map<SpaceToDepth::SpaceToDepthMode, std::string> names = {
{SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST, "BLOCKS_FIRST"},
{SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST, "DEPTH_FIRST"},
};
auto i = names.find(mode);
if (i != names.end())
return i->second;
else
throw std::runtime_error("Unsupported SpaceToDepthMode");
}
std::string SpaceToDepthLayerTest::getTestCaseName(const testing::TestParamInfo<spaceToDepthParamsTuple> &obj) {
std::vector<InputShape> input_shapes;
SpaceToDepth::SpaceToDepthMode mode;
std::size_t block_size;
ov::element::Type model_type;
std::string target_device;
std::tie(input_shapes, model_type, mode, block_size, target_device) = obj.param;
std::ostringstream result;
result << "IS=(";
for (size_t i = 0lu; i < input_shapes.size(); i++) {
result << ov::test::utils::partialShape2str({input_shapes[i].first})
<< (i < input_shapes.size() - 1lu ? "_" : "");
}
result << ")_TS=";
for (size_t i = 0lu; i < input_shapes.front().second.size(); i++) {
result << "{";
for (size_t j = 0lu; j < input_shapes.size(); j++) {
result << ov::test::utils::vec2str(input_shapes[j].second[i]) << (j < input_shapes.size() - 1lu ? "_" : "");
}
result << "}_";
}
result << "modelType=" << model_type.to_string() << "_";
result << "M=" << SpaceToDepthModeToString(mode) << "_";
result << "BS=" << block_size << "_";
result << "targetDevice=" << target_device << "_";
return result.str();
}
void SpaceToDepthLayerTest::SetUp() {
std::vector<InputShape> input_shapes;
SpaceToDepth::SpaceToDepthMode mode;
std::size_t block_size;
ov::element::Type model_type;
std::tie(input_shapes, model_type, mode, block_size, targetDevice) = this->GetParam();
init_input_shapes(input_shapes);
auto param = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes.front());
auto s2d = std::make_shared<ov::op::v0::SpaceToDepth>(param, mode, block_size);
function = std::make_shared<ov::Model>(s2d->outputs(), ov::ParameterVector{param}, "SpaceToDepth");
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,62 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/split.hpp"
namespace ov {
namespace test {
std::string SplitLayerTest::getTestCaseName(const testing::TestParamInfo<splitParams>& obj) {
size_t num_splits;
int64_t axis;
ov::element::Type model_type;
std::vector<size_t> out_indices;
std::vector<InputShape> input_shapes;
std::string target_device;
std::tie(num_splits, axis, model_type, input_shapes, out_indices, target_device) = obj.param;
std::ostringstream result;
result << "IS=(";
for (size_t i = 0lu; i < input_shapes.size(); i++) {
result << ov::test::utils::partialShape2str({input_shapes[i].first})
<< (i < input_shapes.size() - 1lu ? "_" : "");
}
result << ")_TS=";
for (size_t i = 0lu; i < input_shapes.front().second.size(); i++) {
result << "{";
for (size_t j = 0lu; j < input_shapes.size(); j++) {
result << ov::test::utils::vec2str(input_shapes[j].second[i]) << (j < input_shapes.size() - 1lu ? "_" : "");
}
result << "}_";
}
result << "numSplits=" << num_splits << "_";
result << "axis=" << axis << "_";
if (!out_indices.empty()) {
result << "outIndices" << ov::test::utils::vec2str(out_indices) << "_";
}
result << "IS";
result << "modelType=" << model_type.to_string() << "_";
result << "trgDev=" << target_device;
return result.str();
}
void SplitLayerTest::SetUp() {
size_t num_splits;
int64_t axis;
ov::element::Type model_type;
std::vector<size_t> out_indices;
std::vector<InputShape> input_shapes;
std::tie(num_splits, axis, model_type, input_shapes, out_indices, targetDevice) = this->GetParam();
if (out_indices.empty()) {
for (int i = 0; i < num_splits; ++i)
out_indices.push_back(i);
}
init_input_shapes(input_shapes);
auto param = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes.front());
auto split_axis_op =
std::make_shared<ov::op::v0::Constant>(ov::element::Type_t::i64, ov::Shape{}, std::vector<int64_t>{axis});
auto splitNode = std::make_shared<ov::op::v1::Split>(param, split_axis_op, num_splits);
function = std::make_shared<ov::Model>(splitNode->outputs(), ov::ParameterVector{param}, "Split");
}
} // namespace test
} // namespace ov