avg_pool.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 
17 #pragma once
18 
19 #include "ngraph/op/op.hpp"
20 #include "ngraph/op/util/attr_types.hpp"
21 
22 namespace ngraph
23 {
24  namespace op
25  {
26  namespace v1
27  {
28  /// \brief Batched average pooling operation.
29  ///
30  class NGRAPH_API AvgPool : public Op
31  {
32  public:
33  NGRAPH_RTTI_DECLARATION;
34 
35  /// \brief Constructs a batched average pooling operation.
36  AvgPool() = default;
37 
38  ///
39  /// \brief Constructs a batched average pooling operation.
40  ///
41  /// \param arg The output producing the input data batch tensor.<br>
42  /// `[d1, dn]`
43  /// \param strides The strides.<br> `[n]`
44  /// \param pads_begin The beginning of padding shape.<br> `[n]`
45  /// \param pads_end The end of padding shape.<br> `[n]`
46  /// \param kernel The kernel shape.<br> `[n]`
47  /// \param exclude_pad If false then averages include padding elements, each
48  /// treated as the number zero. If true, padding
49  /// elements
50  /// are entirely ignored when computing averages.
51  /// \param rounding_type Whether to use ceiling or floor rounding type while
52  /// computing output shape.
53  /// \param auto_pad Padding type to use for additional padded dimensions
54  ///
55  AvgPool(const Output<Node>& arg,
56  const Strides& strides,
57  const Shape& pads_begin,
58  const Shape& pads_end,
59  const Shape& kernel,
60  bool exclude_pad,
61  op::RoundingType rounding_type,
62  const PadType& auto_pad);
63 
64  ///
65  /// \brief Constructs a batched average pooling operation.
66  ///
67  /// \param arg The output producing the input data batch tensor.<br>
68  /// `[d1, dn]`
69  /// \param strides The strides.<br> `[n]`
70  /// \param pads_begin The beginning of padding shape.<br> `[n]`
71  /// \param pads_end The end of padding shape.<br> `[n]`
72  /// \param kernel The kernel shape.<br> `[n]`
73  /// \param exclude_pad If false then averages include padding elements, each
74  /// treated as the number zero. If true, padding
75  /// elements
76  /// are entirely ignored when computing averages.
77  /// \param rounding_type Whether to use ceiling or floor rounding type while
78  /// computing output shape.
79  ///
80  AvgPool(const Output<Node>& arg,
81  const Strides& strides,
82  const Shape& pads_begin,
83  const Shape& pads_end,
84  const Shape& kernel,
85  bool exclude_pad,
86  op::RoundingType rounding_type);
87 
88  size_t get_version() const override { return 1; }
89  void validate_and_infer_types() override;
90  bool visit_attributes(AttributeVisitor& visitor) override;
91 
92  virtual std::shared_ptr<Node>
93  clone_with_new_inputs(const OutputVector& new_args) const override;
94 
95  /// \return The kernel shape.
96  const Shape& get_kernel() const;
97  void set_kernel(const Shape& kernel);
98  /// \return The strides.
99  const Strides& get_strides() const;
100  void set_strides(const Strides& strides);
101  /// \return The beginning of padding shape.
102  const Shape& get_pads_begin() const;
103  void set_pads_begin(const Shape& pads_begin);
104  /// \return The end of padding shape.
105  const Shape& get_pads_end() const;
106  void set_pads_end(const Shape& pads_end);
107  bool get_exclude_pad() const;
108  void set_exclude_pad(bool exclude_pad);
109  /// \return The pad type for pooling.
110  const PadType& get_auto_pad() const;
111  void set_auto_pad(const PadType& auto_pad);
112  op::RoundingType get_rounding_type() const;
113  void set_rounding_type(op::RoundingType rounding_type);
114  /// \return The default value for AvgPool.
115  virtual std::shared_ptr<Node> get_default_value() const override;
116 
117  protected:
118  Shape m_kernel;
119  Strides m_strides;
120  Shape m_pads_begin;
121  Shape m_pads_end;
122  bool m_exclude_pad{true};
123  PadType m_auto_pad{PadType::EXPLICIT};
124  op::RoundingType m_rounding_type{op::RoundingType::FLOOR};
125  };
126  } // namespace v1
127 
128  using v1::AvgPool;
129  } // namespace op
130 } // namespace ngraph
ngraph::op::v1::AvgPool::get_strides
const Strides & get_strides() const
ngraph::op::v1::AvgPool::get_pads_begin
const Shape & get_pads_begin() const
ngraph::op::PadType
PadType
Padding Type used for Convolution and Pooling
Definition: attr_types.hpp:71
ngraph::op::v1::AvgPool::get_default_value
virtual std::shared_ptr< Node > get_default_value() const override
ngraph::op::RoundingType
RoundingType
Rounding Type used for Pooling operators.
Definition: attr_types.hpp:101
ngraph::op::v1::AvgPool::validate_and_infer_types
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ngraph::op::v1::AvgPool::get_auto_pad
const PadType & get_auto_pad() const
ngraph::op::v1::AvgPool::AvgPool
AvgPool(const Output< Node > &arg, const Strides &strides, const Shape &pads_begin, const Shape &pads_end, const Shape &kernel, bool exclude_pad, op::RoundingType rounding_type)
Constructs a batched average pooling operation.
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::op::v1::AvgPool::AvgPool
AvgPool(const Output< Node > &arg, const Strides &strides, const Shape &pads_begin, const Shape &pads_end, const Shape &kernel, bool exclude_pad, op::RoundingType rounding_type, const PadType &auto_pad)
Constructs a batched average pooling operation.
ngraph::op::v1::AvgPool::get_kernel
const Shape & get_kernel() const
ngraph::op::v1::AvgPool::get_version
size_t get_version() const override
Definition: avg_pool.hpp:88
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::v1::AvgPool::AvgPool
AvgPool()=default
Constructs a batched average pooling operation.
ngraph::op::v1::AvgPool::get_pads_end
const Shape & get_pads_end() const
ngraph::op::v1::AvgPool
Batched average pooling operation.
Definition: avg_pool.hpp:31
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29