41 Status
validate_arguments(
const ITensorInfo *boxes,
const ITensorInfo *pred_boxes,
const ITensorInfo *deltas,
const BoundingBoxTransformInfo &
info)
57 const UniformQuantizationInfo deltas_qinfo = deltas->quantization_info().uniform();
66 if(pred_boxes->total_size() > 0)
73 const UniformQuantizationInfo pred_qinfo = pred_boxes->quantization_info().uniform();
84 : _boxes(nullptr), _pred_boxes(nullptr), _deltas(nullptr), _bbinfo(0, 0, 0)
98 _pred_boxes = pred_boxes;
110 INEKernel::configure(win);
120 void NEBoundingBoxTransformKernel::internal_run<uint16_t>(
const Window &
window)
124 const int img_h = std::floor(_bbinfo.
img_height() / _bbinfo.
scale() + 0.5f);
125 const int img_w = std::floor(_bbinfo.
img_width() / _bbinfo.
scale() + 0.5f);
128 const auto scale_before = _bbinfo.
scale();
141 const auto ptr =
reinterpret_cast<uint16_t *
>(box_it.
ptr());
146 const float width = (b2 / scale_before) - (b0 / scale_before) + 1.f;
147 const float height = (b3 / scale_before) - (b1 / scale_before) + 1.f;
148 const float ctr_x = (b0 / scale_before) + 0.5f * width;
149 const float ctr_y = (b1 / scale_before) + 0.5f * height;
150 for(
size_t j = 0; j < num_classes; ++j)
153 const size_t delta_id =
id.y() * deltas_width + 4u * j;
162 const float pred_ctr_x = dx * width + ctr_x;
163 const float pred_ctr_y = dy * height + ctr_y;
164 const float pred_w = std::exp(dw) * width;
165 const float pred_h = std::exp(dh) * height;
167 pred_ptr[delta_id] =
quantize_qasymm16(scale_after * utility::clamp<float>(pred_ctr_x - 0.5f * pred_w, 0.f, img_w - 1.f), pred_qinfo);
168 pred_ptr[delta_id + 1] =
quantize_qasymm16(scale_after * utility::clamp<float>(pred_ctr_y - 0.5f * pred_h, 0.f, img_h - 1.f), pred_qinfo);
169 pred_ptr[delta_id + 2] =
quantize_qasymm16(scale_after * utility::clamp<float>(pred_ctr_x + 0.5f * pred_w -
offset, 0.f, img_w - 1.f), pred_qinfo);
170 pred_ptr[delta_id + 3] =
quantize_qasymm16(scale_after * utility::clamp<float>(pred_ctr_y + 0.5f * pred_h -
offset, 0.f, img_h - 1.f), pred_qinfo);
176 template <
typename T>
177 void NEBoundingBoxTransformKernel::internal_run(
const Window &
window)
181 const int img_h = std::floor(_bbinfo.
img_height() / _bbinfo.
scale() + 0.5f);
182 const int img_w = std::floor(_bbinfo.
img_width() / _bbinfo.
scale() + 0.5f);
184 const auto scale_after = (_bbinfo.
apply_scale() ? T(_bbinfo.
scale()) : T(1));
185 const auto scale_before = T(_bbinfo.
scale());
195 const auto ptr =
reinterpret_cast<T *
>(box_it.
ptr());
196 const auto b0 = *ptr;
197 const auto b1 = *(ptr + 1);
198 const auto b2 = *(ptr + 2);
199 const auto b3 = *(ptr + 3);
200 const T width = (b2 / scale_before) - (b0 / scale_before) + T(1.f);
201 const T height = (b3 / scale_before) - (b1 / scale_before) + T(1.f);
202 const T ctr_x = (b0 / scale_before) + T(0.5f) * width;
203 const T ctr_y = (b1 / scale_before) + T(0.5f) * height;
204 for(
size_t j = 0; j < num_classes; ++j)
207 const size_t delta_id =
id.y() * deltas_width + 4u * j;
208 const T dx = delta_ptr[delta_id] / T(_bbinfo.
weights()[0]);
209 const T dy = delta_ptr[delta_id + 1] / T(_bbinfo.
weights()[1]);
210 T dw = delta_ptr[delta_id + 2] / T(_bbinfo.
weights()[2]);
211 T dh = delta_ptr[delta_id + 3] / T(_bbinfo.
weights()[3]);
216 const T pred_ctr_x = dx * width + ctr_x;
217 const T pred_ctr_y = dy * height + ctr_y;
218 const T pred_w = std::exp(dw) * width;
219 const T pred_h = std::exp(dh) * height;
221 pred_ptr[delta_id] = scale_after * utility::clamp<T>(pred_ctr_x - T(0.5f) * pred_w, T(0), T(img_w - 1));
222 pred_ptr[delta_id + 1] = scale_after * utility::clamp<T>(pred_ctr_y - T(0.5f) * pred_h, T(0), T(img_h - 1));
223 pred_ptr[delta_id + 2] = scale_after * utility::clamp<T>(pred_ctr_x + T(0.5f) * pred_w -
offset, T(0), T(img_w - 1));
224 pred_ptr[delta_id + 3] = scale_after * utility::clamp<T>(pred_ctr_y + T(0.5f) * pred_h -
offset, T(0), T(img_h - 1));
239 internal_run<float>(
window);
244 internal_run<uint16_t>(
window);
247 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 250 internal_run<float16_t>(
window);
253 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC __global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
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.
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
float dequantize_qasymm8(uint8_t value, const INFO_TYPE &qinfo)
Dequantize a value given an unsigned 8-bit asymmetric quantization scheme.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Describe one of the image's dimensions with a start, end and step.
quantized, asymmetric fixed-point 16-bit number
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Interface for Neon tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Copyright (c) 2017-2021 Arm Limited.
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
float dequantize_qasymm16(uint16_t value, const UniformQuantizationInfo &qinfo)
Dequantize a value given a 16-bit asymmetric quantization scheme.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
quantized, asymmetric fixed-point 8-bit number unsigned
Class to describe a number of elements in each dimension.
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory. ...
UniformQuantizationInfo uniform() const
Return per layer quantization info.
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
constexpr uint8_t * ptr() const
Return a pointer to the current pixel.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
virtual size_t offset_first_element_in_bytes() const =0
The offset from the beginning of the memory allocation to the first element of the tensor...
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(...)
#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)
#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...
void set_num_dimensions(size_t num_dimensions)
Set number of dimensions.
Container for valid region of a window.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(t,...)
Iterator updated by execute_window_loop for each window element.
Describe a multidimensional execution window.
uint16_t quantize_qasymm16(float value, const UniformQuantizationInfo &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given a 16-bit asymmetric quantization scheme.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)