TransposeLayerTest to API2.0 (#19671)

This commit is contained in:
Vitaliy Urusovskij 2023-09-11 16:15:53 +04:00 committed by GitHub
parent 9f4e918ee2
commit 847eb3f4f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 131 additions and 46 deletions

View File

@ -4,57 +4,49 @@
#include <vector>
#include "single_layer_tests/transpose.hpp"
#include "single_op_tests/transpose.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using ov::test::TransposeLayerTest;
namespace {
const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I64,
InferenceEngine::Precision::I32,
InferenceEngine::Precision::I16,
InferenceEngine::Precision::I8,
InferenceEngine::Precision::U8,
const std::vector<ov::element::Type> model_types = {
ov::element::f32,
ov::element::f16,
ov::element::i64,
ov::element::i32,
ov::element::i16,
ov::element::i8,
ov::element::u8,
};
std::vector<std::vector<size_t>> inputShape2D = {{2, 10}, {10, 2}, {10, 10}};
std::vector<std::vector<size_t>> order2D = {{0, 1}, {1, 0}};
std::vector<std::vector<ov::Shape>> input_shape_static_2D = {{{2, 10}}, {{10, 2}}, {{10, 10}}};
std::vector<std::vector<size_t>> order_2D = {{0, 1}, {1, 0}};
INSTANTIATE_TEST_SUITE_P(smoke_Transpose2D, TransposeLayerTest,
::testing::Combine(
::testing::ValuesIn(order2D),
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::ValuesIn(inputShape2D),
::testing::ValuesIn(order_2D),
::testing::ValuesIn(model_types),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shape_static_2D)),
::testing::Values(ov::test::utils::DEVICE_CPU)),
TransposeLayerTest::getTestCaseName);
std::vector<std::vector<size_t>> inputShape4D = {{2, 2, 2, 2}, {1, 10, 2, 3}, {2, 3, 4, 5}};
std::vector<std::vector<size_t>> order4D = {
std::vector<std::vector<ov::Shape>> input_shape_static_4D = {{{2, 2, 2, 2}}, {{1, 10, 2, 3}}, {{2, 3, 4, 5}}};
std::vector<std::vector<size_t>> order_4D = {
{0, 1, 2, 3}, {0, 1, 3, 2}, {0, 2, 1, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}, {0, 3, 2, 1}, {1, 0, 2, 3}, {1, 0, 3, 2},
{1, 2, 0, 3}, {1, 2, 3, 0}, {1, 3, 0, 2}, {1, 3, 2, 0}, {2, 0, 1, 3}, {2, 0, 3, 1}, {2, 1, 0, 3}, {2, 1, 3, 0},
{2, 3, 0, 1}, {2, 3, 1, 0}, {3, 0, 1, 2}, {3, 0, 2, 1}, {3, 1, 0, 2}, {3, 1, 2, 0}, {3, 2, 0, 1}, {3, 2, 1, 0}};
INSTANTIATE_TEST_SUITE_P(smoke_Transpose4D, TransposeLayerTest,
::testing::Combine(
::testing::ValuesIn(order4D),
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::ValuesIn(inputShape4D),
::testing::ValuesIn(order_4D),
::testing::ValuesIn(model_types),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shape_static_4D)),
::testing::Values(ov::test::utils::DEVICE_CPU)),
TransposeLayerTest::getTestCaseName);
std::vector<std::vector<size_t>> inputShape5D = {{2, 2, 2, 2, 2}, {1, 10, 2, 3, 4}, {2, 3, 4, 5, 6}};
std::vector<std::vector<size_t>> order5D = {
std::vector<std::vector<ov::Shape>> input_shape_static_5D = {{{2, 2, 2, 2, 2}}, {{1, 10, 2, 3, 4}}, {{2, 3, 4, 5, 6}}};
std::vector<std::vector<size_t>> order_5D = {
{0, 1, 2, 3, 4},
{1, 0, 2, 3, 4},
{4, 3, 2, 1, 0},
@ -68,18 +60,14 @@ std::vector<std::vector<size_t>> order5D = {
INSTANTIATE_TEST_SUITE_P(smoke_Transpose5D, TransposeLayerTest,
::testing::Combine(
::testing::ValuesIn(order5D),
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::ValuesIn(inputShape5D),
::testing::ValuesIn(order_5D),
::testing::ValuesIn(model_types),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shape_static_5D)),
::testing::Values(ov::test::utils::DEVICE_CPU)),
TransposeLayerTest::getTestCaseName);
std::vector<std::vector<size_t>> inputShape6D = {{2, 2, 2, 2, 2, 2}, {1, 10, 2, 3, 4, 5}, {2, 3, 4, 5, 6, 7}};
std::vector<std::vector<size_t>> order6D = {
std::vector<std::vector<ov::Shape>> input_shape_static_6D = {{{2, 2, 2, 2, 2, 2}}, {{1, 10, 2, 3, 4, 5}}, {{2, 3, 4, 5, 6, 7}}};
std::vector<std::vector<size_t>> order_6D = {
{0, 1, 2, 3, 4, 5},
{1, 0, 2, 3, 4, 5},
{5, 4, 3, 2, 1, 0},
@ -93,13 +81,9 @@ std::vector<std::vector<size_t>> order6D = {
INSTANTIATE_TEST_SUITE_P(smoke_Transpose6D, TransposeLayerTest,
::testing::Combine(
::testing::ValuesIn(order6D),
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::ValuesIn(inputShape6D),
::testing::ValuesIn(order_6D),
::testing::ValuesIn(model_types),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shape_static_6D)),
::testing::Values(ov::test::utils::DEVICE_CPU)),
TransposeLayerTest::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/transpose.hpp"
namespace ov {
namespace test {
TEST_P(TransposeLayerTest, Inference) {
run();
};
} // 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 <tuple>
#include <string>
#include <vector>
#include <memory>
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace ov {
namespace test {
typedef std::tuple<
std::vector<size_t>, // Input order
ov::element::Type, // Model type
std::vector<InputShape>, // Input shapes
std::string // Target device name
> transposeParams;
class TransposeLayerTest : public testing::WithParamInterface<transposeParams>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<transposeParams>& obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,54 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/transpose.hpp"
namespace ov {
namespace test {
std::string TransposeLayerTest::getTestCaseName(const testing::TestParamInfo<transposeParams>& obj) {
ov::element::Type modelType;
std::vector<size_t> inputOrder;
std::vector<InputShape> input_shapes;
std::string targetDevice;
std::tie(inputOrder, modelType, input_shapes, targetDevice) = 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 << "inputOrder=" << ov::test::utils::vec2str(inputOrder) << "_";
result << "modelType=" << modelType.to_string() << "_";
result << "trgDev=" << targetDevice;
return result.str();
}
void TransposeLayerTest::SetUp() {
std::vector<size_t> input_order;
std::vector<InputShape> input_shapes;
ov::element::Type model_type;
std::tie(input_order, model_type, input_shapes, targetDevice) = this->GetParam();
init_input_shapes({input_shapes});
auto param = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes.front());
const auto in_order_shape = input_order.empty() ? ov::Shape({0}) : ov::Shape({inputDynamicShapes.front().size()});
const auto input_order_const = std::make_shared<ov::op::v0::Constant>(ov::element::i64,
in_order_shape,
input_order);
const auto transpose = std::make_shared<ov::op::v1::Transpose>(param, input_order_const);
const ov::ResultVector results{std::make_shared<ov::op::v0::Result>(transpose)};
function = std::make_shared<ov::Model>(results, ov::ParameterVector{param}, "Transpose");
}
} // namespace test
} // namespace ov