roi_align.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 
9 namespace ngraph
10 {
11  namespace op
12  {
13  namespace v3
14  {
15  class NGRAPH_API ROIAlign : public Op
16  {
17  public:
18  static constexpr NodeTypeInfo type_info{"ROIAlign", 3};
19  const NodeTypeInfo& get_type_info() const override { return type_info; }
20  enum class PoolingMode
21  {
22  AVG,
23  MAX
24  };
25 
26  ROIAlign() = default;
27  /// \brief Constructs a ROIAlign node matching the ONNX ROIAlign specification
28  ///
29  /// \param input Input feature map {N, C, H, W}
30  /// \param rois Regions of interest to pool over
31  /// \param batch_indices Indices of images in the batch matching
32  /// the number or ROIs
33  /// \param pooled_h Height of the ROI output features
34  /// \param pooled_w Width of the ROI output features
35  /// \param sampling_ratio Number of sampling points used to compute
36  /// an output element
37  /// \param spatial_scale Spatial scale factor used to translate ROI coordinates
38  /// \param mode Method of pooling - 'avg' or 'max'
39  ROIAlign(const Output<Node>& input,
40  const Output<Node>& rois,
41  const Output<Node>& batch_indices,
42  const int pooled_h,
43  const int pooled_w,
44  const int sampling_ratio,
45  const float spatial_scale,
46  const std::string& mode);
47 
48  ROIAlign(const Output<Node>& input,
49  const Output<Node>& rois,
50  const Output<Node>& batch_indices,
51  const int pooled_h,
52  const int pooled_w,
53  const int sampling_ratio,
54  const float spatial_scale,
55  const PoolingMode mode);
56 
57  virtual void validate_and_infer_types() override;
58  virtual bool visit_attributes(AttributeVisitor& visitor) override;
59  virtual std::shared_ptr<Node>
60  clone_with_new_inputs(const OutputVector& new_args) const override;
61 
62  int get_pooled_h() const { return m_pooled_h; }
63  int get_pooled_w() const { return m_pooled_w; }
64  int get_sampling_ratio() const { return m_sampling_ratio; }
65  float get_spatial_scale() const { return m_spatial_scale; }
66  PoolingMode get_mode() const { return m_mode; }
67  bool evaluate(const HostTensorVector& outputs,
68  const HostTensorVector& inputs) const override;
69  bool has_evaluate() const override;
70 
71  private:
72  PoolingMode mode_from_string(const std::string& mode) const;
73 
74  private:
75  int m_pooled_h;
76  int m_pooled_w;
77  int m_sampling_ratio;
78  float m_spatial_scale;
79  PoolingMode m_mode;
80  };
81  } // namespace v3
82  using v3::ROIAlign;
83  } // namespace op
84 
85  std::ostream& operator<<(std::ostream& s, const op::v3::ROIAlign::PoolingMode& mode);
86 
87  template <>
88  class NGRAPH_API AttributeAdapter<op::v3::ROIAlign::PoolingMode>
89  : public EnumAttributeAdapterBase<op::v3::ROIAlign::PoolingMode>
90  {
91  public:
92  AttributeAdapter(op::v3::ROIAlign::PoolingMode& value)
94  {
95  }
96 
97  static constexpr DiscreteTypeInfo type_info{
98  "AttributeAdapter<op::v3::ROIAlign::PoolingMode>", 3};
99  const DiscreteTypeInfo& get_type_info() const override { return type_info; }
100  };
101 } // namespace ngraph
An AttributeAdapter "captures" an attribute as an AT& and makes it available as a ValueAccessor<VAT>.
Definition: attribute_adapter.hpp:161
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
Access an enum via a string.
Definition: attribute_adapter.hpp:168
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Root of all actual ops.
Definition: op.hpp:17
Definition: roi_align.hpp:16
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
virtual void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ROIAlign(const Output< Node > &input, const Output< Node > &rois, const Output< Node > &batch_indices, const int pooled_h, const int pooled_w, const int sampling_ratio, const float spatial_scale, const std::string &mode)
Constructs a ROIAlign node matching the ONNX ROIAlign specification.
bool has_evaluate() const override
Allows to get information about availability of evaluate method for the current operation.
const NodeTypeInfo & get_type_info() const override
Definition: roi_align.hpp:19
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27