1 // Copyright (C) 2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
5 #include "layer_transformation.hpp"
10 #include <gtest/gtest.h>
12 #include <transformations/utils/utils.hpp>
13 #include <transformations/init_node_info.hpp>
14 #include <low_precision/max_pool.hpp>
15 #include <low_precision/transformer.hpp>
17 #include "common_test_utils/ngraph_test_utils.hpp"
18 #include "simple_low_precision_transformer.hpp"
19 #include "ngraph_functions/low_precision_transformations/max_pool_function.hpp"
21 using namespace testing;
22 using namespace ngraph::pass;
24 class MaxPoolTransformationTestValues {
26 low_precision::LayerTransformation::Params params;
27 std::vector<float> subtractValues;
28 std::vector<float> mutliplyValues;
32 ngraph::element::Type,
34 MaxPoolTransformationTestValues> MaxPoolTransformationParams;
36 class MaxPoolTransformation : public LayerTransformation, public testing::WithParamInterface<MaxPoolTransformationParams> {
38 void SetUp() override {
39 const ngraph::element::Type precision = std::get<0>(GetParam());
40 const ngraph::Shape shape = std::get<1>(GetParam());
41 const MaxPoolTransformationTestValues testValues = std::get<2>(GetParam());
43 actualFunction = ngraph::builder::subgraph::MaxPoolFunction::getOriginal(
47 testValues.params.updatePrecisions ? testValues.params.precisionsOnActivations[0] : precision,
48 testValues.subtractValues,
49 testValues.mutliplyValues
52 SimpleLowPrecisionTransformer transform;
53 transform.add<ngraph::pass::low_precision::MaxPoolTransformation, ngraph::opset1::MaxPool>(testValues.params);
54 transform.transform(actualFunction);
56 referenceFunction = ngraph::builder::subgraph::MaxPoolFunction::getReference(
60 testValues.params.updatePrecisions ? testValues.params.precisionsOnActivations[0] : precision,
61 testValues.subtractValues,
62 testValues.mutliplyValues
66 static std::string getTestCaseName(testing::TestParamInfo<MaxPoolTransformationParams> obj) {
67 const ngraph::element::Type precision = std::get<0>(obj.param);
68 const ngraph::Shape shape = std::get<1>(obj.param);
69 const MaxPoolTransformationTestValues testValues = std::get<2>(obj.param);
71 std::ostringstream result;
73 LayerTransformation::getTestCaseNameByParams(precision, shape, testValues.params) << "_" <<
74 testValues.subtractValues.size() << "_" <<
75 testValues.mutliplyValues.size() << "_";
80 TEST_P(MaxPoolTransformation, CompareFunctions) {
81 actualFunction->validate_nodes_and_infer_types();
82 auto res = compare_functions(referenceFunction, actualFunction, true, true, true);
83 ASSERT_TRUE(res.first) << res.second;
86 const std::vector<ngraph::element::Type> precisions = {
88 // ngraph::element::f16
91 const std::vector<ngraph::Shape> shapes = {
95 const std::vector<MaxPoolTransformationTestValues> testValues = {
96 { LayerTransformation::createParamsU8I8(), { 128 }, { 0.02f } },
97 { LayerTransformation::createParamsU8I8(), {}, { 0.02f } },
98 { LayerTransformation::createParamsU8I8().setUpdatePrecisions(false), { 128 }, { 0.02f } },
99 { LayerTransformation::createParamsU8I8().setUpdatePrecisions(false), {}, { 0.02f } },
100 { LayerTransformation::createParamsI8I8(), { 128 }, { 0.02f } },
103 INSTANTIATE_TEST_CASE_P(
105 MaxPoolTransformation,
107 ::testing::ValuesIn(precisions),
108 ::testing::ValuesIn(shapes),
109 ::testing::ValuesIn(testValues)),
110 MaxPoolTransformation::getTestCaseName);