1 // Copyright (C) 2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
5 #include "ngraph_functions/low_precision_transformations/max_pool_function.hpp"
7 #include <ngraph/opsets/opset1.hpp>
8 #include <ngraph_ops/type_relaxed.hpp>
9 #include "low_precision/network_helper.hpp"
10 #include "ngraph_functions/subgraph_builders.hpp"
11 #include "ngraph_functions/low_precision_transformations/common/builders.hpp"
17 std::shared_ptr<ngraph::Function> MaxPoolFunction::getOriginal(
18 const ngraph::element::Type originalFunctionPrecision,
19 const ngraph::Shape& inputShape,
20 const FakeQuantizeOnData& fakeQuantizeOnData) {
21 const auto input = std::make_shared<ngraph::opset1::Parameter>(originalFunctionPrecision, ngraph::Shape(inputShape));
23 const auto fakeQuantize = ngraph::builder::makeFakeQuantize(
24 input, originalFunctionPrecision, fakeQuantizeOnData.quantizationLevel, fakeQuantizeOnData.constantShape,
25 fakeQuantizeOnData.inputLowValues, fakeQuantizeOnData.inputHighValues, fakeQuantizeOnData.outputLowValues, fakeQuantizeOnData.outputHighValues);
27 const std::shared_ptr<ngraph::Node> maxPool = std::make_shared<ngraph::opset1::MaxPool>(
33 op::RoundingType::FLOOR);
35 ngraph::ResultVector results{ std::make_shared<ngraph::opset1::Result>(maxPool) };
36 return std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{ input }, "MaxPoolTransformation");
39 std::shared_ptr<ngraph::Function> MaxPoolFunction::get(
40 const ngraph::Shape& inputShape,
41 const ngraph::element::Type precisionBeforeDequantization,
42 const ngraph::builder::subgraph::DequantizationOperations& dequantizationBefore,
43 const ngraph::builder::subgraph::DequantizationOperations& dequantizationAfter) {
44 const auto input = std::make_shared<ngraph::opset1::Parameter>(precisionBeforeDequantization, ngraph::Shape(inputShape));
45 std::shared_ptr<ngraph::Node> parent = input;
47 parent = dequantizationBefore.empty() ? parent : makeDequantization(parent, dequantizationBefore);
49 const std::shared_ptr<ngraph::Node> maxPool = std::make_shared<ngraph::opset1::MaxPool>(
55 op::RoundingType::FLOOR);
58 parent = dequantizationAfter.empty() ? maxPool : makeDequantization(maxPool, dequantizationAfter);
59 maxPool->set_friendly_name("maxPool");
61 const std::shared_ptr<ngraph::opset1::Result> result = std::make_shared<ngraph::opset1::Result>(parent);
63 const std::shared_ptr<ngraph::Function> function = std::make_shared<ngraph::Function>(
64 ngraph::ResultVector{ result },
65 std::vector<std::shared_ptr<ngraph::op::Parameter>> { input },
66 "MaxPoolTransformation");
70 } // namespace subgraph
71 } // namespace builder