From 61674c1bd4a06d1c533a12da44ce216827915453 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Fri, 29 May 2020 22:56:58 +0300 Subject: [PATCH] [LPT] Convolution regression tests (#543) * [LPT] Base test infrastructure extending & Convolution test * [LPT] LPT test infrastructure refactoring --- ...oncat_neighboring_graph_transformation.cpp | 6 +- .../concat_transformation.cpp | 6 +- ...oncat_with_intermediate_transformation.cpp | 6 +- .../convolution_transformation.cpp | 39 ++++++ .../layer_transformation.cpp | 49 ++++++++ ...oncat_neighboring_graph_transformation.cpp | 2 +- .../concat_transformation.cpp | 2 +- ...oncat_with_intermediate_transformation.cpp | 2 +- .../convolution_transformation.cpp | 39 ++++++ .../layer_transformation.cpp | 43 +++++++ ...oncat_neighboring_graph_transformation.hpp | 4 +- .../concat_transformation.hpp | 4 +- ...oncat_with_intermediate_transformation.hpp | 4 +- .../convolution_transformation.hpp | 36 ++++++ ...oncat_neighboring_graph_transformation.cpp | 2 + .../concat_transformation.cpp | 2 + ...oncat_with_intermediate_transformation.cpp | 2 + .../convolution_transformation.cpp | 114 ++++++++++++++++++ .../layer_transformation.cpp | 74 ++++++++---- .../layer_transformation.hpp | 67 ++-------- 20 files changed, 409 insertions(+), 94 deletions(-) create mode 100644 inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/convolution_transformation.cpp create mode 100644 inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp create mode 100644 inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/convolution_transformation.cpp create mode 100644 inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp create mode 100644 inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/convolution_transformation.hpp create mode 100644 inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/convolution_transformation.cpp diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_neighboring_graph_transformation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_neighboring_graph_transformation.cpp index 23a38b7dd3b2bb..5116acce4d7311 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_neighboring_graph_transformation.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_neighboring_graph_transformation.cpp @@ -17,9 +17,9 @@ const std::vector netPrecisions = { }; const std::vector trasformationParamValues = { - LayerTestsUtils::LayerTransformationParamsFactory::createParamCpu(), - LayerTestsUtils::LayerTransformationParamsFactory::createParamI8I8(), - LayerTestsUtils::LayerTransformationParamsFactory::createParamU8I8() + LayerTestsUtils::LayerTransformationParamsFactory::createParams(), + LayerTestsUtils::LayerTransformationParamsFactory::createParamsI8I8(), + LayerTestsUtils::LayerTransformationParamsFactory::createParamsU8I8() }; INSTANTIATE_TEST_CASE_P(LPT, ConcatNeighboringGraphTransformation, diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_transformation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_transformation.cpp index f77cedbbf52b9e..bbc88cfaaabb6a 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_transformation.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_transformation.cpp @@ -17,9 +17,9 @@ const std::vector netPrecisions = { }; const std::vector trasformationParamValues = { - LayerTestsUtils::LayerTransformationParamsFactory::createParamCpu(), - LayerTestsUtils::LayerTransformationParamsFactory::createParamI8I8(), - LayerTestsUtils::LayerTransformationParamsFactory::createParamU8I8() + LayerTestsUtils::LayerTransformationParamsFactory::createParams(), + LayerTestsUtils::LayerTransformationParamsFactory::createParamsI8I8(), + LayerTestsUtils::LayerTransformationParamsFactory::createParamsU8I8() }; INSTANTIATE_TEST_CASE_P(LPT, ConcatTransformation, diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_with_intermediate_transformation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_with_intermediate_transformation.cpp index 3e739a7910dae5..32cf7fbd700376 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_with_intermediate_transformation.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/concat_with_intermediate_transformation.cpp @@ -17,9 +17,9 @@ const std::vector netPrecisions = { }; const std::vector trasformationParamValues = { - LayerTestsUtils::LayerTransformationParamsFactory::createParamCpu(), - LayerTestsUtils::LayerTransformationParamsFactory::createParamI8I8(), - LayerTestsUtils::LayerTransformationParamsFactory::createParamU8I8() + LayerTestsUtils::LayerTransformationParamsFactory::createParams(), + LayerTestsUtils::LayerTransformationParamsFactory::createParamsI8I8(), + LayerTestsUtils::LayerTransformationParamsFactory::createParamsU8I8() }; const std::vector transparentIntermediateValues = { true, false }; diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/convolution_transformation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/convolution_transformation.cpp new file mode 100644 index 00000000000000..e97ebad56132fe --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/convolution_transformation.cpp @@ -0,0 +1,39 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "low_precision_transformations/convolution_transformation.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace LayerTestsDefinitions; + +namespace { +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16 +}; + +const std::vector trasformationParamValues = { + LayerTestsUtils::LayerTransformationParamsFactory::createParams() +}; + +const std::vector fqOnActivationsValues = { true, false }; + +const std::vector fqOnWeightsValues = { true, false }; + +INSTANTIATE_TEST_CASE_P(LPT, ConvolutionTransformation, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(InferenceEngine::SizeVector({ 1, 3, 16, 16 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::ValuesIn(trasformationParamValues), + ::testing::ValuesIn(fqOnActivationsValues), + ::testing::ValuesIn(fqOnWeightsValues)), + ConvolutionTransformation::getTestCaseName); +} // namespace + + + + diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp new file mode 100644 index 00000000000000..4416509d2466f7 --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp @@ -0,0 +1,49 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include + +#include + +#include "common_test_utils/common_utils.hpp" +#include "functional_test_utils/plugin_cache.hpp" +#include "functional_test_utils/layer_test_utils.hpp" +#include "functional_test_utils/blob_utils.hpp" + +#include "ngraph_functions/pass/convert_prc.hpp" + +#include "ie_util_internal.hpp" +#include "functional_test_utils/low_precision_transformations/layer_transformation.hpp" +#include "low_precision_transformations/convolution.hpp" +#include "low_precision_transformations/scaleshift_to_convolution.hpp" + + +namespace LayerTestsUtils { + +InferenceEngine::details::LowPrecisionTransformations LayerTransformation::getLowPrecisionTransformations( + const InferenceEngine::details::LayerTransformation::Params& params) const { + return InferenceEngine::details::LowPrecisionTransformer::getAllTransformations(params). + add(InferenceEngine::details::LayerTransformation::Params(params). + setPrecisionsOnActivations({ InferenceEngine::Precision::U8 }), "Convolution"). + addCleanup( + InferenceEngine::details::LayerTransformation::Params(params).setPrecisionsOnActivations({ InferenceEngine::Precision::U8 }), + "ScaleShift"); +} + +InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsFactory::createParams() { + return InferenceEngine::details::LayerTransformation::Params( + true, + true, + true, + InferenceEngine::details::LayerTransformation::QuantizedTensorAlignment::UpdateLevel, + InferenceEngine::details::LayerTransformation::QuantizedTensorAlignment::None, + true, + true, + true); +} + +} // namespace LayerTestsUtils diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_neighboring_graph_transformation.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_neighboring_graph_transformation.cpp index b7d0c6b304d659..c2800a72271d8a 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_neighboring_graph_transformation.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_neighboring_graph_transformation.cpp @@ -16,7 +16,7 @@ const std::vector netPrecisions = { }; const std::vector trasformationParamValues = { - LayerTestsUtils::LayerTransformationParamsFactory::createParamGpu() + LayerTestsUtils::LayerTransformationParamsFactory::createParams() }; INSTANTIATE_TEST_CASE_P(LPT, ConcatNeighboringGraphTransformation, diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_transformation.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_transformation.cpp index fbfd9160129440..5f768d1458afae 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_transformation.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_transformation.cpp @@ -16,7 +16,7 @@ const std::vector netPrecisions = { }; const std::vector trasformationParamValues = { - LayerTestsUtils::LayerTransformationParamsFactory::createParamGpu() + LayerTestsUtils::LayerTransformationParamsFactory::createParams() }; INSTANTIATE_TEST_CASE_P(LPT, ConcatTransformation, diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_with_intermediate_transformation.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_with_intermediate_transformation.cpp index c0a9751247476f..e5c330f16409fb 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_with_intermediate_transformation.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/concat_with_intermediate_transformation.cpp @@ -16,7 +16,7 @@ const std::vector netPrecisions = { }; const std::vector trasformationParamValues = { - LayerTestsUtils::LayerTransformationParamsFactory::createParamGpu() + LayerTestsUtils::LayerTransformationParamsFactory::createParams() }; const std::vector transparentIntermediates = { true, false }; diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/convolution_transformation.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/convolution_transformation.cpp new file mode 100644 index 00000000000000..b99db86cf74503 --- /dev/null +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/convolution_transformation.cpp @@ -0,0 +1,39 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "low_precision_transformations/convolution_transformation.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace LayerTestsDefinitions; + +namespace { +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16 +}; + +const std::vector trasformationParamValues = { + LayerTestsUtils::LayerTransformationParamsFactory::createParams() +}; + +const std::vector fqOnActivationsValues = { true, false }; + +const std::vector fqOnWeightsValues = { true, false }; + +INSTANTIATE_TEST_CASE_P(LPT, ConvolutionTransformation, + ::testing::Combine( + ::testing::ValuesIn(netPrecisions), + ::testing::Values(InferenceEngine::SizeVector({ 1, 3, 16, 16 })), + ::testing::Values(CommonTestUtils::DEVICE_GPU), + ::testing::ValuesIn(trasformationParamValues), + ::testing::ValuesIn(fqOnActivationsValues), + ::testing::ValuesIn(fqOnWeightsValues)), + ConvolutionTransformation::getTestCaseName); +} // namespace + + + + diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp new file mode 100644 index 00000000000000..3a686050cbdf56 --- /dev/null +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/layer_transformation.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include + +#include + +#include "common_test_utils/common_utils.hpp" +#include "functional_test_utils/plugin_cache.hpp" +#include "functional_test_utils/layer_test_utils.hpp" +#include "functional_test_utils/blob_utils.hpp" + +#include "ngraph_functions/pass/convert_prc.hpp" + +#include "ie_util_internal.hpp" +#include "functional_test_utils/low_precision_transformations/layer_transformation.hpp" +#include "low_precision_transformations/convolution.hpp" +#include "low_precision_transformations/scaleshift_to_convolution.hpp" + + +namespace LayerTestsUtils { + +InferenceEngine::details::LowPrecisionTransformations LayerTransformation::getLowPrecisionTransformations( + const InferenceEngine::details::LayerTransformation::Params& params) const { + return InferenceEngine::details::LowPrecisionTransformer::getAllTransformations(params); +} + +InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsFactory::createParams() { + return InferenceEngine::details::LayerTransformation::Params( + true, + true, + true, + InferenceEngine::details::LayerTransformation::QuantizedTensorAlignment::UpdateLevel, + InferenceEngine::details::LayerTransformation::QuantizedTensorAlignment::None, + true, + true, + true); +} +} // namespace LayerTestsUtils diff --git a/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_neighboring_graph_transformation.hpp b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_neighboring_graph_transformation.hpp index 84e1e35b472711..eee5532dc44fc0 100644 --- a/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_neighboring_graph_transformation.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_neighboring_graph_transformation.hpp @@ -11,7 +11,9 @@ namespace LayerTestsDefinitions { -class ConcatNeighboringGraphTransformation : public LayerTestsUtils::LayerTransformation { +class ConcatNeighboringGraphTransformation : + public testing::WithParamInterface, + public LayerTestsUtils::LayerTransformation { public: static std::string getTestCaseName(testing::TestParamInfo obj); InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &info) const override; diff --git a/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_transformation.hpp b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_transformation.hpp index 1ccb9789004ec2..cf9aa3c605cb77 100644 --- a/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_transformation.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_transformation.hpp @@ -11,7 +11,9 @@ namespace LayerTestsDefinitions { -class ConcatTransformation : public LayerTestsUtils::LayerTransformation { +class ConcatTransformation : + public testing::WithParamInterface, + public LayerTestsUtils::LayerTransformation { public: static std::string getTestCaseName(testing::TestParamInfo obj); diff --git a/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_with_intermediate_transformation.hpp b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_with_intermediate_transformation.hpp index 30224a72f9c3d7..d1d21f33c56164 100644 --- a/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_with_intermediate_transformation.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/concat_with_intermediate_transformation.hpp @@ -20,7 +20,9 @@ typedef std::tuple< // multichannel bool> ConcatWithIntermediateTransformationParams; -class ConcatWithIntermediateTransformation : public LayerTestsUtils::LayerTransformation { +class ConcatWithIntermediateTransformation : + public testing::WithParamInterface, + public LayerTestsUtils::LayerTransformation { public: static std::string getTestCaseName(testing::TestParamInfo obj); diff --git a/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/convolution_transformation.hpp b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/convolution_transformation.hpp new file mode 100644 index 00000000000000..13f7f6ee9361fd --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/include/low_precision_transformations/convolution_transformation.hpp @@ -0,0 +1,36 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "functional_test_utils/low_precision_transformations/layer_transformation.hpp" + +namespace LayerTestsDefinitions { + +typedef std::tuple< + InferenceEngine::Precision, + InferenceEngine::SizeVector, + std::string, + InferenceEngine::details::LayerTransformation::Params, + bool, // fqOnActivations + bool // fqOnWeights +> ConvolutionTransformationParams; + +class ConvolutionTransformation : + public testing::WithParamInterface, + public LayerTestsUtils::LayerTransformation { +public: + static std::string getTestCaseName(testing::TestParamInfo obj); + +protected: + void SetUp() override; + +private: + void validate(); +}; + +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_neighboring_graph_transformation.cpp b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_neighboring_graph_transformation.cpp index 46053e77c56955..8af28552ee59d2 100644 --- a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_neighboring_graph_transformation.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_neighboring_graph_transformation.cpp @@ -132,6 +132,8 @@ void ConcatNeighboringGraphTransformation::validate() { const InferenceEngine::CNNLayerPtr outputLayer = it.second->getCreatorLayer().lock(); EXPECT_TRUE(outputLayer != nullptr); EXPECT_EQ("ScaleShift", outputLayer->type); + + checkParentPrecision(outputLayer, params.updatePrecisions); } // check quantized FQ layers map: should includes all FQ diff --git a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_transformation.cpp b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_transformation.cpp index 022473e6424f68..2a594774a54402 100644 --- a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_transformation.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_transformation.cpp @@ -89,6 +89,8 @@ void ConcatTransformation::validate() { EXPECT_TRUE(outputLayer != nullptr); EXPECT_EQ("ScaleShift", outputLayer->type); + checkParentPrecision(outputLayer, params.updatePrecisions); + IE_SUPPRESS_DEPRECATED_END } diff --git a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_with_intermediate_transformation.cpp b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_with_intermediate_transformation.cpp index ec274f03342ab2..aca75dfee2ee9e 100644 --- a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_with_intermediate_transformation.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/concat_with_intermediate_transformation.cpp @@ -172,6 +172,8 @@ void ConcatWithIntermediateTransformation::validate() { children = CNNNetworkHelper::getChildren(*concat); EXPECT_EQ(1ul, children.size()); EXPECT_EQ("ScaleShift", children[0]->type); + + checkParentPrecision(children[0], params.updatePrecisions); } else { std::vector children = CNNNetworkHelper::getChildren(*intermediate); EXPECT_EQ(2ul, children.size()); diff --git a/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/convolution_transformation.cpp b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/convolution_transformation.cpp new file mode 100644 index 00000000000000..c0f87d40c1ac80 --- /dev/null +++ b/inference-engine/tests/functional/plugin/shared/src/low_precision_transformations/convolution_transformation.cpp @@ -0,0 +1,114 @@ +// Copyright (C) 2019 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "low_precision_transformations/convolution_transformation.hpp" + +#include +#include +#include +#include + +#include + +#include "common_test_utils/common_utils.hpp" +#include "functional_test_utils/plugin_cache.hpp" +#include "functional_test_utils/layer_test_utils.hpp" +#include "functional_test_utils/blob_utils.hpp" +#include "ngraph_functions/pass/convert_prc.hpp" +#include "ngraph_functions/builders.hpp" + + +namespace LayerTestsDefinitions { + +std::string ConvolutionTransformation::getTestCaseName(testing::TestParamInfo obj) { + InferenceEngine::Precision netPrecision; + InferenceEngine::SizeVector inputShapes; + std::string targetDevice; + InferenceEngine::details::LayerTransformation::Params params; + bool fqOnActivations; + bool fqOnWeights; + std::tie(netPrecision, inputShapes, targetDevice, params, fqOnActivations, fqOnWeights) = obj.param; + + std::ostringstream result; + result << netPrecision.name() << "_" << targetDevice << "_" << toString(params) << + (fqOnActivations ? "" : "_noFqOnActivations") << + (fqOnWeights ? "" : "_noFqOnWeights"); + return result.str(); +} + +void ConvolutionTransformation::SetUp() { + threshold = 0.1f; + + InferenceEngine::SizeVector inputShape; + InferenceEngine::Precision netPrecision; + InferenceEngine::details::LayerTransformation::Params params; + bool fqOnActivations; + bool fqOnWeights; + std::tie(netPrecision, inputShape, targetDevice, params, fqOnActivations, fqOnWeights) = this->GetParam(); + auto precision = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + + const float k = 50.f; + + const auto input = std::make_shared(precision, ngraph::Shape(inputShape)); + const auto fakeQuantizeOnActivations = fqOnActivations ? + ngraph::builder::makeFakeQuantize( + input, precision, 256ul, { 1ul }, + { 0.f }, { 255.f / k }, { 0.f }, { 255.f / k }) : + nullptr; + + auto weights = ngraph::opset1::Constant::create( + precision, + ngraph::Shape{ inputShape[1], inputShape[1], 1, 1 }, + std::vector(inputShape[1] * inputShape[1], 1)); + + const auto convolution = std::make_shared( + fakeQuantizeOnActivations == nullptr ? input : fakeQuantizeOnActivations, + fqOnWeights ? + ngraph::builder::makeFakeQuantize( + weights, precision, 255ul, { 1ul }, + { -128.f / k }, { 127.f / k }, { -128.f / k }, { 127.f / k }) : + weights->output(0), + ngraph::Strides{ 1, 1 }, + ngraph::CoordinateDiff{ 0, 0 }, + ngraph::CoordinateDiff{ 0, 0 }, + ngraph::Strides{ 1, 1 }); + + ngraph::ResultVector results {std::make_shared(convolution)}; + function = std::make_shared(results, ngraph::ParameterVector { input }, "ConvolutionTransformation"); + + validate(); +} + +void ConvolutionTransformation::validate() { + InferenceEngine::SizeVector inputShape; + InferenceEngine::Precision netPrecision; + InferenceEngine::details::LayerTransformation::Params params; + bool fqOnActivations; + bool fqOnWeights; + std::tie(netPrecision, inputShape, targetDevice, params, fqOnActivations, fqOnWeights) = this->GetParam(); + + const InferenceEngine::CNNNetwork network = transform(params); + + IE_SUPPRESS_DEPRECATED_START + + InferenceEngine::OutputsDataMap outputs = network.getOutputsInfo(); + EXPECT_EQ(1, outputs.size()); + + std::map::iterator it = outputs.begin(); + const InferenceEngine::CNNLayerPtr outputLayer = it->second->getCreatorLayer().lock(); + EXPECT_TRUE(outputLayer != nullptr); + EXPECT_EQ(fqOnActivations & fqOnWeights ? "ScaleShift" : "Convolution", outputLayer->type); + + IE_SUPPRESS_DEPRECATED_END +} + +TEST_P(ConvolutionTransformation, CompareWithRefImpl) { + Run(); + + if (targetDevice == std::string{CommonTestUtils::DEVICE_GPU}) { + PluginCache::get().reset(); + } +}; + +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/low_precision_transformations/layer_transformation.cpp b/inference-engine/tests/ie_test_utils/functional_test_utils/low_precision_transformations/layer_transformation.cpp index 0d0ece7098c9bf..db998a6b626826 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/low_precision_transformations/layer_transformation.cpp +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/low_precision_transformations/layer_transformation.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -23,7 +24,8 @@ namespace LayerTestsUtils { -InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsFactory::createParamU8I8() { + +InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsFactory::createParamsU8I8() { return InferenceEngine::details::LayerTransformation::Params( false, true, @@ -37,7 +39,7 @@ InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsF { InferenceEngine::Precision::I8 }); } -InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsFactory::createParamU8U8() { +InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsFactory::createParamsU8U8() { return InferenceEngine::details::LayerTransformation::Params( false, true, @@ -51,7 +53,7 @@ InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsF { InferenceEngine::Precision::U8 }); } -InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsFactory::createParamI8I8() { +InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsFactory::createParamsI8I8() { return InferenceEngine::details::LayerTransformation::Params( false, true, @@ -65,28 +67,52 @@ InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsF { InferenceEngine::Precision::I8 }); } -InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsFactory::createParamCpu() { - return InferenceEngine::details::LayerTransformation::Params( - true, - true, - true, - InferenceEngine::details::LayerTransformation::QuantizedTensorAlignment::UpdateLevel, - InferenceEngine::details::LayerTransformation::QuantizedTensorAlignment::None, - true, - true, - true); +InferenceEngine::details::LowPrecisionTransformer LayerTransformation::getLowPrecisionTransformer( + const InferenceEngine::details::LayerTransformation::Params& params) const { + InferenceEngine::details::LowPrecisionTransformer transformer(getLowPrecisionTransformations(params)); + return transformer; } -InferenceEngine::details::LayerTransformation::Params LayerTransformationParamsFactory::createParamGpu() { - // not completed - return InferenceEngine::details::LayerTransformation::Params( - true, - true, - true, - InferenceEngine::details::LayerTransformation::QuantizedTensorAlignment::UpdateLevel, - InferenceEngine::details::LayerTransformation::QuantizedTensorAlignment::None, - true, - true, - true); +InferenceEngine::CNNNetwork LayerTransformation::transform(InferenceEngine::details::LayerTransformation::Params& params) { + InferenceEngine::details::CNNNetworkImplPtr cnnNetworkImp = cloneNet(InferenceEngine::CNNNetwork(function)); + + auto transformer = getLowPrecisionTransformer(params); + transformer.transform(*cnnNetworkImp); + + return InferenceEngine::CNNNetwork(cnnNetworkImp); +} + +InferenceEngine::CNNNetwork LayerTransformation::transform(const InferenceEngine::details::LowPrecisionTransformations& transformations) { + InferenceEngine::details::CNNNetworkImplPtr cnnNetworkImp = cloneNet(InferenceEngine::CNNNetwork(function)); + + InferenceEngine::details::LowPrecisionTransformer transformer(transformations); + transformer.transform(*cnnNetworkImp); + + return InferenceEngine::CNNNetwork(cnnNetworkImp); } + +void LayerTransformation::checkParentPrecision(const InferenceEngine::CNNLayerPtr& layer, const bool lowPrecision) { + EXPECT_EQ(1ul, layer->insData.size()) << "insert data count is no expected: " << layer->insData.size(); + const InferenceEngine::DataPtr insData = layer->insData[0].lock(); + EXPECT_TRUE(insData != nullptr) << "insert data is nullable"; + const InferenceEngine::Precision precision = insData->getTensorDesc().getPrecision(); + + const std::unordered_set expectedPrecisions = lowPrecision ? + std::unordered_set({ InferenceEngine::Precision::U8, InferenceEngine::Precision::I8 }) : + std::unordered_set({ InferenceEngine::Precision::FP16, InferenceEngine::Precision::FP32 }); + EXPECT_TRUE((expectedPrecisions.find(precision) != expectedPrecisions.end())) << + "actual precision is " << precision; +} + +std::string LayerTransformation::toString(const InferenceEngine::details::LayerTransformation::Params& params) { + std::ostringstream result; + result << + (params.supportAsymmetricQuantization ? "asymmetric" : "symmetric") << "_" << + params.precisionsOnActivations << "_" << + params.precisionsOnWeights << "_" << + params.quantizedTensorAlignmentOnActivations; + + return result.str(); +} + } // namespace LayerTestsUtils diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/low_precision_transformations/layer_transformation.hpp b/inference-engine/tests/ie_test_utils/functional_test_utils/low_precision_transformations/layer_transformation.hpp index 81a3a82fb9ba71..13fdb67581dafc 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/low_precision_transformations/layer_transformation.hpp +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/low_precision_transformations/layer_transformation.hpp @@ -21,70 +21,27 @@ typedef std::tuple< class LayerTransformationParamsFactory { public: - static InferenceEngine::details::LayerTransformation::Params createParamU8I8(); - static InferenceEngine::details::LayerTransformation::Params createParamU8U8(); - static InferenceEngine::details::LayerTransformation::Params createParamI8I8(); - static InferenceEngine::details::LayerTransformation::Params createParamCpu(); - static InferenceEngine::details::LayerTransformation::Params createParamGpu(); + static InferenceEngine::details::LayerTransformation::Params createParamsU8I8(); + static InferenceEngine::details::LayerTransformation::Params createParamsU8U8(); + static InferenceEngine::details::LayerTransformation::Params createParamsI8I8(); + static InferenceEngine::details::LayerTransformation::Params createParams(); }; -template -class LayerTransformation : public testing::WithParamInterface, public LayerTestsUtils::LayerTestsCommon { -public: +class LayerTransformation : public LayerTestsUtils::LayerTestsCommon { +protected: InferenceEngine::details::LowPrecisionTransformations getLowPrecisionTransformations( - const InferenceEngine::details::LayerTransformation::Params& params) const { - if (targetDevice == "CPU") { - return InferenceEngine::details::LowPrecisionTransformer::getAllTransformations(params). - add(InferenceEngine::details::LayerTransformation::Params(params). - setPrecisionsOnActivations({ InferenceEngine::Precision::U8 }), "Convolution"). - addCleanup( - InferenceEngine::details::LayerTransformation::Params(params).setPrecisionsOnActivations({ InferenceEngine::Precision::U8 }), - "ScaleShift"); - } else if (targetDevice == "GPU") { - return InferenceEngine::details::LowPrecisionTransformer::getAllTransformations(params); - } else { - THROW_IE_EXCEPTION << "unknown target device " << targetDevice; - } - } + const InferenceEngine::details::LayerTransformation::Params& params) const; InferenceEngine::details::LowPrecisionTransformer getLowPrecisionTransformer( - const InferenceEngine::details::LayerTransformation::Params& params) const { - InferenceEngine::details::LowPrecisionTransformer transformer(getLowPrecisionTransformations(params)); - return transformer; - } - - InferenceEngine::CNNNetwork transform() { - return transform(LayerTransformationParamsFactory::createParamCpu()); - } - - InferenceEngine::CNNNetwork transform(InferenceEngine::details::LayerTransformation::Params& params) { - InferenceEngine::details::CNNNetworkImplPtr cnnNetworkImp = cloneNet(InferenceEngine::CNNNetwork(function)); - - auto transformer = getLowPrecisionTransformer(params); - transformer.transform(*cnnNetworkImp); - - return InferenceEngine::CNNNetwork(cnnNetworkImp); - } - - InferenceEngine::CNNNetwork transform(const InferenceEngine::details::LowPrecisionTransformations& transformations) { - InferenceEngine::details::CNNNetworkImplPtr cnnNetworkImp = cloneNet(InferenceEngine::CNNNetwork(function)); + const InferenceEngine::details::LayerTransformation::Params& params) const; - InferenceEngine::details::LowPrecisionTransformer transformer(transformations); - transformer.transform(*cnnNetworkImp); + InferenceEngine::CNNNetwork transform(InferenceEngine::details::LayerTransformation::Params& params); - return InferenceEngine::CNNNetwork(cnnNetworkImp); - } + InferenceEngine::CNNNetwork transform(const InferenceEngine::details::LowPrecisionTransformations& transformations); - static std::string toString(const InferenceEngine::details::LayerTransformation::Params& params) { - std::ostringstream result; - result << - (params.supportAsymmetricQuantization ? "asymmetric" : "symmetric") << "_" << - params.precisionsOnActivations << "_" << - params.precisionsOnWeights << "_" << - params.quantizedTensorAlignmentOnActivations; + static void checkParentPrecision(const InferenceEngine::CNNLayerPtr& layer, const bool lowPrecision); - return result.str(); - } + static std::string toString(const InferenceEngine::details::LayerTransformation::Params& params); }; } // namespace LayerTestsUtils