39 Status
validate_arguments(
const ITensorInfo *input1,
const ITensorInfo *input2,
const ITensorInfo *output,
const PriorBoxLayerInfo &
info)
47 const int var_size =
info.variances().size();
51 for(
int i = 0; i < var_size; ++i)
59 if(!
info.max_sizes().empty())
64 for(
unsigned int i = 0; i <
info.max_sizes().size(); ++i)
69 if(output !=
nullptr && output->total_size() != 0)
80 : _input1(nullptr), _input2(nullptr), _output(nullptr), _info()
84 void NEPriorBoxLayerKernel::store_coordinates(
float *out,
const int offset,
const float center_x,
const float center_y,
const float box_width,
const float box_height,
const int width,
87 float xmin = (center_x - box_width / 2.f) / width;
88 float ymin = (center_y - box_height / 2.f) / height;
89 float xmax = (center_x + box_width / 2.f) / width;
90 float ymax = (center_y + box_height / 2.f) / height;
92 float32x4_t vec_elements = { xmin, ymin, xmax, ymax };
95 static const float32x4_t CONST_0 = vdupq_n_f32(0.f);
96 static const float32x4_t CONST_1 = vdupq_n_f32(1.f);
97 vec_elements = vmaxq_f32(vminq_f32(vec_elements, CONST_1), CONST_0);
99 vst1q_f32(out +
offset, vec_elements);
102 void NEPriorBoxLayerKernel::calculate_prior_boxes(
const Window &window)
110 const int layer_width = _input1->
info()->
dimension(width_idx);
111 const int layer_height = _input1->
info()->
dimension(height_idx);
115 if(img_width == 0 || img_height == 0)
121 float step_x = _info.
steps()[0];
122 float step_y = _info.
steps()[1];
123 if(step_x == 0.f || step_y == 0.f)
125 step_x = static_cast<float>(img_width) / layer_width;
126 step_y = static_cast<float>(img_height) / layer_height;
132 Iterator output(_output,
slice);
137 int idx =
id.x() / (4 * num_priors);
138 center_x = (static_cast<float>(idx % layer_width) + _info.
offset()) * step_x;
139 center_y = (static_cast<float>(idx / layer_width) + _info.
offset()) * step_y;
145 auto out = reinterpret_cast<float *>(output.ptr());
146 for(
unsigned int i = 0; i < _info.
min_sizes().size(); ++i)
148 const float min_size = _info.
min_sizes().at(i);
149 box_width = min_size;
150 box_height = min_size;
151 store_coordinates(out,
offset, center_x, center_y, box_width, box_height, img_width, img_height);
156 const float max_size = _info.
max_sizes().at(i);
157 box_width = std::sqrt(min_size * max_size);
158 box_height = box_width;
160 store_coordinates(out,
offset, center_x, center_y, box_width, box_height, img_width, img_height);
167 if(fabs(ar - 1.) < 1e-6)
172 box_width = min_size * sqrt(ar);
173 box_height = min_size / sqrt(ar);
175 store_coordinates(out,
offset, center_x, center_y, box_width, box_height, img_width, img_height);
181 out = reinterpret_cast<float *>(_output->
ptr_to_element(Coordinates(
id.x(), 1)));
185 var = vdupq_n_f32(_info.
variances().at(0));
192 for(
int i = 0; i < num_priors; ++i)
194 vst1q_f32(out + 4 * i, var);
212 const int num_priors =
info.aspect_ratios().size() *
info.min_sizes().size() +
info.max_sizes().size();
215 INEKernel::configure(win);
232 calculate_prior_boxes(
window);
Window first_slice_window_2D() const
First 2D slice of the window.
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
const Window & window() const
The maximum window the kernel can be executed on.
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
void configure(const ITensor *input1, const ITensor *input2, ITensor *output, const PriorBoxLayerInfo &info)
Set the input and output tensors.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
std::vector< float > aspect_ratios() const
Get aspect ratios.
1 channel, 1 F32 per channel
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
const DataLayout data_layout
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Interface for CPU tensor.
Copyright (c) 2017-2021 Arm Limited.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
std::array< float, 2 > steps() const
Get the step coordinates.
Class to describe a number of elements in each dimension.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
float offset() const
Get the offset.
Coordinates2D img_size() const
Get the image size coordinates.
NEPriorBoxLayerKernel()
Default constructor.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
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.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
std::vector< float > max_sizes() const
Get max sizes.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
std::vector< float > variances() const
Get min variances.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
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...
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
bool clip() const
Get the clip value.
DataLayout
[DataLayout enum definition]
Describe a multidimensional execution window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
std::vector< float > min_sizes() const
Get min sizes.