pooling_factory.hpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16 #pragma once
17 
18 #include <memory>
19 #include <type_traits>
20 
21 #include "ngraph/node.hpp"
22 #include "ngraph/op/avg_pool.hpp"
23 #include "ngraph/op/max_pool.hpp"
24 #include "ngraph/op/op.hpp"
25 #include "ngraph/op/util/attr_types.hpp"
26 #include "ngraph/shape.hpp"
27 #include "ngraph/strides.hpp"
28 #include "onnx_import/core/node.hpp"
29 
30 namespace ngraph
31 {
32  namespace onnx_import
33  {
34  namespace pooling
35  {
36  ///
37  /// \brief Factory class which generates sub-graphs for ONNX 'regular' pooling
38  /// operators.
39  ///
40  /// \note This factory is intended for creating pooling operations like:
41  /// - AveragePool
42  /// - MaxPool
43  ///
44  /// This base class holds all common attributes like srides, dilations,
45  /// paddings, kernel shape and auto_pad type.
46  ///
47  /// \see GlobalPoolingFactory
49  {
50  public:
51  virtual ~PoolingFactory() = default;
52 
53  ///
54  /// \brief Creates average pooling ONNX operation.
55  /// \return Vector of output nodes.
56  ///
57  OutputVector make_avg_pool() const;
58 
59  ///
60  /// \brief Creates max pooling ONNX operation.
61  /// \return Vector of output nodes.
62  ///
63  OutputVector make_max_pool() const;
64 
65  protected:
66  explicit PoolingFactory(const Node& node);
67 
68  Node m_onnx_node;
69  const OutputVector m_inputs;
70  Shape m_kernel_shape;
71  Strides m_strides;
72  Strides m_dilations;
73  Shape m_padding_below;
74  Shape m_padding_above;
75  ngraph::op::PadType m_auto_pad;
76  };
77 
78  ///
79  /// \brief Factory class which generates sub-graphs for ONNX 'local' pooling
80  /// operators.
81  /// \note For a 'local' pooling operation, the kernel shape attribute is required
83  {
84  public:
85  explicit LocalPoolingFactory(const Node& node);
86  virtual ~LocalPoolingFactory() = default;
87  };
88 
89  ///
90  /// \brief Factory class which generates sub-graphs for ONNX 'global' pooling
91  /// operators.
92  /// \note In a 'global' pooling operation, the kernel shape is calculated
93  /// based on spatial dims
95  {
96  public:
97  explicit GlobalPoolingFactory(const Node& node);
98  virtual ~GlobalPoolingFactory() = default;
99  };
100 
101  } // namespace pooling
102  } // namespace onnx_import
103 } // namespace ngraph
ngraph::op::PadType
PadType
Padding Type used for Convolution and Pooling
Definition: attr_types.hpp:71
ngraph::onnx_import::pooling::PoolingFactory::make_max_pool
OutputVector make_max_pool() const
Creates max pooling ONNX operation.
ngraph::onnx_import::pooling::PoolingFactory::make_avg_pool
OutputVector make_avg_pool() const
Creates average pooling ONNX operation.
ngraph::onnx_import::Node
Definition: node.hpp:56
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::onnx_import::pooling::LocalPoolingFactory
Factory class which generates sub-graphs for ONNX 'local' pooling operators.
Definition: pooling_factory.hpp:83
ngraph::onnx_import::pooling::PoolingFactory
Factory class which generates sub-graphs for ONNX 'regular' pooling operators.
Definition: pooling_factory.hpp:49
ngraph::onnx_import::pooling::GlobalPoolingFactory
Factory class which generates sub-graphs for ONNX 'global' pooling operators.
Definition: pooling_factory.hpp:95