avg_pool.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "ngraph/op/op.hpp"
8 #include "ngraph/op/util/attr_types.hpp"
9 
10 namespace ngraph
11 {
12  namespace op
13  {
14  namespace v1
15  {
16  /// \brief Batched average pooling operation.
17  ///
18  class NGRAPH_API AvgPool : public Op
19  {
20  public:
21  NGRAPH_RTTI_DECLARATION;
22 
23  /// \brief Constructs a batched average pooling operation.
24  AvgPool() = default;
25 
26  ///
27  /// \brief Constructs a batched average pooling operation.
28  ///
29  /// \param arg The output producing the input data batch tensor.<br>
30  /// `[d1, dn]`
31  /// \param strides The strides.<br> `[n]`
32  /// \param pads_begin The beginning of padding shape.<br> `[n]`
33  /// \param pads_end The end of padding shape.<br> `[n]`
34  /// \param kernel The kernel shape.<br> `[n]`
35  /// \param exclude_pad If false then averages include padding elements, each
36  /// treated as the number zero. If true, padding
37  /// elements
38  /// are entirely ignored when computing averages.
39  /// \param rounding_type Whether to use ceiling or floor rounding type while
40  /// computing output shape.
41  /// \param auto_pad Padding type to use for additional padded dimensions
42  ///
43  AvgPool(const Output<Node>& arg,
44  const Strides& strides,
45  const Shape& pads_begin,
46  const Shape& pads_end,
47  const Shape& kernel,
48  bool exclude_pad,
49  op::RoundingType rounding_type = op::RoundingType::FLOOR,
50  const PadType& auto_pad = op::PadType::EXPLICIT);
51 
52  size_t get_version() const override { return 1; }
53  void validate_and_infer_types() override;
54  bool visit_attributes(AttributeVisitor& visitor) override;
55 
56  virtual std::shared_ptr<Node>
57  clone_with_new_inputs(const OutputVector& new_args) const override;
58 
59  /// \return The kernel shape.
60  const Shape& get_kernel() const;
61  void set_kernel(const Shape& kernel);
62  /// \return The strides.
63  const Strides& get_strides() const;
64  void set_strides(const Strides& strides);
65  /// \return The beginning of padding shape.
66  const Shape& get_pads_begin() const;
67  void set_pads_begin(const Shape& pads_begin);
68  /// \return The end of padding shape.
69  const Shape& get_pads_end() const;
70  void set_pads_end(const Shape& pads_end);
71  bool get_exclude_pad() const;
72  void set_exclude_pad(bool exclude_pad);
73  /// \return The pad type for pooling.
74  const PadType& get_auto_pad() const;
75  void set_auto_pad(const PadType& auto_pad);
76  op::RoundingType get_rounding_type() const;
77  void set_rounding_type(op::RoundingType rounding_type);
78  /// \return The default value for AvgPool.
79  virtual std::shared_ptr<Node> get_default_value() const override;
80 
81  protected:
82  Shape m_kernel;
83  Strides m_strides;
84  Shape m_pads_begin;
85  Shape m_pads_end;
86  bool m_exclude_pad{true};
87  PadType m_auto_pad{PadType::EXPLICIT};
88  op::RoundingType m_rounding_type{op::RoundingType::FLOOR};
89  };
90  } // namespace v1
91 
92  using v1::AvgPool;
93  } // namespace op
94 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Shape for a tensor.
Definition: shape.hpp:19
Strides for a tensor.
Definition: strides.hpp:18
Root of all actual ops.
Definition: op.hpp:17
Batched average pooling operation.
Definition: avg_pool.hpp:19
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:52
const Shape & get_kernel() const
RoundingType
Rounding Type used for Pooling operators.
Definition: attr_types.hpp:91
PadType
Padding Type used for Convolution and Pooling
Definition: attr_types.hpp:61
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16