1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
5 #include "low_precision/relu.hpp"
11 #include "low_precision/common/ie_lpt_exception.hpp"
12 #include "low_precision/network_helper.hpp"
16 namespace low_precision {
18 void ReluTransformation::registerMatcherIn(GraphRewrite &pass, TransformationContext &context) const {
22 make_op_pattern<opset1::Relu>({ make_op_label<opset1::Multiply>()}));
25 bool ReluTransformation::transform(TransformationContext& context, ngraph::pattern::Matcher &m) const {
26 std::shared_ptr<Node> relu = m.get_match_root();
27 if (!LayerTransformation::canBeTransformed(context, relu)) {
31 if (!canBeTransformed(context, relu)) {
35 relu = separateInStandaloneBranch(relu);
36 const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(relu, 0);
37 moveDequantizationAfter(context, relu, dequantization, false, false);
41 bool ReluTransformation::isPrecisionPreserved(std::shared_ptr<Node> op) const noexcept {
45 bool ReluTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr<Node> op) const {
46 if (!LayerTransformation::canBeTransformed(context, op)) {
50 const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(op, 0);
51 if (dequantization.empty()) {
55 if (!canSubtractBeHandled(op, dequantization)) {
59 const std::shared_ptr<opset1::Constant> constant = as_type_ptr<opset1::Constant>(dequantization.multiply->input_value(1).get_node_shared_ptr());
60 const auto scales = constant->cast_vector<float>();
61 if (std::any_of(scales.begin(), scales.end(), [](const float value) { return value < 0.f; })) {
68 } // namespace low_precision