From 757b757a200dd7ab6ae36240ffe629e8afcff1e1 Mon Sep 17 00:00:00 2001 From: Mikhail Nosov Date: Wed, 8 Dec 2021 09:21:07 +0300 Subject: [PATCH] Preprocessing - added test for dynamic spatial shapes (resize) (#8980) * Preprocessing - added test for dynamic spatial shapes (resize) * Applied review comments * Remove unnecessary change * Revert signature to keep compatibility with kmb plugin * Try fix centos --- .../skip_tests_config.cpp | 2 ++ .../subgraph_tests/preprocess.cpp | 1 + .../subgraph/preprocess.hpp | 4 +-- .../src/base/ov_subgraph.cpp | 4 +-- .../src/subgraph/preprocess.cpp | 17 +++++++----- .../preprocess/preprocess_builders.hpp | 26 ++++++++++++++++++- 6 files changed, 43 insertions(+), 11 deletions(-) diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/skip_tests_config.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/skip_tests_config.cpp index 5e678cb5de4..0c5c61b35e8 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/skip_tests_config.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/skip_tests_config.cpp @@ -94,5 +94,7 @@ std::vector disabledTestPatterns() { R"(smoke_PrePostProcess.*cvt_color_i420.*)", // Unsupported R"(smoke_Behavior/InferRequestSetBlobByType.setInputBlobsByType/BlobType=Batched_Device=GPU_Config=().*)", + // TODO: Issue 72624 + R"(smoke_PrePostProcess.*resize_dynamic.*)", }; } diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/subgraph_tests/preprocess.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/subgraph_tests/preprocess.cpp index f6463330724..af253628e41 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/subgraph_tests/preprocess.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/subgraph_tests/preprocess.cpp @@ -28,6 +28,7 @@ inline std::vector GPU_smoke_preprocess_functions() { preprocess_func(resize_nearest, "resize_nearest", 0.01f), preprocess_func(resize_linear_nhwc, "resize_linear_nhwc", 0.01f), preprocess_func(resize_cubic, "resize_cubic", 0.01f), + preprocess_func(resize_dynamic, "resize_dynamic", 0.01f, { ov::Shape {1, 3, 123, 123} }), preprocess_func(convert_layout_by_dims, "convert_layout_by_dims", 0.01f), preprocess_func(resize_and_convert_layout, "resize_and_convert_layout", 0.01f), preprocess_func(cvt_color_nv12_to_rgb_single_plane, "cvt_color_nv12_to_rgb_single_plane", 1.f), diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/preprocess.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/preprocess.hpp index 2cc103700c0..49cf6e9ab6b 100644 --- a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/preprocess.hpp +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/preprocess.hpp @@ -9,7 +9,7 @@ #include #include -#include "../base/layer_test_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "ngraph_functions/builders.hpp" #include "ngraph_functions/preprocess/preprocess_builders.hpp" #include "ngraph_functions/utils/ngraph_helpers.hpp" @@ -21,7 +21,7 @@ using preprocessParamsTuple = std::tuple< std::string>; // Device name class PrePostProcessTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { + virtual public ov::test::SubgraphBaseTest { public: static std::string getTestCaseName(const testing::TestParamInfo &obj); diff --git a/inference-engine/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp b/inference-engine/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp index 801ac5c22c2..dfa7e968c67 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp @@ -58,12 +58,12 @@ void SubgraphBaseTest::run() { init_ref_function(functionRefs, targetStaticShapeVec); } generate_inputs(targetStaticShapeVec); - infer(); - validate(); } catch (const std::exception& ex) { throw std::runtime_error("Incorrect target static shape: " + CommonTestUtils::vec2str(targetStaticShapeVec) + " " + ex.what()); } + infer(); + validate(); } status = LayerTestsUtils::PassRate::Statuses::PASSED; } catch (const std::exception& ex) { diff --git a/inference-engine/tests/functional/shared_test_classes/src/subgraph/preprocess.cpp b/inference-engine/tests/functional/shared_test_classes/src/subgraph/preprocess.cpp index e715fb0e20b..be7e2025816 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/subgraph/preprocess.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/subgraph/preprocess.cpp @@ -5,7 +5,6 @@ #include "shared_test_classes/subgraph/preprocess.hpp" #include "ngraph_functions/preprocess/preprocess_builders.hpp" #include "openvino/core/preprocess/pre_post_process.hpp" -#include using namespace ov; using namespace ov::preprocess; @@ -20,7 +19,7 @@ std::string PrePostProcessTest::getTestCaseName( std::tie(func, targetName) = obj.param; std::ostringstream result; - result << "Func=" << std::get<1>(func) << "_"; + result << "Func=" << func.m_name << "_"; result << "Device=" << targetName << ""; return result.str(); } @@ -28,14 +27,20 @@ std::string PrePostProcessTest::getTestCaseName( void PrePostProcessTest::SetUp() { preprocess_func func; std::tie(func, targetDevice) = GetParam(); - function = (std::get<0>(func))(); - threshold = std::get<2>(func); + function = func.m_function(); + rel_threshold = func.m_accuracy; functionRefs = ngraph::clone_function(*function); - abs_threshold = std::get<2>(func); + abs_threshold = func.m_accuracy; + if (func.m_shapes.empty()) { + for (const auto& input : function->inputs()) { + func.m_shapes.push_back(input.get_shape()); + } + } + init_input_shapes(ov::test::static_shapes_to_test_representation(func.m_shapes)); } TEST_P(PrePostProcessTest, CompareWithRefs) { - Run(); + run(); } } // namespace SubgraphTestsDefinitions diff --git a/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/preprocess/preprocess_builders.hpp b/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/preprocess/preprocess_builders.hpp index 97eeed3aa61..017fe62c6d3 100644 --- a/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/preprocess/preprocess_builders.hpp +++ b/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/preprocess/preprocess_builders.hpp @@ -10,7 +10,19 @@ namespace ov { namespace builder { namespace preprocess { -using preprocess_func = std::tuple()>, std::string, float>; +struct preprocess_func { + preprocess_func() = default; + preprocess_func(const std::function()>& f, + const std::string& name, + float acc, + const std::vector& shapes = {}): + m_function(f), m_name(name), m_accuracy(acc), m_shapes(shapes) { + } + std::function()> m_function = nullptr; + std::string m_name = {}; + float m_accuracy = 0.01f; + std::vector m_shapes = {}; +}; inline std::vector generic_preprocess_functions(); @@ -368,6 +380,17 @@ inline std::shared_ptr cvt_color_bgrx_to_bgr() { return p.build(); } +inline std::shared_ptr resize_dynamic() { + using namespace ov::preprocess; + auto function = create_preprocess_1input(element::f32, PartialShape{1, 3, 20, 20}); + auto p = PrePostProcessor(function); + p.input().tensor().set_spatial_dynamic_shape(); + p.input().preprocess().resize(ResizeAlgorithm::RESIZE_LINEAR); + p.input().network().set_layout("NCHW"); + function = p.build(); + return function; +} + inline std::vector generic_preprocess_functions() { return std::vector { preprocess_func(mean_only, "mean_only", 0.01f), @@ -388,6 +411,7 @@ inline std::vector generic_preprocess_functions() { preprocess_func(resize_nearest, "resize_nearest", 0.01f), preprocess_func(resize_linear_nhwc, "resize_linear_nhwc", 0.01f), preprocess_func(resize_cubic, "resize_cubic", 0.01f), + preprocess_func(resize_dynamic, "resize_dynamic", 0.01f, { Shape {1, 3, 123, 123} }), preprocess_func(convert_layout_by_dims, "convert_layout_by_dims", 0.01f), preprocess_func(resize_and_convert_layout, "resize_and_convert_layout", 0.01f), preprocess_func(resize_and_convert_layout_i8, "resize_and_convert_layout_i8", 0.01f),