From 8384279b2e55b9e6164317e78d3ec839d5b00bbe Mon Sep 17 00:00:00 2001 From: Vitaliy Urusovskij Date: Wed, 20 Dec 2023 15:28:06 +0400 Subject: [PATCH] Preprocessing tests to new utils (#21752) --- .../preprocessing/yuv_to_grey_tests.hpp | 2 - .../src/preprocessing/yuv_to_grey_tests.cpp | 12 ++- .../base/utils/generate_inputs.hpp | 5 +- .../src/base/utils/generate_inputs.cpp | 88 +++++++++---------- 4 files changed, 50 insertions(+), 57 deletions(-) diff --git a/src/tests/functional/plugin/shared/include/preprocessing/yuv_to_grey_tests.hpp b/src/tests/functional/plugin/shared/include/preprocessing/yuv_to_grey_tests.hpp index e3a99fcee0ad79..b16630b97633a6 100644 --- a/src/tests/functional/plugin/shared/include/preprocessing/yuv_to_grey_tests.hpp +++ b/src/tests/functional/plugin/shared/include/preprocessing/yuv_to_grey_tests.hpp @@ -6,8 +6,6 @@ #include -#include - #include "shared_test_classes/base/ov_subgraph.hpp" using TParams = std::tuple; diff --git a/src/tests/functional/plugin/shared/src/preprocessing/yuv_to_grey_tests.cpp b/src/tests/functional/plugin/shared/src/preprocessing/yuv_to_grey_tests.cpp index 2e1dea33834fd8..99fcae998f8490 100644 --- a/src/tests/functional/plugin/shared/src/preprocessing/yuv_to_grey_tests.cpp +++ b/src/tests/functional/plugin/shared/src/preprocessing/yuv_to_grey_tests.cpp @@ -3,8 +3,7 @@ // #include "preprocessing/yuv_to_grey_tests.hpp" -#include "shared_test_classes/single_layer/convert_color_i420.hpp" -#include "shared_test_classes/single_layer/convert_color_nv12.hpp" +#include "shared_test_classes/base/utils/generate_inputs.hpp" namespace ov { namespace preprocess { @@ -167,7 +166,7 @@ TEST_P(PreprocessingYUV2GreyTest, convert_single_plane_i420_use_opencv) { // Test various possible r/g/b values within dimensions const auto input_yuv_shape = Shape{1, get_full_height() * 3 / 2, width, 1}; const auto input_y_shape = Shape{1, get_full_height(), width, 1}; - auto ov20_input_yuv = LayerTestsDefinitions::I420TestUtils::color_test_image(height, width, b_step); + auto ov20_input_yuv = ov::test::utils::color_test_image(height, width, b_step, ColorFormat::I420_SINGLE_PLANE); auto ov20_input_y = std::vector(ov20_input_yuv.begin(), ov20_input_yuv.begin() + shape_size(input_y_shape)); @@ -188,8 +187,7 @@ TEST_P(PreprocessingYUV2GreyTest, convert_three_plane_i420_use_opencv) { const auto input_y_shape = Shape{1, get_full_height(), width, 1}; const auto input_u_shape = Shape{1, get_full_height() / 2, width / 2, 1}; const auto input_v_shape = Shape{1, get_full_height() / 2, width / 2, 1}; - // const auto input_uv_shape = Shape{1, get_full_height() / 2, width / 2, 2}; - auto ov20_input_yuv = LayerTestsDefinitions::I420TestUtils::color_test_image(height, width, b_step); + auto ov20_input_yuv = ov::test::utils::color_test_image(height, width, b_step, ColorFormat::I420_THREE_PLANES); auto input_yuv_iter = ov20_input_yuv.begin(); auto ov20_input_y = std::vector(input_yuv_iter, input_yuv_iter + shape_size(input_y_shape)); @@ -218,7 +216,7 @@ TEST_P(PreprocessingYUV2GreyTest, convert_single_plane_nv12_use_opencv) { // Test various possible r/g/b values within dimensions const auto input_yuv_shape = Shape{1, get_full_height() * 3 / 2, width, 1}; const auto input_y_shape = Shape{1, get_full_height(), width, 1}; - auto ov20_input_yuv = LayerTestsDefinitions::NV12TestUtils::color_test_image(height, width, b_step); + auto ov20_input_yuv = ov::test::utils::color_test_image(height, width, b_step, ColorFormat::NV12_SINGLE_PLANE); auto ov20_input_y = std::vector(ov20_input_yuv.begin(), ov20_input_yuv.begin() + shape_size(input_y_shape)); @@ -238,7 +236,7 @@ TEST_P(PreprocessingYUV2GreyTest, convert_two_plane_nv12_use_opencv) { // Test various possible r/g/b values within dimensions const auto input_y_shape = Shape{1, get_full_height(), width, 1}; const auto input_uv_shape = Shape{1, get_full_height() / 2, width / 2, 2}; - auto ov20_input_yuv = LayerTestsDefinitions::NV12TestUtils::color_test_image(height, width, b_step); + auto ov20_input_yuv = ov::test::utils::color_test_image(height, width, b_step, ColorFormat::NV12_TWO_PLANES); auto input_yuv_iter = ov20_input_yuv.begin(); auto ov20_input_y = std::vector(input_yuv_iter, input_yuv_iter + shape_size(input_y_shape)); diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/generate_inputs.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/generate_inputs.hpp index 980483e2317689..df2a47513e17de 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/generate_inputs.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/generate_inputs.hpp @@ -4,8 +4,7 @@ #pragma once -#include "ie_core.hpp" -#include "ngraph/node.hpp" +#include "openvino/core/preprocess/color_format.hpp" #include "shared_test_classes/base/utils/ranges.hpp" @@ -16,6 +15,8 @@ namespace utils { void set_const_ranges(double _min, double _max); void reset_const_ranges(); +std::vector color_test_image(size_t height, size_t width, int b_step, ov::preprocess::ColorFormat format); + using InputsMap = std::map& node, size_t port, diff --git a/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp b/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp index c61d9d5ee39578..887cfe2746a0a6 100644 --- a/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp +++ b/src/tests/functional/shared_test_classes/src/base/utils/generate_inputs.cpp @@ -38,6 +38,43 @@ void reset_const_ranges() { const_range.is_defined = false; } +std::vector color_test_image(size_t height, size_t width, int b_step, ov::preprocess::ColorFormat format) { + // Test all possible r/g/b values within dimensions + int b_dim = 255 / b_step + 1; + auto input_yuv = std::vector(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(y) * 512 / static_cast(height); + int g = static_cast(x) * 512 / static_cast(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 (ov::preprocess::ColorFormat::I420_SINGLE_PLANE == format || + ov::preprocess::ColorFormat::I420_THREE_PLANES == 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; +} + namespace { /** @@ -912,48 +949,7 @@ ov::runtime::Tensor generate(const } namespace color_conversion { -enum class ColorFormat { - i420, - nv12 -}; - -inline std::vector 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(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(y) * 512 / static_cast(height); - int g = static_cast(x) * 512 / static_cast(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) { +void fill_tensor(ov::Tensor& tensor, ov::preprocess::ColorFormat format) { size_t full_height = tensor.get_shape()[1]; size_t full_width = tensor.get_shape()[2]; int b_dim = static_cast(full_height * 2 / (3 * full_width)); @@ -976,7 +972,7 @@ ov::runtime::Tensor generate(const std::shared_ptr& node, if (node->inputs().size() > 1 || b_dim < 2) return generate(std::static_pointer_cast(node), port, elemType, targetShape); ov::Tensor tensor(elemType, targetShape); - color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::i420); + color_conversion::fill_tensor(tensor, ov::preprocess::ColorFormat::I420_SINGLE_PLANE); return tensor; } @@ -989,7 +985,7 @@ ov::runtime::Tensor generate(const if (node->inputs().size() > 1 || b_dim < 2) return generate(std::static_pointer_cast(node), port, elemType, targetShape); ov::Tensor tensor(elemType, targetShape); - color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::i420); + color_conversion::fill_tensor(tensor, ov::preprocess::ColorFormat::I420_SINGLE_PLANE); return tensor; } @@ -1003,7 +999,7 @@ ov::runtime::Tensor generate(const if (node->inputs().size() > 1 || b_dim < 2) return generate(std::static_pointer_cast(node), port, elemType, targetShape); ov::Tensor tensor(elemType, targetShape); - color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::nv12); + color_conversion::fill_tensor(tensor, ov::preprocess::ColorFormat::NV12_SINGLE_PLANE); return tensor; } @@ -1016,7 +1012,7 @@ ov::runtime::Tensor generate(const if (node->inputs().size() > 1 || b_dim < 2) return generate(std::static_pointer_cast(node), port, elemType, targetShape); ov::Tensor tensor(elemType, targetShape); - color_conversion::fill_tensor(tensor, color_conversion::ColorFormat::nv12); + color_conversion::fill_tensor(tensor, ov::preprocess::ColorFormat::NV12_SINGLE_PLANE); return tensor; }