Refactor ConversionLayerTest, ConcatLayerTest, ConstantLayerTest, ConvertColorI420LayerTest, ConvertColorNV12LayerTest (#19777)

* Refactor ConversionLayerTest

* Refactor ConcatLayerTest

* Refactor ConstantLayerTest

* Refactor ConvertColorI420LayerTest

* Refactor ConvertColorNV12LayerTest
This commit is contained in:
Oleg Pipikin 2023-09-21 22:56:14 +02:00 committed by GitHub
parent e068cfc5a3
commit b1bf16c7cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 900 additions and 93 deletions

View File

@ -4,15 +4,15 @@
#include <vector>
#include "single_layer_tests/concat.hpp"
#include "single_op_tests/concat.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
namespace {
using ov::test::ConcatLayerTest;
std::vector<int> axes = {-3, -2, -1, 0, 1, 2, 3};
std::vector<std::vector<std::vector<size_t>>> inShapes = {
std::vector<std::vector<ov::Shape>> shapes_static = {
{{10, 10, 10, 10}},
{{10, 10, 10, 10}, {10, 10, 10, 10}},
{{10, 10, 10, 10}, {10, 10, 10, 10}, {10, 10, 10, 10}},
@ -21,19 +21,14 @@ std::vector<std::vector<std::vector<size_t>>> inShapes = {
};
std::vector<InferenceEngine::Precision> netPrecisions = {InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16};
std::vector<ov::element::Type> netPrecisions = {ov::element::f32,
ov::element::f16};
INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, ConcatLayerTest,
::testing::Combine(
::testing::ValuesIn(axes),
::testing::ValuesIn(inShapes),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(shapes_static)),
::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(ov::test::utils::DEVICE_CPU)),
ConcatLayerTest::getTestCaseName);
} // namespace

View File

@ -2,38 +2,34 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "single_layer_tests/constant.hpp"
#include <vector>
#include "single_op_tests/constant.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
namespace {
using ov::test::ConstantLayerTest;
std::vector<std::vector<size_t>> shapes{
std::vector<ov::Shape> shapes{
{2, 2, 3},
{3, 4, 1},
{1, 1, 12},
};
std::vector<InferenceEngine::Precision> precisions{
InferenceEngine::Precision::BF16, InferenceEngine::Precision::FP16,
InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP64,
InferenceEngine::Precision::U4, InferenceEngine::Precision::U8,
InferenceEngine::Precision::U16, InferenceEngine::Precision::U32,
InferenceEngine::Precision::I4, InferenceEngine::Precision::I8,
InferenceEngine::Precision::I16, InferenceEngine::Precision::I32,
std::vector<ov::element::Type> model_types{
ov::element::bf16, ov::element::f16,
ov::element::f32, ov::element::f64,
ov::element::u4, ov::element::u8,
ov::element::u16, ov::element::u32,
ov::element::i4, ov::element::i8,
ov::element::i16, ov::element::i32,
};
std::vector<std::string> data{"0", "1", "2", "3", "4", "5", "6", "7", "0", "1", "2", "3"};
std::vector<InferenceEngine::Precision> precisionsWithNegativeValues{
InferenceEngine::Precision::BF16, InferenceEngine::Precision::FP16,
InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP64,
InferenceEngine::Precision::I4, InferenceEngine::Precision::I8,
InferenceEngine::Precision::I16, InferenceEngine::Precision::I32,
std::vector<ov::element::Type> model_types_with_negative_values{
ov::element::bf16, ov::element::f16,
ov::element::f32, ov::element::f64,
ov::element::i4, ov::element::i8,
ov::element::i16, ov::element::i32,
};
std::vector<std::string> dataWithNegativeValues{"1", "-2", "3", "-4", "5", "-6",
@ -41,13 +37,13 @@ std::vector<std::string> dataWithNegativeValues{"1", "-2", "3", "-4", "5", "-6",
INSTANTIATE_TEST_SUITE_P(smoke_Constant, ConstantLayerTest,
::testing::Combine(::testing::ValuesIn(shapes),
::testing::ValuesIn(precisions), ::testing::Values(data),
::testing::ValuesIn(model_types), ::testing::Values(data),
::testing::Values(ov::test::utils::DEVICE_CPU)),
ConstantLayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_Constant_with_negative_values, ConstantLayerTest,
::testing::Combine(::testing::ValuesIn(shapes),
::testing::ValuesIn(precisionsWithNegativeValues),
::testing::ValuesIn(model_types_with_negative_values),
::testing::Values(dataWithNegativeValues),
::testing::Values(ov::test::utils::DEVICE_CPU)),
ConstantLayerTest::getTestCaseName);

View File

@ -5,48 +5,39 @@
#include <vector>
#include "common_test_utils/test_constants.hpp"
#include "single_layer_tests/conversion.hpp"
using namespace LayerTestsDefinitions;
#include "single_op_tests/conversion.hpp"
namespace {
const std::vector<ngraph::helpers::ConversionTypes> conversionOpTypes = {
ngraph::helpers::ConversionTypes::CONVERT,
ngraph::helpers::ConversionTypes::CONVERT_LIKE,
using ov::test::ConversionLayerTest;
const std::vector<ov::test::utils::ConversionTypes> conversionOpTypes = {
ov::test::utils::ConversionTypes::CONVERT,
ov::test::utils::ConversionTypes::CONVERT_LIKE,
};
const std::vector<std::vector<size_t>> inShape = {{1, 2, 3, 4}};
const std::vector<std::vector<ov::Shape>> shapes = {{{1, 2, 3, 4}}};
const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::U8,
InferenceEngine::Precision::I8,
InferenceEngine::Precision::U16,
InferenceEngine::Precision::I16,
InferenceEngine::Precision::U32,
InferenceEngine::Precision::I32,
InferenceEngine::Precision::U64,
InferenceEngine::Precision::I64,
InferenceEngine::Precision::BF16,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP64,
InferenceEngine::Precision::BOOL,
InferenceEngine::Precision::MIXED,
InferenceEngine::Precision::Q78,
InferenceEngine::Precision::U4,
InferenceEngine::Precision::I4,
InferenceEngine::Precision::BIN,
InferenceEngine::Precision::CUSTOM,
const std::vector<ov::element::Type> types = {
ov::element::u8,
ov::element::i8,
ov::element::u16,
ov::element::i16,
ov::element::u32,
ov::element::i32,
ov::element::u64,
ov::element::i64,
ov::element::bf16,
ov::element::f16,
ov::element::f32,
ov::element::f64,
};
INSTANTIATE_TEST_SUITE_P(smoke_ConversionLayerTest,
ConversionLayerTest,
::testing::Combine(::testing::ValuesIn(conversionOpTypes),
::testing::Values(inShape),
::testing::ValuesIn(netPrecisions),
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::Values(InferenceEngine::Layout::ANY),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(shapes)),
::testing::ValuesIn(types),
::testing::ValuesIn(types),
::testing::Values(ov::test::utils::DEVICE_CPU)),
ConversionLayerTest::getTestCaseName);
} // namespace

View File

@ -4,34 +4,71 @@
#include <vector>
#include "single_layer_tests/convert_color_i420.hpp"
#include "single_op_tests/convert_color_i420.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
namespace {
using ov::test::ConvertColorI420LayerTest;
const std::vector<ov::Shape> inShapes_nhwc = {
const std::vector<ov::Shape> in_shapes = {
{1, 10, 10, 1}
};
auto generate_input_static_shapes = [] (const std::vector<ov::Shape>& original_shapes, bool single_plane) {
std::vector<std::vector<ov::Shape>> result_shapes;
for (const auto& original_shape : original_shapes) {
std::vector<ov::Shape> one_result_shapes;
if (single_plane) {
auto shape = original_shape;
shape[1] = shape[1] * 3 / 2;
one_result_shapes.push_back(shape);
} else {
auto shape = original_shape;
one_result_shapes.push_back(shape);
auto uvShape = ov::Shape{shape[0], shape[1] / 2, shape[2] / 2, 1};
one_result_shapes.push_back(uvShape);
one_result_shapes.push_back(uvShape);
}
result_shapes.push_back(one_result_shapes);
}
return result_shapes;
};
auto in_shapes_single_plain_static = generate_input_static_shapes(in_shapes, true);
auto in_shapes_not_single_plain_static = generate_input_static_shapes(in_shapes, false);
const std::vector<ov::element::Type> inTypes = {
ov::element::u8, ov::element::f32
};
const auto testCase_values = ::testing::Combine(
::testing::ValuesIn(inShapes_nhwc),
const auto test_case_values_single_plain = ::testing::Combine(
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_single_plain_static)),
::testing::ValuesIn(inTypes),
::testing::Bool(),
::testing::Bool(),
::testing::Values(true),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
const auto test_case_values_not_single_plain = ::testing::Combine(
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_not_single_plain_static)),
::testing::ValuesIn(inTypes),
::testing::Bool(),
::testing::Values(false),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorI420, ConvertColorI420LayerTest, testCase_values, ConvertColorI420LayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorI420SinglePlain,
ConvertColorI420LayerTest,
test_case_values_single_plain,
ConvertColorI420LayerTest::getTestCaseName);
const auto testCase_accuracy_values = ::testing::Combine(
::testing::Values(ov::Shape{1, 16*6, 16, 1}),
INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorI420NotSinglePlain,
ConvertColorI420LayerTest,
test_case_values_not_single_plain,
ConvertColorI420LayerTest::getTestCaseName);
const auto test_case_accuracy_values = ::testing::Combine(
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(generate_input_static_shapes({{1, 16*6, 16, 1}}, true))),
::testing::Values(ov::element::u8),
::testing::Values(false),
::testing::Values(true),
@ -39,12 +76,12 @@ const auto testCase_accuracy_values = ::testing::Combine(
);
INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorI420_acc,
ConvertColorI420AccuracyTest,
testCase_accuracy_values,
ConvertColorI420LayerTest,
test_case_accuracy_values,
ConvertColorI420LayerTest::getTestCaseName);
const auto testCase_accuracy_values_nightly = ::testing::Combine(
::testing::Values(ov::Shape{1, 256*256, 256, 1}),
const auto test_case_accuracy_values_nightly = ::testing::Combine(
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(generate_input_static_shapes({{1, 256*256, 256, 1}}, true))),
::testing::Values(ov::element::u8),
::testing::Values(false),
::testing::Values(true),
@ -52,8 +89,8 @@ const auto testCase_accuracy_values_nightly = ::testing::Combine(
);
INSTANTIATE_TEST_SUITE_P(nightly_TestsConvertColorI420_acc,
ConvertColorI420AccuracyTest,
testCase_accuracy_values_nightly,
ConvertColorI420LayerTest,
test_case_accuracy_values_nightly,
ConvertColorI420LayerTest::getTestCaseName);
} // namespace

View File

@ -4,34 +4,70 @@
#include <vector>
#include "single_layer_tests/convert_color_nv12.hpp"
#include "single_op_tests/convert_color_nv12.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
namespace {
using ov::test::ConvertColorNV12LayerTest;
const std::vector<ov::Shape> inShapes_nhwc = {
const std::vector<ov::Shape> in_shapes = {
{1, 10, 10, 1}
};
auto generate_input_static_shapes = [] (const std::vector<ov::Shape>& original_shapes, bool single_plane) {
std::vector<std::vector<ov::Shape>> result_shapes;
for (const auto& original_shape : original_shapes) {
std::vector<ov::Shape> one_result_shapes;
if (single_plane) {
auto shape = original_shape;
shape[1] = shape[1] * 3 / 2;
one_result_shapes.push_back(shape);
} else {
auto shape = original_shape;
one_result_shapes.push_back(shape);
auto uvShape = ov::Shape{shape[0], shape[1] / 2, shape[2] / 2, 2};
one_result_shapes.push_back(uvShape);
}
result_shapes.push_back(one_result_shapes);
}
return result_shapes;
};
auto in_shapes_single_plain_static = generate_input_static_shapes(in_shapes, true);
auto in_shapes_not_single_plain_static = generate_input_static_shapes(in_shapes, false);
const std::vector<ov::element::Type> inTypes = {
ov::element::u8, ov::element::f32
};
const auto testCase_values = ::testing::Combine(
::testing::ValuesIn(inShapes_nhwc),
const auto test_case_values_single_plain = ::testing::Combine(
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_single_plain_static)),
::testing::ValuesIn(inTypes),
::testing::Bool(),
::testing::Bool(),
::testing::Values(true),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
const auto test_case_values_not_single_plain = ::testing::Combine(
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(in_shapes_not_single_plain_static)),
::testing::ValuesIn(inTypes),
::testing::Bool(),
::testing::Values(false),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorNV12, ConvertColorNV12LayerTest, testCase_values, ConvertColorNV12LayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorNV12_1Plain,
ConvertColorNV12LayerTest,
test_case_values_single_plain,
ConvertColorNV12LayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorNV12_3Plains,
ConvertColorNV12LayerTest,
test_case_values_not_single_plain,
ConvertColorNV12LayerTest::getTestCaseName);
const auto testCase_accuracy_values = ::testing::Combine(
::testing::Values(ov::Shape{1, 16*6, 16, 1}),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(generate_input_static_shapes({{1, 16*6, 16, 1}}, true))),
::testing::Values(ov::element::u8),
::testing::Values(false),
::testing::Values(true),
@ -39,12 +75,12 @@ const auto testCase_accuracy_values = ::testing::Combine(
);
INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorNV12_acc,
ConvertColorNV12AccuracyTest,
ConvertColorNV12LayerTest,
testCase_accuracy_values,
ConvertColorNV12LayerTest::getTestCaseName);
const auto testCase_accuracy_values_nightly = ::testing::Combine(
::testing::Values(ov::Shape{1, 256*256, 256, 1}),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(generate_input_static_shapes({{1, 256*256, 256, 1}}, true))),
::testing::Values(ov::element::u8),
::testing::Values(false),
::testing::Values(true),
@ -52,7 +88,7 @@ const auto testCase_accuracy_values_nightly = ::testing::Combine(
);
INSTANTIATE_TEST_SUITE_P(nightly_TestsConvertColorNV12_acc,
ConvertColorNV12AccuracyTest,
ConvertColorNV12LayerTest,
testCase_accuracy_values_nightly,
ConvertColorNV12LayerTest::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/concat.hpp"
namespace ov {
namespace test {
TEST_P(ConcatLayerTest, 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/constant.hpp"
namespace ov {
namespace test {
TEST_P(ConstantLayerTest, 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/conversion.hpp"
namespace ov {
namespace test {
TEST_P(ConversionLayerTest, 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/convert_color_i420.hpp"
namespace ov {
namespace test {
TEST_P(ConvertColorI420LayerTest, 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/convert_color_nv12.hpp"
namespace ov {
namespace test {
TEST_P(ConvertColorNV12LayerTest, 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 {
using concatParamsTuple = typename std::tuple<
int, // Concat axis
std::vector<InputShape>, // Input shapes
ov::element::Type, // Model type
std::string>; // Device name
// Multichannel
class ConcatLayerTest : public testing::WithParamInterface<concatParamsTuple>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<concatParamsTuple> &obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,30 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <string>
#include <tuple>
#include <vector>
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace ov {
namespace test {
using constantParamsTuple = typename std::tuple<
ov::Shape, // Constant data shape
ov::element::Type, // Constant data precision
std::vector<std::string>, // Constant elements
std::string>; // Device name
class ConstantLayerTest : public testing::WithParamInterface<constantParamsTuple>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<constantParamsTuple> &obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,30 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <map>
#include "gtest/gtest.h"
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "common_test_utils/test_enums.hpp"
namespace ov {
namespace test {
using ConversionParamsTuple = typename std::tuple<ov::test::utils::ConversionTypes, // Convertion op type
std::vector<InputShape>, // Input shapes
ov::element::Type, // Input type
ov::element::Type, // Convert type
std::string>; // Device name
class ConversionLayerTest : public testing::WithParamInterface<ConversionParamsTuple>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<ConversionParamsTuple>& obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,30 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <tuple>
#include <string>
#include <vector>
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace ov {
namespace test {
using ConvertColorI420ParamsTuple = std::tuple<
std::vector<InputShape>, // Input Shape
ov::element::Type, // Element type
bool, // Conversion type
bool, // 1 or 3 planes
std::string>; // Device name
class ConvertColorI420LayerTest : public testing::WithParamInterface<ConvertColorI420ParamsTuple>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<ConvertColorI420ParamsTuple> &obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,31 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <tuple>
#include <string>
#include <vector>
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace ov {
namespace test {
using ConvertColorNV12ParamsTuple = std::tuple<
std::vector<InputShape>, // Input Shape
ov::element::Type, // Element type
bool, // Conversion type
bool, // 1 or 2 planes
std::string>; // Device name
class ConvertColorNV12LayerTest : public testing::WithParamInterface<ConvertColorNV12ParamsTuple>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<ConvertColorNV12ParamsTuple> &obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -54,6 +54,104 @@ void compare(const std::shared_ptr<ov::op::v0::DetectionOutput> &node,
ov::test::utils::compare(expected, actual, 1e-2f, relThreshold);
}
namespace color_conversion {
template <typename T>
inline void validate_colors(const T* expected, const T* actual, size_t size, float dev_threshold, float abs_threshold = 0.01f) {
size_t mismatches = 0;
for (size_t i = 0; i < size; i++) {
if (std::abs(static_cast<float>(expected[i] - actual[i])) > abs_threshold) {
mismatches++;
}
}
ASSERT_LT(mismatches / size, dev_threshold) << mismatches <<
" out of " << size << " color mismatches found which exceeds allowed threshold " << dev_threshold;
}
inline void validate_colors(const ov::Tensor& expected, const ov::Tensor& actual, float dev_threshold, float abs_threshold = 0.01f) {
OPENVINO_ASSERT(expected.get_size() == actual.get_size());
OPENVINO_ASSERT(expected.get_element_type() == actual.get_element_type());
#define CASE(X) \
case X: \
validate_colors( \
static_cast<ov::fundamental_type_for<X>*>(expected.data()), \
static_cast<ov::fundamental_type_for<X>*>(actual.data()), \
expected.get_size(), \
dev_threshold, \
abs_threshold); \
break;
switch (expected.get_element_type()) {
CASE(ov::element::Type_t::i8)
CASE(ov::element::Type_t::i16)
CASE(ov::element::Type_t::i32)
CASE(ov::element::Type_t::i64)
CASE(ov::element::Type_t::u8)
CASE(ov::element::Type_t::u16)
CASE(ov::element::Type_t::u32)
CASE(ov::element::Type_t::u64)
CASE(ov::element::Type_t::bf16)
CASE(ov::element::Type_t::f16)
CASE(ov::element::Type_t::f32)
CASE(ov::element::Type_t::f64)
default:
OPENVINO_THROW("Unsupported element type: ", expected.get_element_type());
}
#undef CASE
}
} // namespace color_conversion
void compare(const std::shared_ptr<ov::op::v8::I420toRGB> &node,
size_t port,
const ov::runtime::Tensor &expected,
const ov::runtime::Tensor &actual,
double absThreshold,
double relThreshold) {
ov::test::utils::compare(expected, actual, absThreshold, relThreshold);
// Allow less than 2% of deviations with 1 color step. 2% is experimental value
// For different calculation methods - 1.4% deviation is observed
color_conversion::validate_colors(expected, actual, 0.02);
}
void compare(const std::shared_ptr<ov::op::v8::I420toBGR> &node,
size_t port,
const ov::runtime::Tensor &expected,
const ov::runtime::Tensor &actual,
double absThreshold,
double relThreshold) {
ov::test::utils::compare(expected, actual, absThreshold, relThreshold);
// Allow less than 2% of deviations with 1 color step. 2% is experimental value
// For different calculation methods - 1.4% deviation is observed
color_conversion::validate_colors(expected, actual, 0.02);
}
void compare(const std::shared_ptr<ov::op::v8::NV12toRGB> &node,
size_t port,
const ov::runtime::Tensor &expected,
const ov::runtime::Tensor &actual,
double absThreshold,
double relThreshold) {
ov::test::utils::compare(expected, actual, absThreshold, relThreshold);
// Allow less than 2% of deviations with 1 color step. 2% is experimental value
// For different calculation methods - 1.4% deviation is observed
color_conversion::validate_colors(expected, actual, 0.02);
}
void compare(const std::shared_ptr<ov::op::v8::NV12toBGR> &node,
size_t port,
const ov::runtime::Tensor &expected,
const ov::runtime::Tensor &actual,
double absThreshold,
double relThreshold) {
ov::test::utils::compare(expected, actual, absThreshold, relThreshold);
// Allow less than 2% of deviations with 1 color step. 2% is experimental value
// For different calculation methods - 1.4% deviation is observed
color_conversion::validate_colors(expected, actual, 0.02);
}
template<typename T>
void compareResults(const std::shared_ptr<ov::Node> &node,
size_t port,

View File

@ -1020,7 +1020,6 @@ ov::runtime::Tensor generate(const
comparison::fill_tensor(tensor);
return tensor;
}
ov::runtime::Tensor generate(const
std::shared_ptr<ov::op::v10::IsNaN>& node,
size_t port,
@ -1031,6 +1030,115 @@ ov::runtime::Tensor generate(const
return tensor;
}
namespace color_conversion {
enum class ColorFormat {
i420,
nv12
};
inline std::vector<uint8_t> color_test_image(size_t height, size_t width, int b_step, ColorFormat format) {
// Test all possible r/g/b values within dimensions
int b_dim = 255 / b_step + 1;
auto input_yuv = std::vector<uint8_t>(height * b_dim * width * 3 / 2);
for (int b = 0; b <= 255; b += b_step) {
for (size_t y = 0; y < height / 2; y++) {
for (size_t x = 0; x < width / 2; x++) {
int r = static_cast<int>(y) * 512 / static_cast<int>(height);
int g = static_cast<int>(x) * 512 / static_cast<int>(width);
// Can't use random y/u/v for testing as this can lead to invalid R/G/B values
int y_val = ((66 * r + 129 * g + 25 * b + 128) / 256) + 16;
int u_val = ((-38 * r - 74 * g + 112 * b + 128) / 256) + 128;
int v_val = ((112 * r - 94 * g + 18 * b + 128) / 256) + 128;
size_t b_offset = height * width * b / b_step * 3 / 2;
if (ColorFormat::i420 == format) {
size_t u_index = b_offset + height * width + y * width / 2 + x;
size_t v_index = u_index + height * width / 4;
input_yuv[u_index] = u_val;
input_yuv[v_index] = v_val;
} else {
size_t uv_index = b_offset + height * width + y * width + x * 2;
input_yuv[uv_index] = u_val;
input_yuv[uv_index + 1] = v_val;
}
size_t y_index = b_offset + y * 2 * width + x * 2;
input_yuv[y_index] = y_val;
input_yuv[y_index + 1] = y_val;
input_yuv[y_index + width] = y_val;
input_yuv[y_index + width + 1] = y_val;
}
}
}
return input_yuv;
}
void fill_tensor(ov::Tensor& tensor, ColorFormat format) {
size_t full_height = tensor.get_shape()[1];
size_t full_width = tensor.get_shape()[2];
int b_dim = static_cast<int>(full_height * 2 / (3 * full_width));
ASSERT_GT(b_dim, 1) << "Image height is invalid";
ASSERT_EQ(255 % (b_dim - 1), 0) << "Image height is invalid";
int b_step = 255 / (b_dim - 1);
auto input_image = color_test_image(full_width, full_width, b_step, format);
auto data_ptr = static_cast<uint8_t*>(tensor.data());
for (size_t j = 0; j < input_image.size(); ++j) {
data_ptr[j] = input_image[j];
}
}
} // namespace color_conversion
ov::runtime::Tensor generate(const std::shared_ptr<ov::op::v8::I420toRGB>& node,
size_t port,
const ov::element::Type& elemType,
const ov::Shape& targetShape) {
auto b_dim = static_cast<int>(targetShape[1] * 2 / (3 * targetShape[2]));
if (node->inputs().size() > 1 || b_dim < 2)
return generate(std::static_pointer_cast<ov::Node>(node), port, elemType, targetShape);
ov::Tensor tensor(elemType, targetShape);
color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::i420);
return tensor;
}
ov::runtime::Tensor generate(const
std::shared_ptr<ov::op::v8::I420toBGR>& node,
size_t port,
const ov::element::Type& elemType,
const ov::Shape& targetShape) {
auto b_dim = static_cast<int>(targetShape[1] * 2 / (3 * targetShape[2]));
if (node->inputs().size() > 1 || b_dim < 2)
return generate(std::static_pointer_cast<ov::Node>(node), port, elemType, targetShape);
ov::Tensor tensor(elemType, targetShape);
color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::i420);
return tensor;
}
ov::runtime::Tensor generate(const
std::shared_ptr<ov::op::v8::NV12toRGB>& node,
size_t port,
const ov::element::Type& elemType,
const ov::Shape& targetShape) {
auto b_dim = static_cast<int>(targetShape[1] * 2 / (3 * targetShape[2]));
if (node->inputs().size() > 1 || b_dim < 2)
return generate(std::static_pointer_cast<ov::Node>(node), port, elemType, targetShape);
ov::Tensor tensor(elemType, targetShape);
color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::nv12);
return tensor;
}
ov::runtime::Tensor generate(const
std::shared_ptr<ov::op::v8::NV12toBGR>& node,
size_t port,
const ov::element::Type& elemType,
const ov::Shape& targetShape) {
auto b_dim = static_cast<int>(targetShape[1] * 2 / (3 * targetShape[2]));
if (node->inputs().size() > 1 || b_dim < 2)
return generate(std::static_pointer_cast<ov::Node>(node), port, elemType, targetShape);
ov::Tensor tensor(elemType, targetShape);
color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::nv12);
return tensor;
}
template<typename T>
ov::runtime::Tensor generateInput(const std::shared_ptr<ov::Node>& node,
size_t port,

View File

@ -0,0 +1,55 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/concat.hpp"
namespace ov {
namespace test {
std::string ConcatLayerTest::getTestCaseName(const testing::TestParamInfo<concatParamsTuple> &obj) {
int axis;
std::vector<InputShape> shapes;
ov::element::Type model_type;
std::string targetName;
std::tie(axis, shapes, model_type, targetName) = obj.param;
std::ostringstream result;
result << "IS=(";
for (size_t i = 0lu; i < shapes.size(); i++) {
result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : "");
}
result << ")_TS=";
for (size_t i = 0lu; i < shapes.front().second.size(); i++) {
result << "{";
for (size_t j = 0lu; j < shapes.size(); j++) {
result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : "");
}
result << "}_";
}
result << "axis=" << axis << "_";
result << "netPRC=" << model_type.get_type_name() << "_";
result << "trgDev=" << targetName;
return result.str();
}
void ConcatLayerTest::SetUp() {
int axis;
std::vector<InputShape> shapes;
ov::element::Type model_type;
std::tie(axis, shapes, model_type, targetDevice) = this->GetParam();
init_input_shapes(shapes);
ov::ParameterVector params;
ov::NodeVector params_nodes;
for (const auto& shape : inputDynamicShapes) {
auto param = std::make_shared<ov::op::v0::Parameter>(model_type, shape);
params.push_back(param);
params_nodes.push_back(param);
}
auto concat = std::make_shared<ov::op::v0::Concat>(params_nodes, axis);
auto result = std::make_shared<ov::op::v0::Result>(concat);
function = std::make_shared<ov::Model>(result, params, "concat");
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,47 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/constant.hpp"
namespace ov {
namespace test {
namespace {
template <size_t N>
std::vector<std::string> getElements(const std::vector<std::string>& v) {
const auto new_size = std::min(N, v.size());
return {begin(v), std::next(begin(v), new_size)};
}
} // namespace
std::string ConstantLayerTest::getTestCaseName(
const testing::TestParamInfo<constantParamsTuple>& obj) {
ov::Shape shape;
ov::element::Type model_type;
std::vector<std::string> data_elements;
std::string target_device;
std::tie(shape, model_type, data_elements, target_device) = obj.param;
std::ostringstream result;
result << "TS={" << ov::test::utils::vec2str(shape) << "}_";
result << "dataPRC=" << model_type.get_type_name() << "_";
result << "dataValue=" << ov::test::utils::vec2str(getElements<5>(data_elements)) << "_";
result << "targetDevice=" << target_device << "_";
return result.str();
}
void ConstantLayerTest::SetUp() {
ov::Shape shape;
ov::element::Type model_type;
std::vector<std::string> data_elements;
std::tie(shape, model_type, data_elements, targetDevice) = this->GetParam();
auto constant = ov::op::v0::Constant::create(model_type, shape, data_elements);
auto result = std::make_shared<ov::op::v0::Result>(constant);
function = std::make_shared<ov::Model>(result, ov::ParameterVector{}, "constant");
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,66 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/conversion.hpp"
namespace ov {
namespace test {
namespace {
std::map<ov::test::utils::ConversionTypes, std::string> conversionNames = {
{ov::test::utils::ConversionTypes::CONVERT, "Convert"},
{ov::test::utils::ConversionTypes::CONVERT_LIKE, "ConvertLike"}};
}
std::string ConversionLayerTest::getTestCaseName(const testing::TestParamInfo<ConversionParamsTuple>& obj) {
ov::test::utils::ConversionTypes conversion_type;
ov::element::Type input_type, convert_type;
std::string device_name;
std::vector<InputShape> shapes;
std::tie(conversion_type, shapes, input_type, convert_type, device_name) =
obj.param;
std::ostringstream result;
result << "conversionOpType=" << conversionNames[conversion_type] << "_";
result << "IS=(";
for (size_t i = 0lu; i < shapes.size(); i++) {
result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : "");
}
result << ")_TS=";
for (size_t i = 0lu; i < shapes.front().second.size(); i++) {
result << "{";
for (size_t j = 0lu; j < shapes.size(); j++) {
result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : "");
}
result << "}_";
}
result << "inputPRC=" << input_type.get_type_name() << "_";
result << "targetPRC=" << convert_type.get_type_name() << "_";
result << "trgDev=" << device_name;
return result.str();
}
void ConversionLayerTest::SetUp() {
ov::test::utils::ConversionTypes conversion_type;
ov::element::Type input_type, convert_type;
std::vector<InputShape> shapes;
std::tie(conversion_type, shapes, input_type, convert_type, targetDevice) = GetParam();
init_input_shapes(shapes);
ov::ParameterVector params;
for (const auto& shape : inputDynamicShapes) {
params.push_back(std::make_shared<ov::op::v0::Parameter>(input_type, shape));
}
std::shared_ptr<ov::Node> conversion;
if (conversion_type == ov::test::utils::ConversionTypes::CONVERT) {
conversion = std::make_shared<ov::op::v0::Convert>(params.front(), convert_type);
} else /*CONVERT_LIKE*/ {
auto like = std::make_shared<ov::op::v0::Constant>(convert_type, ov::Shape{1});
conversion = std::make_shared<ov::op::v1::ConvertLike>(params.front(), like);
}
auto result = std::make_shared<ov::op::v0::Result>(conversion);
function = std::make_shared<ov::Model>(result, params, "Conversion");
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,75 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/convert_color_i420.hpp"
#include "openvino/op/i420_to_rgb.hpp"
#include "openvino/op/i420_to_bgr.hpp"
#include "openvino/op/parameter.hpp"
#include "openvino/op/result.hpp"
namespace ov {
namespace test {
std::string ConvertColorI420LayerTest::getTestCaseName(const testing::TestParamInfo<ConvertColorI420ParamsTuple> &obj) {
std::vector<InputShape> shapes;
ov::element::Type type;
bool conversion, single_plane;
std::string device_name;
std::tie(shapes, type, conversion, single_plane, device_name) = obj.param;
std::ostringstream result;
result << "IS=(";
for (size_t i = 0lu; i < shapes.size(); i++) {
result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : "");
}
result << ")_TS=";
for (size_t i = 0lu; i < shapes.front().second.size(); i++) {
result << "{";
for (size_t j = 0lu; j < shapes.size(); j++) {
result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : "");
}
result << "}_";
}
result << "netPRC=" << type.c_type_string() << "_";
result << "convRGB=" << conversion << "_";
result << "singlePlane=" << single_plane << "_";
result << "targetDevice=" << device_name;
return result.str();
}
void ConvertColorI420LayerTest::SetUp() {
std::vector<InputShape> shapes;
ov::element::Type net_type;
bool conversion_to_rgb;
bool single_plane;
abs_threshold = 1.1f; // I420 conversion can use various algorithms, thus some absolute deviation is allowed
rel_threshold = 1.1f; // Ignore relative comparison for I420 convert (allow 100% relative deviation)
std::tie(shapes, net_type, conversion_to_rgb, single_plane, targetDevice) = GetParam();
init_input_shapes(shapes);
if (single_plane) {
auto param = std::make_shared<ov::op::v0::Parameter>(net_type, inputDynamicShapes.front());
std::shared_ptr<ov::Node> convert_color;
if (conversion_to_rgb) {
convert_color = std::make_shared<ov::op::v8::I420toRGB>(param);
} else {
convert_color = std::make_shared<ov::op::v8::I420toBGR>(param);
}
function = std::make_shared<ov::Model>(std::make_shared<ov::op::v0::Result>(convert_color),
ov::ParameterVector{param}, "ConvertColorI420");
} else {
auto param_y = std::make_shared<ov::op::v0::Parameter>(net_type, inputDynamicShapes[0]);
auto param_u = std::make_shared<ov::op::v0::Parameter>(net_type, inputDynamicShapes[1]);
auto param_v = std::make_shared<ov::op::v0::Parameter>(net_type, inputDynamicShapes[2]);
std::shared_ptr<ov::Node> convert_color;
if (conversion_to_rgb) {
convert_color = std::make_shared<ov::op::v8::I420toRGB>(param_y, param_u, param_v);
} else {
convert_color = std::make_shared<ov::op::v8::I420toBGR>(param_y, param_u, param_v);
}
function = std::make_shared<ov::Model>(std::make_shared<ov::op::v0::Result>(convert_color),
ov::ParameterVector{param_y, param_u, param_v},
"ConvertColorI420");
}
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,75 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/convert_color_nv12.hpp"
#include "openvino/op/nv12_to_rgb.hpp"
#include "openvino/op/nv12_to_bgr.hpp"
#include "openvino/op/parameter.hpp"
#include "openvino/op/result.hpp"
namespace ov {
namespace test {
std::string ConvertColorNV12LayerTest::getTestCaseName(const testing::TestParamInfo<ConvertColorNV12ParamsTuple> &obj) {
std::vector<InputShape> shapes;
ov::element::Type type;
bool conversion, single_plane;
std::string device_name;
std::tie(shapes, type, conversion, single_plane, device_name) = obj.param;
std::ostringstream result;
result << "IS=(";
for (size_t i = 0lu; i < shapes.size(); i++) {
result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : "");
}
result << ")_TS=";
for (size_t i = 0lu; i < shapes.front().second.size(); i++) {
result << "{";
for (size_t j = 0lu; j < shapes.size(); j++) {
result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : "");
}
result << "}_";
}
result << "modelType=" << type.c_type_string() << "_";
result << "convRGB=" << conversion << "_";
result << "single_plane=" << single_plane << "_";
result << "targetDevice=" << device_name;
return result.str();
}
void ConvertColorNV12LayerTest::SetUp() {
std::vector<InputShape> shapes;
ov::element::Type net_type;
bool conversionToRGB, single_plane;
abs_threshold = 1.1f; // NV12 conversion can use various algorithms, thus some absolute deviation is allowed
rel_threshold = 1.1f; // Ignore relative comparison for NV12 convert (allow 100% relative deviation)
std::tie(shapes, net_type, conversionToRGB, single_plane, targetDevice) = GetParam();
init_input_shapes(shapes);
if (single_plane) {
auto param = std::make_shared<ov::op::v0::Parameter>(net_type, inputDynamicShapes.front());
std::shared_ptr<ov::Node> convert_color;
if (conversionToRGB) {
convert_color = std::make_shared<ov::op::v8::NV12toRGB>(param);
} else {
convert_color = std::make_shared<ov::op::v8::NV12toBGR>(param);
}
function = std::make_shared<ov::Model>(std::make_shared<ov::op::v0::Result>(convert_color),
ov::ParameterVector{param}, "ConvertColorNV12");
} else {
auto param_y = std::make_shared<ov::op::v0::Parameter>(net_type, inputDynamicShapes[0]);
auto param_uv = std::make_shared<ov::op::v0::Parameter>(net_type, inputDynamicShapes[1]);
std::shared_ptr<ov::Node> convert_color;
if (conversionToRGB) {
convert_color = std::make_shared<ov::op::v8::NV12toRGB>(param_y, param_uv);
} else {
convert_color = std::make_shared<ov::op::v8::NV12toBGR>(param_y, param_uv);
}
function = std::make_shared<ov::Model>(std::make_shared<ov::op::v0::Result>(convert_color),
ov::ParameterVector{param_y, param_uv}, "ConvertColorNV12");
}
}
} // namespace test
} // namespace ov