41 const auto layer_width =
static_cast<int>(src1.
shape()[0]);
42 const auto layer_height =
static_cast<int>(src1.
shape()[1]);
46 if(img_width == 0 || img_height == 0)
48 img_width =
static_cast<int>(src2.
shape()[0]);
49 img_height =
static_cast<int>(src2.
shape()[1]);
52 float step_x = info.
steps()[0];
53 float step_y = info.
steps()[1];
54 if(step_x == 0.f || step_y == 0.f)
56 step_x =
static_cast<float>(img_width) / layer_width;
57 step_x =
static_cast<float>(img_height) / layer_height;
62 const int total_elements = layer_width * layer_height * num_priors * 4;
67 for(
int y = 0; y < layer_height; ++y)
69 for(
int x = 0; x < layer_width; ++x)
71 const float center_x = (x + info.
offset()) * step_x;
72 const float center_y = (y + info.
offset()) * step_y;
75 for(
unsigned int i = 0; i < info.
min_sizes().size(); ++i)
77 const float min_size = info.
min_sizes().at(i);
79 box_height = min_size;
81 result[idx++] = (center_x - box_width / 2.f) / img_width;
82 result[idx++] = (center_y - box_height / 2.f) / img_height;
83 result[idx++] = (center_x + box_width / 2.f) / img_width;
84 result[idx++] = (center_y + box_height / 2.f) / img_height;
88 const float max_size = info.
max_sizes().at(i);
89 box_width = sqrt(min_size * max_size);
90 box_height = box_width;
93 result[idx++] = (center_x - box_width / 2.f) / img_width;
94 result[idx++] = (center_y - box_height / 2.f) / img_height;
95 result[idx++] = (center_x + box_width / 2.f) / img_width;
96 result[idx++] = (center_y + box_height / 2.f) / img_height;
102 if(fabs(ar - 1.) < 1e-6)
107 box_width = min_size * sqrt(ar);
108 box_height = min_size / sqrt(ar);
111 result[idx++] = (center_x - box_width / 2.f) / img_width;
112 result[idx++] = (center_y - box_height / 2.f) / img_height;
113 result[idx++] = (center_x + box_width / 2.f) / img_width;
114 result[idx++] = (center_y + box_height / 2.f) / img_height;
123 for(
int i = 0; i < total_elements; ++i)
125 result[i] = std::min<T>(std::max<T>(result[i], 0.f), 1.f);
132 std::fill_n(result.data() + idx, total_elements, info.
variances().at(0));
136 for(
int h = 0; h < layer_height; ++h)
138 for(
int w = 0;
w < layer_width; ++
w)
140 for(
int i = 0; i < num_priors; ++i)
142 for(
int j = 0; j < 4; ++j)
std::vector< float > aspect_ratios() const
Get aspect ratios.
DataType data_type() const override
Data type of the tensor.
TensorShape shape() const override
Shape of the tensor.
Copyright (c) 2017-2021 Arm Limited.
std::array< float, 2 > steps() const
Get the step coordinates.
SimpleTensor< T > prior_box_layer(const SimpleTensor< T > &src1, const SimpleTensor< T > &src2, const PriorBoxLayerInfo &info, const TensorShape &output_shape)
float offset() const
Get the offset.
Coordinates2D img_size() const
Get the image size coordinates.
Simple tensor object that stores elements in a consecutive chunk of memory.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
std::vector< float > max_sizes() const
Get max sizes.
std::vector< float > variances() const
Get min variances.
bool clip() const
Get the clip value.
std::vector< float > min_sizes() const
Get min sizes.