prior_box.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  {
14  {
15  // min_size Desired min_size of prior boxes
16  // max_size Desired max_size of prior boxes
17  // aspect_ratio Aspect ratios of prior boxes
18  // clip Clip output to [0,1]
19  // flip Flip aspect ratios
20  // step Distance between prior box centers
21  // offset Box offset relative to top center of image
22  // variance Values to adjust prior boxes with
23  // scale_all_sizes Scale all sizes
24  std::vector<float> min_size;
25  std::vector<float> max_size;
26  std::vector<float> aspect_ratio;
27  std::vector<float> density;
28  std::vector<float> fixed_ratio;
29  std::vector<float> fixed_size;
30  bool clip = false;
31  bool flip = false;
32  float step = 0.0f;
33  float offset = 0.0f;
34  std::vector<float> variance;
35  bool scale_all_sizes = true;
36  };
37 
38  namespace v0
39  {
40  /// \brief Layer which generates prior boxes of specified sizes
41  /// normalized to input image size
42  class NGRAPH_API PriorBox : public Op
43  {
44  public:
45  static constexpr NodeTypeInfo type_info{"PriorBox", 0};
46  const NodeTypeInfo& get_type_info() const override { return type_info; }
47  PriorBox() = default;
48  /// \brief Constructs a PriorBox operation
49  ///
50  /// \param layer_shape Shape of layer for which prior boxes are computed
51  /// \param image_shape Shape of image to which prior boxes are scaled
52  /// \param attrs PriorBox attributes
53  PriorBox(const Output<Node>& layer_shape,
54  const Output<Node>& image_shape,
55  const PriorBoxAttrs& attrs);
56 
57  void validate_and_infer_types() override;
58  virtual std::shared_ptr<Node>
59  clone_with_new_inputs(const OutputVector& new_args) const override;
60 
61  static int64_t number_of_priors(const PriorBoxAttrs& attrs);
62 
63  static std::vector<float>
64  normalized_aspect_ratio(const std::vector<float>& aspect_ratio, bool flip);
65  const PriorBoxAttrs& get_attrs() const { return m_attrs; }
66  virtual bool visit_attributes(AttributeVisitor& visitor) override;
67  bool evaluate(const HostTensorVector& outputs,
68  const HostTensorVector& inputs) const override;
69  bool has_evaluate() const override;
70 
71  private:
72  PriorBoxAttrs m_attrs;
73  };
74  } // namespace v0
75  using v0::PriorBox;
76  } // namespace op
77 } // 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
Root of all actual ops.
Definition: op.hpp:17
Layer which generates prior boxes of specified sizes normalized to input image size.
Definition: prior_box.hpp:43
bool evaluate(const HostTensorVector &outputs, const HostTensorVector &inputs) const override
Evaluates the op on input_values putting results in output_values.
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.
const NodeTypeInfo & get_type_info() const override
Definition: prior_box.hpp:46
PriorBox(const Output< Node > &layer_shape, const Output< Node > &image_shape, const PriorBoxAttrs &attrs)
Constructs a PriorBox operation.
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27
Definition: prior_box.hpp:14