max_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 max pooling operation.
17  class NGRAPH_API MaxPool : public Op
18  {
19  public:
20  NGRAPH_RTTI_DECLARATION;
21 
22  /// \brief Constructs a batched max pooling operation.
23  MaxPool() = default;
24 
25  /// \brief Constructs a batched max pooling operation.
26  ///
27  /// \param arg The node producing the input data batch tensor.
28  /// \param strides The strides.
29  /// \param pads_begin The beginning of padding shape.
30  /// \param pads_end The end of padding shape.
31  /// \param kernel The kernel shape.
32  /// \param rounding_mode Whether to use ceiling or floor rounding type while
33  /// computing output shape.
34  /// \param auto_pad The pad type for automatically computing padding sizes.
35  MaxPool(const Output<Node>& arg,
36  const Strides& strides,
37  const Shape& pads_begin,
38  const Shape& pads_end,
39  const Shape& kernel,
40  op::RoundingType rounding_mode = op::RoundingType::FLOOR,
41  const PadType& auto_pad = op::PadType::EXPLICIT);
42 
43  bool visit_attributes(AttributeVisitor& visitor) override;
44  size_t get_version() const override { return 1; }
45  void validate_and_infer_types() override;
46 
47  virtual std::shared_ptr<Node>
48  clone_with_new_inputs(const OutputVector& new_args) const override;
49 
50  /// \return The kernel shape.
51  const Shape& get_kernel() const { return m_kernel; }
52  void set_kernel(const Shape& kernel) { m_kernel = kernel; }
53  /// \return The strides.
54  const Strides& get_strides() const { return m_strides; }
55  void set_strides(const Strides& strides) { m_strides = strides; }
56  /// \return The beginning of padding shape.
57  const Shape& get_pads_begin() const { return m_pads_begin; }
58  void set_pads_begin(const Shape& pads_begin) { m_pads_begin = pads_begin; }
59  /// \return The end of padding shape.
60  const Shape& get_pads_end() const { return m_pads_end; }
61  void set_adding_above(const Shape& pads_end) { m_pads_end = pads_end; }
62  /// \return The pad type for pooling.
63  const PadType& get_auto_pad() const { return m_auto_pad; }
64  void set_auto_pad(const PadType& auto_pad) { m_auto_pad = auto_pad; }
65  /// \return The ceiling mode being used for output shape computations
66  op::RoundingType get_rounding_type() const { return m_rounding_type; }
67  void set_rounding_type(op::RoundingType rounding_mode)
68  {
69  m_rounding_type = rounding_mode;
70  }
71  /// \return The default value for MaxPool.
72  virtual std::shared_ptr<Node> get_default_value() const override;
73 
74  bool evaluate(const HostTensorVector& outputs,
75  const HostTensorVector& inputs) const override;
76  bool has_evaluate() const override;
77 
78  protected:
79  Shape m_kernel;
80  Strides m_strides;
81  Shape m_pads_begin;
82  Shape m_pads_end;
83  PadType m_auto_pad;
84  op::RoundingType m_rounding_type;
85 
86  private:
87  bool update_auto_padding(const PartialShape& in_shape,
88  Shape& new_pads_end,
89  Shape& new_pads_begin) const;
90  bool evaluate_maxpool(const HostTensorVector& outputs,
91  const HostTensorVector& inputs) const;
92  };
93  } // namespace v1
94  } // namespace op
95 } // 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
Class representing a shape that may be partially or totally dynamic.
Definition: partial_shape.hpp:34
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 max pooling operation.
Definition: max_pool.hpp:18
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:51
const Shape & get_pads_end() const
Definition: max_pool.hpp:60
const Strides & get_strides() const
Definition: max_pool.hpp:54
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
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:57
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:44
const PadType & get_auto_pad() const
Definition: max_pool.hpp:63
op::RoundingType get_rounding_type() const
Definition: max_pool.hpp:66
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