[LPT] POT support: absent convert fix & element-wise empty dequantization data (...
[platform/upstream/dldt.git] / inference-engine / tests / ngraph_functions / src / low_precision_transformations / max_pool_function.cpp
1 // Copyright (C) 2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include "ngraph_functions/low_precision_transformations/max_pool_function.hpp"
6
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"
12
13 namespace ngraph {
14 namespace builder {
15 namespace subgraph {
16
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));
22
23     const auto fakeQuantize = ngraph::builder::makeFakeQuantize(
24         input, originalFunctionPrecision, fakeQuantizeOnData.quantizationLevel, fakeQuantizeOnData.constantShape,
25         fakeQuantizeOnData.inputLowValues, fakeQuantizeOnData.inputHighValues, fakeQuantizeOnData.outputLowValues, fakeQuantizeOnData.outputHighValues);
26
27     const std::shared_ptr<ngraph::Node> maxPool = std::make_shared<ngraph::opset1::MaxPool>(
28         fakeQuantize,
29         Strides{ 1, 1 },
30         Shape{ 1, 1 },
31         Shape{ 0, 0 },
32         Shape{ 2, 2 },
33         op::RoundingType::FLOOR);
34
35     ngraph::ResultVector results{ std::make_shared<ngraph::opset1::Result>(maxPool) };
36     return std::make_shared<ngraph::Function>(results, ngraph::ParameterVector{ input }, "MaxPoolTransformation");
37 }
38
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;
46
47     parent = dequantizationBefore.empty() ? parent : makeDequantization(parent, dequantizationBefore);
48
49     const std::shared_ptr<ngraph::Node> maxPool = std::make_shared<ngraph::opset1::MaxPool>(
50         parent,
51         Strides{ 1, 1 },
52         Shape{ 1, 1 },
53         Shape{ 0, 0 },
54         Shape{ 2, 2 },
55         op::RoundingType::FLOOR);
56     parent = maxPool;
57
58     parent = dequantizationAfter.empty() ? maxPool : makeDequantization(maxPool, dequantizationAfter);
59     maxPool->set_friendly_name("maxPool");
60
61     const std::shared_ptr<ngraph::opset1::Result> result = std::make_shared<ngraph::opset1::Result>(parent);
62
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");
67     return function;
68 }
69
70 }  // namespace subgraph
71 }  // namespace builder
72 }  // namespace ngraph