1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
5 #include <gtest/gtest.h>
6 #include <inference_engine/shape_infer/built-in/ie_built_in_holder.hpp>
7 #include <xml_net_builder.hpp>
8 #include <inference_engine/cnn_network_impl.hpp>
9 #include <inference_engine/ie_format_parser.h>
10 #include <xml_helper.hpp>
11 #include <inference_engine/shape_infer/ie_reshaper.hpp>
12 #include "built_in_shape_infer_general_test.hpp"
14 using namespace InferenceEngine;
15 using namespace ShapeInfer;
17 class BuiltInShapeInferPoolImplTest
18 : public BuiltInShapeInferTestWithParam<std::tuple<InOutShapes, kernel, stride, pad, pool_type, exclude_pad, auto_pad, NewInOutShapes, pad_end>> {
20 void SetUp() override {
21 BuiltInShapeInferCommon::SetUp();
22 auto params = GetParam();
23 inOutShapes = std::get<0>(params);
24 kernel = std::get<1>(params);
25 stride = std::get<2>(params);
26 pad = std::get<3>(params);
27 pool_type = std::get<4>(params);
28 exclude_pad = std::get<5>(params);
29 auto_pad = std::get<6>(params);
30 newInOutShapes = std::get<7>(params);
31 pad_end = std::get<8>(params);
34 std::map<std::string, std::string> getMapParams() {
35 std::map<std::string, std::string> params = {
36 {"kernel", kernel.toSeparetedRow(",")},
37 {"strides", stride.toSeparetedRow(",")},
38 {"pads_begin", pad.toSeparetedRow(",")},
39 {"pool-method", pool_type},
40 {"exclude-pad", exclude_pad ? "false" : "true"}
42 if (!auto_pad.empty()) params["auto_pad"] = auto_pad;
43 if (!pad_end.empty()) params["pads_end"] = pad_end.toSeparetedRow(",");
48 std::string type = "Pooling";
49 testing::InOutShapes inOutShapes;
50 testing::InOutShapes newInOutShapes;
54 std::string pool_type;
60 TEST_P(BuiltInShapeInferPoolImplTest, body) {
61 auto impl = getShapeInferImpl(type);
62 ASSERT_NE(nullptr, impl);
63 ASSERT_NO_THROW(sts = impl->inferShapes(getBlobs(inOutShapes.inDims), getMapParams(), blobs, outShapes, &resp));
64 ASSERT_EQ(int(OK), sts) << resp.msg;
65 ASSERT_EQ(inOutShapes.outDims, outShapes);
68 TEST_P(BuiltInShapeInferPoolImplTest, reshaper) {
69 auto layerParams = getMapParams();
70 auto cnnNetworkImplPtr = buildSingleLayerNetwork<4>(type, inOutShapes, &layerParams, "pooling_data");
71 auto reshaper = std::make_shared<Reshaper>(*cnnNetworkImplPtr);
72 auto inputShapes = setInputShapes(*cnnNetworkImplPtr, newInOutShapes.inDims);
73 reshaper->run(inputShapes);
74 checkNetworkInOut(*cnnNetworkImplPtr, newInOutShapes);
77 TEST_P(BuiltInShapeInferPoolImplTest, batch) {
78 auto layerParams = getMapParams();
79 auto cnnNetworkImplPtr = buildSingleLayerNetwork<4>(type, inOutShapes, &layerParams, "pooling_data");
80 auto reshaper = std::make_shared<Reshaper>(*cnnNetworkImplPtr);
81 sts = cnnNetworkImplPtr->setBatchSize(BATCH, &resp);
82 ASSERT_EQ((int)OK, sts) << resp.msg;
83 inOutShapes.inDims[0][0] = inOutShapes.outDims[0][0] = BATCH;
84 checkNetworkInOut(*cnnNetworkImplPtr, inOutShapes);
87 INSTANTIATE_TEST_CASE_P(
88 BuiltInImpls, BuiltInShapeInferPoolImplTest,
91 ::testing::make_tuple(InOutShapes({{{4, 3, 228, 228}},
92 {{4, 3, 229, 115}}}), kernel({4, 2}), stride({2, 1}),
93 pad({2, 1}), pool_type("max"), exclude_pad(true), auto_pad(""),
94 NewInOutShapes({{{1, 3, 228, 228}},
95 {{1, 3, 229, 115}}}), pad_end()),
96 // fixate pad + right/bottom
97 ::testing::make_tuple(InOutShapes({{{4, 3, 228, 228}},
98 {{4, 3, 229, 115}}}), kernel({4, 2}), stride({2, 1}),
99 pad({2, 1}), pool_type("max"), exclude_pad(true), auto_pad(""),
100 NewInOutShapes({{{1, 3, 228, 228}},
101 {{1, 3, 229, 115}}}), pad_end({3, 2})),
102 // valid + empty paddings
103 ::testing::make_tuple(InOutShapes({{{4, 3, 228, 228}},
104 {{4, 3, 227, 113}}}), kernel({4, 2}), stride({2, 1}),
105 pad({0, 0}), pool_type("max"), exclude_pad(true), auto_pad("valid"),
106 NewInOutShapes({{{1, 3, 228, 228}},
107 {{1, 3, 227, 113}}}), pad_end()),
108 // valid + fixated paddings (shouldn't affect)
109 ::testing::make_tuple(InOutShapes({{{4, 3, 228, 228}},
110 {{4, 3, 227, 113}}}), kernel({4, 2}), stride({2, 1}),
111 pad({2, 4}), pool_type("max"), exclude_pad(true), auto_pad("valid"),
112 NewInOutShapes({{{1, 3, 228, 228}},
113 {{1, 3, 227, 113}}}), pad_end({2, 1})),
114 // same_upper + empty paddings
115 ::testing::make_tuple(InOutShapes({{{4, 3, 227, 227}},
116 {{4, 3, 227, 114}}}), kernel({4, 2}), stride({2, 1}),
117 pad({0, 0}), pool_type("max"), exclude_pad(true), auto_pad("same_upper"),
118 NewInOutShapes({{{1, 3, 227, 227}},
119 {{1, 3, 227, 114}}}), pad_end()),
120 // same_upper + fixated paddings (shouldn't affect)
121 ::testing::make_tuple(InOutShapes({{{4, 3, 227, 227}},
122 {{4, 3, 227, 114}}}), kernel({4, 2}), stride({2, 1}),
123 pad({2, 4}), pool_type("max"), exclude_pad(true), auto_pad("same_upper"),
124 NewInOutShapes({{{1, 3, 227, 227}},
125 {{1, 3, 227, 114}}}), pad_end({0, 0})),
126 // same_lower + empty paddings
127 ::testing::make_tuple(InOutShapes({{{4, 3, 227, 227}},
128 {{4, 3, 227, 113}}}), kernel({4, 2}), stride({2, 1}),
129 pad({0, 0}), pool_type("max"), exclude_pad(true), auto_pad("same_lower"),
130 NewInOutShapes({{{1, 3, 227, 227}},
131 {{1, 3, 227, 113}}}), pad_end({0, 0})),
132 // same_lower + fixated paddings (shouldn't affect)
133 ::testing::make_tuple(InOutShapes({{{4, 3, 227, 227}},
134 {{4, 3, 227, 113}}}), kernel({4, 2}), stride({2, 1}),
135 pad({2, 4}), pool_type("max"), exclude_pad(true), auto_pad("same_lower"),
136 NewInOutShapes({{{1, 3, 227, 227}},
137 {{1, 3, 227, 113}}}), pad_end({0, 0})),
140 ::testing::make_tuple(InOutShapes({{{4, 3, 16, 128, 130}},
141 {{4, 3, 17, 129, 66}}}), kernel({4, 2, 2}), stride({2, 1, 1}),
142 pad({2, 1, 1}), pool_type("max"), exclude_pad(true), auto_pad(""),
143 NewInOutShapes({{{1, 3, 16, 128, 130}},
144 {{1, 3, 17, 129, 66}}}), pad_end()),
145 // valid + empty paddings
146 ::testing::make_tuple(InOutShapes({{{4, 3, 16, 128, 130}},
147 {{4, 3, 15, 127, 64}}}), kernel({4, 2, 2}), stride({2, 1, 1}),
148 pad({0, 0, 0}), pool_type("max"), exclude_pad(true), auto_pad("valid"),
149 NewInOutShapes({{{1, 3, 16, 128, 130}},
150 {{1, 3, 15, 127, 64}}}), pad_end()),
151 // same_upper + empty paddings
152 ::testing::make_tuple(InOutShapes({{{4, 3, 16, 128, 130}},
153 {{4, 3, 16, 128, 65}}}), kernel({4, 2, 2}), stride({2, 1, 1}),
154 pad({0, 0, 0}), pool_type("max"), exclude_pad(true), auto_pad("same_upper"),
155 NewInOutShapes({{{1, 3, 16, 128, 130}},
156 {{1, 3, 16, 128, 65}}}), pad_end())