max_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 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 = op::RoundingType::FLOOR,
53  const PadType& auto_pad = op::PadType::EXPLICIT);
54 
55  bool visit_attributes(AttributeVisitor& visitor) override;
56  size_t get_version() const override { return 1; }
57  void validate_and_infer_types() override;
58 
59  virtual std::shared_ptr<Node>
60  clone_with_new_inputs(const OutputVector& new_args) const override;
61 
62  /// \return The kernel shape.
63  const Shape& get_kernel() const { return m_kernel; }
64  void set_kernel(const Shape& kernel) { m_kernel = kernel; }
65  /// \return The strides.
66  const Strides& get_strides() const { return m_strides; }
67  void set_strides(const Strides& strides) { m_strides = strides; }
68  /// \return The beginning of padding shape.
69  const Shape& get_pads_begin() const { return m_pads_begin; }
70  void set_pads_begin(const Shape& pads_begin) { m_pads_begin = pads_begin; }
71  /// \return The end of padding shape.
72  const Shape& get_pads_end() const { return m_pads_end; }
73  void set_adding_above(const Shape& pads_end) { m_pads_end = pads_end; }
74  /// \return The pad type for pooling.
75  const PadType& get_auto_pad() const { return m_auto_pad; }
76  void set_auto_pad(const PadType& auto_pad) { m_auto_pad = auto_pad; }
77  /// \return The ceiling mode being used for output shape computations
78  op::RoundingType get_rounding_type() const { return m_rounding_type; }
79  void set_rounding_type(op::RoundingType rounding_mode)
80  {
81  m_rounding_type = rounding_mode;
82  }
83  /// \return The default value for MaxPool.
84  virtual std::shared_ptr<Node> get_default_value() const override;
85 
86  bool evaluate(const HostTensorVector& outputs,
87  const HostTensorVector& inputs) const override;
88 
89  protected:
90  Shape m_kernel;
91  Strides m_strides;
92  Shape m_pads_begin;
93  Shape m_pads_end;
94  PadType m_auto_pad;
95  op::RoundingType m_rounding_type;
96 
97  private:
98  bool update_auto_padding(const PartialShape& in_shape,
99  Shape& new_pads_end,
100  Shape& new_pads_begin) const;
101  bool evaluate_maxpool(const HostTensorVector& outputs,
102  const HostTensorVector& inputs) const;
103  };
104  } // namespace v1
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
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:46
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 max pooling operation.
Definition: max_pool.hpp:30
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
const Shape & get_kernel() const
Definition: max_pool.hpp:63
const Shape & get_pads_end() const
Definition: max_pool.hpp:72
const Strides & get_strides() const
Definition: max_pool.hpp:66
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
MaxPool(const Output< Node > &arg, const Strides &strides, const Shape &pads_begin, const Shape &pads_end, const Shape &kernel, op::RoundingType rounding_mode=op::RoundingType::FLOOR, const PadType &auto_pad=op::PadType::EXPLICIT)
Constructs a batched max pooling operation.
const Shape & get_pads_begin() const
Definition: max_pool.hpp:69
MaxPool()=default
Constructs a batched max pooling operation.
virtual std::shared_ptr< Node > get_default_value() const override
size_t get_version() const override
Definition: max_pool.hpp:56
const PadType & get_auto_pad() const
Definition: max_pool.hpp:75
op::RoundingType get_rounding_type() const
Definition: max_pool.hpp:78
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