From 6deec50b0b599568b93a8b725e2cef0fa292cd28 Mon Sep 17 00:00:00 2001 From: Patryk Elszkowski Date: Tue, 15 Jun 2021 06:07:18 +0200 Subject: [PATCH] Reshape OP: add SLT for special `-1` value in new shape dimensions (#5648) * add test for special `-1` value in new shape dimensions * add ticket with next steps --- .../single_layer_tests/reshape.cpp | 73 +++++++++++-------- .../serialization/single_layer/reshape.cpp | 8 +- .../single_layer_tests/reshape.cpp | 28 +++++-- .../single_layer_tests/reshape.cpp | 26 +++++-- .../single_layer/reshape.hpp | 66 ++++++++++++----- .../src/single_layer/reshape.cpp | 47 +++++++++++- 6 files changed, 182 insertions(+), 66 deletions(-) diff --git a/docs/template_plugin/tests/functional/shared_tests_instances/single_layer_tests/reshape.cpp b/docs/template_plugin/tests/functional/shared_tests_instances/single_layer_tests/reshape.cpp index 85313f410d3..e0c986ad8b5 100644 --- a/docs/template_plugin/tests/functional/shared_tests_instances/single_layer_tests/reshape.cpp +++ b/docs/template_plugin/tests/functional/shared_tests_instances/single_layer_tests/reshape.cpp @@ -2,43 +2,58 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "single_layer_tests/reshape.hpp" + #include -#include "single_layer_tests/reshape.hpp" #include "common_test_utils/test_constants.hpp" using namespace LayerTestsDefinitions; namespace { const std::vector netPrecisions = { - InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP32, }; -INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheckDynBatch, ReshapeLayerTest, - ::testing::Combine( - ::testing::Values(true), - ::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({30, 30, 30, 30})), - ::testing::Values(std::vector({30, 30, 30, 30})), - ::testing::Values(CommonTestUtils::DEVICE_TEMPLATE), - ::testing::Values(std::map({}))), - ReshapeLayerTest::getTestCaseName); +INSTANTIATE_TEST_CASE_P( + smoke_ReshapeCheckDynBatch, ReshapeLayerTestRevise, + ::testing::Combine( + ::testing::Values(true), ::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({30, 30, 30, 30})), + ::testing::Values(std::vector({30, 30, 30, 30})), + ::testing::Values(CommonTestUtils::DEVICE_TEMPLATE), + ::testing::Values(std::map({}))), + ReshapeLayerTestRevise::getTestCaseName); -INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheck, ReshapeLayerTest, - ::testing::Combine( - ::testing::Values(true), - ::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({10, 10, 10, 10})), - ::testing::Values(std::vector({10, 0, 100})), - ::testing::Values(CommonTestUtils::DEVICE_TEMPLATE), - ::testing::Values(std::map({}))), - ReshapeLayerTest::getTestCaseName); -} // namespace \ No newline at end of file +INSTANTIATE_TEST_CASE_P( + smoke_ReshapeCheck, ReshapeLayerTestRevise, + ::testing::Combine( + ::testing::Values(true), ::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({10, 10, 10, 10})), + ::testing::Values(std::vector({10, 0, 100})), + ::testing::Values(CommonTestUtils::DEVICE_TEMPLATE), + ::testing::Values(std::map({}))), + ReshapeLayerTestRevise::getTestCaseName); + +INSTANTIATE_TEST_CASE_P( + smoke_ReshapeCheckNegative, ReshapeLayerTestRevise, + ::testing::Combine( + ::testing::Values(true), ::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({10, 10, 10, 10})), + ::testing::Values(std::vector({10, -1, 100})), + ::testing::Values(CommonTestUtils::DEVICE_TEMPLATE), + ::testing::Values(std::map({}))), + ReshapeLayerTestRevise::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/inference_engine/serialization/single_layer/reshape.cpp b/inference-engine/tests/functional/inference_engine/serialization/single_layer/reshape.cpp index c7b60da690f..9ba9aec704b 100644 --- a/inference-engine/tests/functional/inference_engine/serialization/single_layer/reshape.cpp +++ b/inference-engine/tests/functional/inference_engine/serialization/single_layer/reshape.cpp @@ -10,7 +10,7 @@ using namespace LayerTestsDefinitions; namespace { - TEST_P(ReshapeLayerTest, Serialize) { + TEST_P(ReshapeLayerTestRevise, Serialize) { Serialize(); } @@ -19,7 +19,7 @@ namespace { InferenceEngine::Precision::FP16 }; - INSTANTIATE_TEST_CASE_P(smoke_ReshapeSerialization, ReshapeLayerTest, + INSTANTIATE_TEST_CASE_P(smoke_ReshapeSerialization, ReshapeLayerTestRevise, ::testing::Combine( ::testing::Values(true), ::testing::ValuesIn(netPrecisions), @@ -28,8 +28,8 @@ namespace { ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(std::vector({30, 30, 30, 30})), - ::testing::Values(std::vector({30, 30, 30, 30})), + ::testing::Values(std::vector({30, 30, 30, 30})), ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::Values(std::map({{CONFIG_KEY(DYN_BATCH_ENABLED), CONFIG_VALUE(YES)}}))), - ReshapeLayerTest::getTestCaseName); + ReshapeLayerTestRevise::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/reshape.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/reshape.cpp index 0bdef642658..28419ec971f 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/reshape.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/reshape.cpp @@ -15,7 +15,7 @@ const std::vector netPrecisions = { InferenceEngine::Precision::FP16 }; -INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheckDynBatch, ReshapeLayerTest, +INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheckDynBatch, ReshapeLayerTestRevise, ::testing::Combine( ::testing::Values(true), ::testing::ValuesIn(netPrecisions), @@ -24,12 +24,12 @@ INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheckDynBatch, ReshapeLayerTest, ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(std::vector({30, 30, 30, 30})), - ::testing::Values(std::vector({30, 30, 30, 30})), + ::testing::Values(std::vector({30, 30, 30, 30})), ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::Values(std::map({{CONFIG_KEY(DYN_BATCH_ENABLED), CONFIG_VALUE(YES)}}))), - ReshapeLayerTest::getTestCaseName); + ReshapeLayerTestRevise::getTestCaseName); -INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheck, ReshapeLayerTest, +INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheck, ReshapeLayerTestRevise, ::testing::Combine( ::testing::Values(true), ::testing::ValuesIn(netPrecisions), @@ -38,8 +38,22 @@ INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheck, ReshapeLayerTest, ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(std::vector({10, 10, 10, 10})), - ::testing::Values(std::vector({10, 0, 100})), + ::testing::Values(std::vector({10, 0, 100})), ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::Values(std::map({}))), - ReshapeLayerTest::getTestCaseName); -} // namespace \ No newline at end of file + ReshapeLayerTestRevise::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheckNegative, ReshapeLayerTestRevise, + ::testing::Combine( + ::testing::Values(true), + ::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({10, 10, 10, 10})), + ::testing::Values(std::vector({10, -1, 100})), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(std::map({}))), + ReshapeLayerTestRevise::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/reshape.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/reshape.cpp index a304c345776..84d30807341 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/reshape.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/reshape.cpp @@ -16,7 +16,7 @@ const std::vector netPrecisions = { }; //TODO: Issue : - 28981 -INSTANTIATE_TEST_CASE_P(DISABLE_smoke_ReshapeCheckDynBatch, ReshapeLayerTest, +INSTANTIATE_TEST_CASE_P(DISABLE_smoke_ReshapeCheckDynBatch, ReshapeLayerTestRevise, ::testing::Combine( ::testing::Values(true), ::testing::ValuesIn(netPrecisions), @@ -25,12 +25,12 @@ INSTANTIATE_TEST_CASE_P(DISABLE_smoke_ReshapeCheckDynBatch, ReshapeLayerTest, ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(std::vector({1, 16, 16, 16})), - ::testing::Values(std::vector({1, 0, 256})), + ::testing::Values(std::vector({1, 0, 256})), ::testing::Values(CommonTestUtils::DEVICE_GPU), ::testing::Values(std::map({{CONFIG_KEY(DYN_BATCH_ENABLED), CONFIG_VALUE(YES)}}))), - ReshapeLayerTest::getTestCaseName); + ReshapeLayerTestRevise::getTestCaseName); -INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheck, ReshapeLayerTest, +INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheck, ReshapeLayerTestRevise, ::testing::Combine( ::testing::Values(true), ::testing::ValuesIn(netPrecisions), @@ -39,8 +39,22 @@ INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheck, ReshapeLayerTest, ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(InferenceEngine::Layout::ANY), ::testing::Values(std::vector({10, 10, 10, 10})), - ::testing::Values(std::vector({10, 0, 100})), + ::testing::Values(std::vector({10, 0, 100})), ::testing::Values(CommonTestUtils::DEVICE_GPU), ::testing::Values(std::map({}))), - ReshapeLayerTest::getTestCaseName); + ReshapeLayerTestRevise::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheckNegative, ReshapeLayerTestRevise, + ::testing::Combine( + ::testing::Values(true), + ::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({10, 10, 10, 10})), + ::testing::Values(std::vector({10, -1, 100})), + ::testing::Values(CommonTestUtils::DEVICE_GPU), + ::testing::Values(std::map({}))), + ReshapeLayerTestRevise::getTestCaseName); } // namespace diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/reshape.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/reshape.hpp index d0acf57931d..9ddeeed509a 100644 --- a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/reshape.hpp +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/reshape.hpp @@ -4,36 +4,66 @@ #pragma once -#include -#include -#include #include +#include +#include +#include + #include "ngraph_functions/builders.hpp" #include "ngraph_functions/utils/ngraph_helpers.hpp" - #include "shared_test_classes/base/layer_test_utils.hpp" namespace LayerTestsDefinitions { -typedef std::tuple< - bool, // SpecialZero - InferenceEngine::Precision, // Network precision - InferenceEngine::Precision, // Input precision - InferenceEngine::Precision, // Output precision - InferenceEngine::Layout, // Input layout - InferenceEngine::Layout, // Output layout - std::vector, // Input shapes - std::vector, // OutForm Shapes - std::string, // Device name - std::map // Config -> reshapeParams; +//TODO: remove this alias when ticket 57975 is done - ticket: 57976 +typedef std::tuple, // Input shapes + std::vector, // OutForm Shapes + std::string, // Device name + std::map // Config + > + reshapeParams; + +//TODO: remove this class when ticket 57975 is done - ticket: 57976 class ReshapeLayerTest : public testing::WithParamInterface, virtual public LayerTestsUtils::LayerTestsCommon { public: - static std::string getTestCaseName(testing::TestParamInfo obj); + static std::string getTestCaseName( + testing::TestParamInfo obj); protected: void SetUp() override; }; -} // namespace LayerTestsDefinitions \ No newline at end of file + +//TODO: use this alias in all dependencies - ticket: 57975 +typedef std::tuple, // Input shapes + std::vector, // OutForm Shapes + std::string, // Device name + std::map // Config + > + reshapeParamsRevise; + +//TODO: use this class in all dependencies - ticket: 57975 +class ReshapeLayerTestRevise + : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon { +public: + static std::string getTestCaseName( + testing::TestParamInfo obj); + +protected: + void SetUp() override; +}; +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/shared_test_classes/src/single_layer/reshape.cpp b/inference-engine/tests/functional/shared_test_classes/src/single_layer/reshape.cpp index 3063b01b27b..708c40ebbe0 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/single_layer/reshape.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/single_layer/reshape.cpp @@ -5,7 +5,7 @@ #include "shared_test_classes/single_layer/reshape.hpp" namespace LayerTestsDefinitions { - std::string ReshapeLayerTest::getTestCaseName(testing::TestParamInfo obj) { +std::string ReshapeLayerTest::getTestCaseName(testing::TestParamInfo obj) { InferenceEngine::Precision netPrecision; InferenceEngine::Precision inPrc, outPrc; InferenceEngine::Layout inLayout, outLayout; @@ -44,4 +44,47 @@ void ReshapeLayerTest::SetUp() { ngraph::ResultVector results{std::make_shared(reshape)}; function = std::make_shared(results, paramsIn, "Reshape"); } -} // namespace LayerTestsDefinitions \ No newline at end of file + +std::string ReshapeLayerTestRevise::getTestCaseName(testing::TestParamInfo obj) { + InferenceEngine::Precision netPrecision; + InferenceEngine::Precision inPrc, outPrc; + InferenceEngine::Layout inLayout, outLayout; + InferenceEngine::SizeVector inputShapes; + std::vector outFormShapes; + std::string targetDevice; + std::map config; + bool specialZero; + std::tie(specialZero, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShapes, outFormShapes, targetDevice, config) = obj.param; + std::ostringstream result; + result << "IS=" << CommonTestUtils::vec2str(inputShapes) << "_"; + result << "OS=" << CommonTestUtils::vec2str(outFormShapes) << "_"; + result << "specialZero=" << specialZero << "_"; + result << "netPRC=" << netPrecision.name() << "_"; + result << "inPRC=" << inPrc.name() << "_"; + result << "outPRC=" << outPrc.name() << "_"; + result << "inL=" << inLayout << "_"; + result << "outL=" << outLayout << "_"; + result << "trgDev=" << targetDevice; + return result.str(); +} + +void ReshapeLayerTestRevise::SetUp() { + InferenceEngine::SizeVector inputShapes; + std::vector outFormShapes; + bool specialZero; + InferenceEngine::Precision netPrecision; + std::tie(specialZero, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShapes, outFormShapes, targetDevice, configuration) = + this->GetParam(); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto paramsIn = ngraph::builder::makeParams(ngPrc, {inputShapes}); + auto paramIn = ngraph::helpers::convert2OutputVector( + ngraph::helpers::castOps2Nodes(paramsIn)); + auto constNode = std::make_shared( + ngraph::element::Type_t::i64, ngraph::Shape{outFormShapes.size()}, outFormShapes); + auto reshape = std::dynamic_pointer_cast( + std::make_shared(paramIn[0], constNode, specialZero)); + ngraph::ResultVector results{std::make_shared(reshape)}; + function = std::make_shared(results, paramsIn, "Reshape"); +} + +} // namespace LayerTestsDefinitions