diff --git a/inference-engine/src/low_precision_transformations/src/add.cpp b/inference-engine/src/low_precision_transformations/src/add.cpp index daddb07a6ef..f284d106fd4 100644 --- a/inference-engine/src/low_precision_transformations/src/add.cpp +++ b/inference-engine/src/low_precision_transformations/src/add.cpp @@ -90,7 +90,7 @@ void AddTransformation::registerMatcherIn(GraphRewrite &pass, TransformationCont bool AddTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher &m) const { std::shared_ptr op = as_type_ptr(m.get_match_root()); - if (!canBeTransformed(context, op)) { + if ((op == nullptr) || (!canBeTransformed(context, op))) { return false; } diff --git a/inference-engine/src/low_precision_transformations/src/mvn.cpp b/inference-engine/src/low_precision_transformations/src/mvn.cpp index b4540d22ccd..1057569cea9 100644 --- a/inference-engine/src/low_precision_transformations/src/mvn.cpp +++ b/inference-engine/src/low_precision_transformations/src/mvn.cpp @@ -46,6 +46,9 @@ bool MVNTransformation::canBeTransformed(const TransformationContext& context, s } auto mvn = as_type_ptr(operation); + if (mvn == nullptr) { + return false; + } const std::shared_ptr multiply = mvn->get_input_node_shared_ptr(0); auto scalesConst = as_type_ptr(multiply->get_input_node_shared_ptr(1)); diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/lpt_public_methods_test.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/lpt_public_methods_test.cpp new file mode 100644 index 00000000000..94be9f4f36c --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/lpt_public_methods_test.cpp @@ -0,0 +1,56 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include + +#include + +#include + +#include "common_test_utils/ngraph_test_utils.hpp" +#include "low_precision/transformer.hpp" + +using namespace testing; +using namespace ngraph; +using namespace ngraph::pass; + +TEST(LPT, isPrecisionPreservedTransformation) { + const auto layer = std::make_shared(element::f32, Shape{ 1, 3, 16, 16 }); + const auto transformations = low_precision::LowPrecisionTransformer::getAllTransformations(); + + for (const auto& transformation : transformations.transformations) { + ASSERT_NO_THROW(transformation.second->isPrecisionPreserved(layer)); + } +} + +TEST(LPT, canBeTransformedTransformation) { + const auto input = std::make_shared(element::f32, Shape{ 1, 3, 16, 16 }); + const auto mulConst = op::v0::Constant::create(element::f32, Shape{}, { 1.f }); + const auto mul = std::make_shared(input, mulConst); + const auto shapeConst = op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{ 4 }, { 1, 3, 16, 16 }); + const auto layer = std::make_shared(mul, shapeConst, true); + + ngraph::ResultVector results{ std::make_shared(layer) }; + const auto function = std::make_shared(results, ngraph::ParameterVector{ input }, "TestFunction"); + + const auto transformations = low_precision::LowPrecisionTransformer::getAllTransformations(); + for (const auto& transformation : transformations.transformations) { + ASSERT_NO_THROW(transformation.second->canBeTransformed(low_precision::TransformationContext(function), layer)); + } +} + +TEST(LPT, isQuantizedTransformation) { + const auto input = std::make_shared(element::f32, Shape{ 1, 3, 16, 16 }); + const auto mulConst = op::v0::Constant::create(element::f32, Shape{}, { 1.f }); + const auto mul = std::make_shared(input, mulConst); + const auto shapeConst = op::v0::Constant::create(ngraph::element::i64, ngraph::Shape{ 4 }, { 1, 3, 16, 16 }); + const auto layer = std::make_shared(mul, shapeConst, true); + + const auto transformations = low_precision::LowPrecisionTransformer::getAllTransformations(); + for (const auto& transformation : transformations.transformations) { + ASSERT_NO_THROW(transformation.second->isQuantized(layer)); + } +}