max_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 max pooling operation.
29  class NGRAPH_API MaxPool : public Op
30  {
31  public:
32  NGRAPH_RTTI_DECLARATION;
33 
34  /// \brief Constructs a batched max pooling operation.
35  MaxPool() = default;
36 
37  /// \brief Constructs a batched max pooling operation.
38  ///
39  /// \param arg The node producing the input data batch tensor.
40  /// \param strides The strides.
41  /// \param pads_begin The beginning of padding shape.
42  /// \param pads_end The end of padding shape.
43  /// \param kernel The kernel shape.
44  /// \param rounding_mode Whether to use ceiling or floor rounding type while
45  /// computing output shape.
46  /// \param auto_pad The pad type for automatically computing padding sizes.
47  MaxPool(const Output<Node>& arg,
48  const Strides& strides,
49  const Shape& pads_begin,
50  const Shape& pads_end,
51  const Shape& kernel,
52  op::RoundingType rounding_mode,
53  const PadType& auto_pad);
54 
55  /// \brief Constructs a batched max pooling operation.
56  ///
57  /// \param arg The node producing the input data batch tensor.
58  /// \param strides The strides.
59  /// \param pads_begin The beginning of padding shape.
60  /// \param pads_end The end of padding shape.
61  /// \param kernel The kernel shape.
62  /// \param rounding_mode Whether to use ceiling or floor rounding type while
63  /// computing output shape.
64  MaxPool(const Output<Node>& arg,
65  const Strides& strides,
66  const Shape& pads_begin,
67  const Shape& pads_end,
68  const Shape& kernel,
69  op::RoundingType rounding_mode);
70 
71  bool visit_attributes(AttributeVisitor& visitor) override;
72  size_t get_version() const override { return 1; }
73  void validate_and_infer_types() override;
74 
75  virtual std::shared_ptr<Node>
76  clone_with_new_inputs(const OutputVector& new_args) const override;
77 
78  /// \return The kernel shape.
79  const Shape& get_kernel() const { return m_kernel; }
80  void set_kernel(const Shape& kernel) { m_kernel = kernel; }
81  /// \return The strides.
82  const Strides& get_strides() const { return m_strides; }
83  void set_strides(const Strides& strides) { m_strides = strides; }
84  /// \return The beginning of padding shape.
85  const Shape& get_pads_begin() const { return m_pads_begin; }
86  void set_pads_begin(const Shape& pads_begin) { m_pads_begin = pads_begin; }
87  /// \return The end of padding shape.
88  const Shape& get_pads_end() const { return m_pads_end; }
89  void set_adding_above(const Shape& pads_end) { m_pads_end = pads_end; }
90  /// \return The pad type for pooling.
91  const PadType& get_auto_pad() const { return m_auto_pad; }
92  void set_auto_pad(const PadType& auto_pad) { m_auto_pad = auto_pad; }
93  /// \return The ceiling mode being used for output shape computations
94  op::RoundingType get_rounding_type() const { return m_rounding_type; }
95  void set_rounding_type(op::RoundingType rounding_mode)
96  {
97  m_rounding_type = rounding_mode;
98  }
99  /// \return The default value for MaxPool.
100  virtual std::shared_ptr<Node> get_default_value() const override;
101 
102  bool evaluate(const HostTensorVector& outputs,
103  const HostTensorVector& inputs) const override;
104 
105  protected:
106  Shape m_kernel;
107  Strides m_strides;
108  Shape m_pads_begin;
109  Shape m_pads_end;
110  PadType m_auto_pad;
111  op::RoundingType m_rounding_type{op::RoundingType::FLOOR};
112 
113  private:
114  bool update_auto_padding(const PartialShape& in_shape,
115  Shape& new_pads_end,
116  Shape& new_pads_begin) const;
117  };
118  } // namespace v1
119  } // namespace op
120 } // namespace ngraph
ngraph::op::PadType
PadType
Padding Type used for Convolution and Pooling
Definition: attr_types.hpp:71
ngraph::op::v1::MaxPool::get_kernel
const Shape & get_kernel() const
Definition: max_pool.hpp:79
ngraph::op::v1::MaxPool::get_pads_begin
const Shape & get_pads_begin() const
Definition: max_pool.hpp:85
ngraph::op::v1::MaxPool::get_rounding_type
op::RoundingType get_rounding_type() const
Definition: max_pool.hpp:94
ngraph::op::v1::MaxPool::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::RoundingType
RoundingType
Rounding Type used for Pooling operators.
Definition: attr_types.hpp:101
ngraph::op::v1::MaxPool::get_pads_end
const Shape & get_pads_end() const
Definition: max_pool.hpp:88
ngraph::op::v1::MaxPool::MaxPool
MaxPool()=default
Constructs a batched max pooling operation.
ngraph::op::v1::MaxPool::MaxPool
MaxPool(const Output< Node > &arg, const Strides &strides, const Shape &pads_begin, const Shape &pads_end, const Shape &kernel, op::RoundingType rounding_mode, const PadType &auto_pad)
Constructs a batched max pooling operation.
ngraph::op::v1::MaxPool::get_default_value
virtual std::shared_ptr< Node > get_default_value() const override
ngraph::op::v1::MaxPool::get_auto_pad
const PadType & get_auto_pad() const
Definition: max_pool.hpp:91
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::op::v1::MaxPool::MaxPool
MaxPool(const Output< Node > &arg, const Strides &strides, const Shape &pads_begin, const Shape &pads_end, const Shape &kernel, op::RoundingType rounding_mode)
Constructs a batched max pooling operation.
ngraph::op::v1::MaxPool
Batched max pooling operation.
Definition: max_pool.hpp:30
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::v1::MaxPool::get_version
size_t get_version() const override
Definition: max_pool.hpp:72
ngraph::op::v1::MaxPool::get_strides
const Strides & get_strides() const
Definition: max_pool.hpp:82
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29