avg_pool.hpp
1 //*****************************************************************************
2 // Copyright 2017-2021 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 = op::RoundingType::FLOOR,
62  const PadType& auto_pad = op::PadType::EXPLICIT);
63 
64  size_t get_version() const override { return 1; }
65  void validate_and_infer_types() override;
66  bool visit_attributes(AttributeVisitor& visitor) override;
67 
68  virtual std::shared_ptr<Node>
69  clone_with_new_inputs(const OutputVector& new_args) const override;
70 
71  /// \return The kernel shape.
72  const Shape& get_kernel() const;
73  void set_kernel(const Shape& kernel);
74  /// \return The strides.
75  const Strides& get_strides() const;
76  void set_strides(const Strides& strides);
77  /// \return The beginning of padding shape.
78  const Shape& get_pads_begin() const;
79  void set_pads_begin(const Shape& pads_begin);
80  /// \return The end of padding shape.
81  const Shape& get_pads_end() const;
82  void set_pads_end(const Shape& pads_end);
83  bool get_exclude_pad() const;
84  void set_exclude_pad(bool exclude_pad);
85  /// \return The pad type for pooling.
86  const PadType& get_auto_pad() const;
87  void set_auto_pad(const PadType& auto_pad);
88  op::RoundingType get_rounding_type() const;
89  void set_rounding_type(op::RoundingType rounding_type);
90  /// \return The default value for AvgPool.
91  virtual std::shared_ptr<Node> get_default_value() const override;
92 
93  protected:
94  Shape m_kernel;
95  Strides m_strides;
96  Shape m_pads_begin;
97  Shape m_pads_end;
98  bool m_exclude_pad{true};
99  PadType m_auto_pad{PadType::EXPLICIT};
100  op::RoundingType m_rounding_type{op::RoundingType::FLOOR};
101  };
102  } // namespace v1
103 
104  using v1::AvgPool;
105  } // namespace op
106 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:71
A handle for one of a node's outputs.
Definition: node_output.hpp:42
Shape for a tensor.
Definition: shape.hpp:31
Strides for a tensor.
Definition: strides.hpp:30
Root of all actual ops.
Definition: op.hpp:29
Batched average pooling operation.
Definition: avg_pool.hpp:31
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=op::RoundingType::FLOOR, const PadType &auto_pad=op::PadType::EXPLICIT)
Constructs a batched average pooling operation.
AvgPool()=default
Constructs a batched average pooling operation.
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
const Shape & get_pads_begin() const
const PadType & get_auto_pad() const
virtual std::shared_ptr< Node > get_default_value() const override
const Shape & get_pads_end() const
const Strides & get_strides() const
size_t get_version() const override
Definition: avg_pool.hpp:64
const Shape & get_kernel() const
RoundingType
Rounding Type used for Pooling operators.
Definition: attr_types.hpp:103
PadType
Padding Type used for Convolution and Pooling
Definition: attr_types.hpp:73
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28