24.02.1
|
Go to the documentation of this file.
41 const ITensorInfo *input2,
42 const ITensorInfo *output,
43 const PriorBoxLayerInfo &
info)
51 const int var_size =
info.variances().size();
55 for (
int i = 0; i < var_size; ++i)
63 if (!
info.max_sizes().empty())
66 "Max and min sizes dimensions should match");
69 for (
unsigned int i = 0; i <
info.max_sizes().size(); ++i)
72 "Max size should be greater than min size");
75 if (output !=
nullptr && output->total_size() != 0)
89 void NEPriorBoxLayerKernel::store_coordinates(
float *out,
93 const float box_width,
94 const float box_height,
98 float xmin = (center_x - box_width / 2.f) / width;
99 float ymin = (center_y - box_height / 2.f) / height;
100 float xmax = (center_x + box_width / 2.f) / width;
101 float ymax = (center_y + box_height / 2.f) / height;
103 float32x4_t vec_elements = {xmin, ymin, xmax, ymax};
106 static const float32x4_t CONST_0 = vdupq_n_f32(0.f);
107 static const float32x4_t CONST_1 = vdupq_n_f32(1.f);
108 vec_elements = vmaxq_f32(vminq_f32(vec_elements, CONST_1), CONST_0);
110 vst1q_f32(out +
offset, vec_elements);
113 void NEPriorBoxLayerKernel::calculate_prior_boxes(
const Window &window)
126 if (img_width == 0 || img_height == 0)
132 float step_x = _info.
steps()[0];
133 float step_y = _info.
steps()[1];
134 if (step_x == 0.f || step_y == 0.f)
136 step_x =
static_cast<float>(img_width) / layer_width;
137 step_y =
static_cast<float>(img_height) / layer_height;
143 Iterator output(_output,
slice);
146 [&](
const Coordinates &
id)
150 int idx =
id.x() / (4 * num_priors);
151 center_x = (
static_cast<float>(idx % layer_width) + _info.
offset()) * step_x;
152 center_y = (
static_cast<float>(idx / layer_width) + _info.
offset()) * step_y;
158 auto out =
reinterpret_cast<float *
>(output.ptr());
159 for (
unsigned int i = 0; i < _info.
min_sizes().size(); ++i)
161 const float min_size = _info.
min_sizes().at(i);
162 box_width = min_size;
163 box_height = min_size;
164 store_coordinates(out,
offset, center_x, center_y, box_width, box_height, img_width, img_height);
169 const float max_size = _info.
max_sizes().at(i);
170 box_width = std::sqrt(min_size * max_size);
171 box_height = box_width;
173 store_coordinates(out,
offset, center_x, center_y, box_width, box_height, img_width, img_height);
180 if (fabs(ar - 1.) < 1e-6)
185 box_width = min_size * sqrt(ar);
186 box_height = min_size / sqrt(ar);
188 store_coordinates(out,
offset, center_x, center_y, box_width, box_height, img_width, img_height);
194 out =
reinterpret_cast<float *
>(_output->
ptr_to_element(Coordinates(
id.x(), 1)));
198 var = vdupq_n_f32(_info.
variances().at(0));
206 for (
int i = 0; i < num_priors; ++i)
208 vst1q_f32(out + 4 * i, var);
229 const int num_priors =
info.aspect_ratios().size() *
info.min_sizes().size() +
info.max_sizes().size();
232 INEKernel::configure(win);
252 calculate_prior_boxes(
window);
Class to describe a number of elements in each dimension.
std::vector< float > max_sizes() const
Get max sizes.
NEPriorBoxLayerKernel()
Default constructor.
std::vector< float > min_sizes() const
Get min sizes.
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
bool clip() const
Get the clip value.
std::vector< float > aspect_ratios() const
Get aspect ratios.
DataLayout
[DataLayout enum definition]
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
Coordinates2D img_size() const
Get the image size coordinates.
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Interface for CPU tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
constexpr auto data_layout
std::array< float, 2 > steps() const
Get the step coordinates.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&...iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
void configure(const ITensor *input1, const ITensor *input2, ITensor *output, const PriorBoxLayerInfo &info)
Set the input and output tensors.
const Window & window() const
The maximum window the kernel can be executed on.
Information about executing thread and CPU.
float offset() const
Get the offset.
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
Describe a multidimensional execution window.
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const PriorBoxLayerInfo &info)
Static function to check if given info will lead to a valid configuration of NEPriorBoxLayerKernel.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Copyright (c) 2017-2024 Arm Limited.
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
std::vector< float > variances() const
Get min variances.
Store the tensor's metadata.
@ F32
32-bit floating-point number
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
Window first_slice_window_2D() const
First 2D slice of the window.