MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / prior_box_layer

Function prior_box_layer

tests/validation/reference/PriorBoxLayer.cpp:39–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37{
38template <typename T>
39SimpleTensor<T> prior_box_layer(const SimpleTensor<T> &src1,
40 const SimpleTensor<T> &src2,
41 const PriorBoxLayerInfo &info,
42 const TensorShape &output_shape)
43{
44 const auto layer_width = static_cast<int>(src1.shape()[0]);
45 const auto layer_height = static_cast<int>(src1.shape()[1]);
46
47 int img_width = info.img_size().x;
48 int img_height = info.img_size().y;
49 if (img_width == 0 || img_height == 0)
50 {
51 img_width = static_cast<int>(src2.shape()[0]);
52 img_height = static_cast<int>(src2.shape()[1]);
53 }
54
55 float step_x = info.steps()[0];
56 float step_y = info.steps()[1];
57 if (step_x == 0.f || step_y == 0.f)
58 {
59 step_x = static_cast<float>(img_width) / layer_width;
60 step_x = static_cast<float>(img_height) / layer_height;
61 }
62
63 // Calculate number of aspect ratios
64 const int num_priors = info.aspect_ratios().size() * info.min_sizes().size() + info.max_sizes().size();
65 const int total_elements = layer_width * layer_height * num_priors * 4;
66
67 SimpleTensor<T> result(output_shape, src1.data_type());
68
69 int idx = 0;
70 for (int y = 0; y < layer_height; ++y)
71 {
72 for (int x = 0; x < layer_width; ++x)
73 {
74 const float center_x = (x + info.offset()) * step_x;
75 const float center_y = (y + info.offset()) * step_y;
76 float box_width;
77 float box_height;
78 for (unsigned int i = 0; i < info.min_sizes().size(); ++i)
79 {
80 const float min_size = info.min_sizes().at(i);
81 box_width = min_size;
82 box_height = min_size;
83 // (xmin, ymin, xmax, ymax)
84 result[idx++] = (center_x - box_width / 2.f) / img_width;
85 result[idx++] = (center_y - box_height / 2.f) / img_height;
86 result[idx++] = (center_x + box_width / 2.f) / img_width;
87 result[idx++] = (center_y + box_height / 2.f) / img_height;
88
89 if (!info.max_sizes().empty())
90 {
91 const float max_size = info.max_sizes().at(i);
92 box_width = sqrt(min_size * max_size);
93 box_height = box_width;
94
95 // (xmin, ymin, xmax, ymax)
96 result[idx++] = (center_x - box_width / 2.f) / img_width;

Callers 1

compute_referenceMethod · 0.85

Calls 15

sqrtFunction · 0.85
fabsFunction · 0.85
img_sizeMethod · 0.80
stepsMethod · 0.80
aspect_ratiosMethod · 0.80
min_sizesMethod · 0.80
max_sizesMethod · 0.80
offsetMethod · 0.80
clipMethod · 0.80
variancesMethod · 0.80
shapeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected