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