40 Status
validate_arguments(
const ITensorInfo *boxes,
const ITensorInfo *pred_boxes,
const ITensorInfo *deltas,
const BoundingBoxTransformInfo &
info)
56 const UniformQuantizationInfo deltas_qinfo = deltas->quantization_info().uniform();
65 if(pred_boxes->total_size() > 0)
72 const UniformQuantizationInfo pred_qinfo = pred_boxes->quantization_info().uniform();
83 : _boxes(nullptr), _pred_boxes(nullptr), _deltas(nullptr), _bbinfo(0, 0, 0)
97 _pred_boxes = pred_boxes;
106 INEKernel::configure(win);
116 void NEBoundingBoxTransformKernel::internal_run<uint16_t>(
const Window &window)
120 const int img_h = std::floor(_bbinfo.
img_height() / _bbinfo.
scale() + 0.5f);
121 const int img_w = std::floor(_bbinfo.
img_width() / _bbinfo.
scale() + 0.5f);
124 const auto scale_before = _bbinfo.
scale();
137 const auto ptr = reinterpret_cast<uint16_t *>(box_it.ptr());
142 const float width = (b2 / scale_before) - (b0 / scale_before) + 1.f;
143 const float height = (b3 / scale_before) - (b1 / scale_before) + 1.f;
144 const float ctr_x = (b0 / scale_before) + 0.5f * width;
145 const float ctr_y = (b1 / scale_before) + 0.5f * height;
146 for(
size_t j = 0; j < num_classes; ++j)
149 const size_t delta_id =
id.y() * deltas_width + 4u * j;
158 const float pred_ctr_x = dx * width + ctr_x;
159 const float pred_ctr_y = dy * height + ctr_y;
160 const float pred_w = std::exp(dw) * width;
161 const float pred_h = std::exp(dh) * height;
163 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);
164 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);
165 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);
166 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);
172 template <
typename T>
173 void NEBoundingBoxTransformKernel::internal_run(
const Window &window)
177 const int img_h = std::floor(_bbinfo.
img_height() / _bbinfo.
scale() + 0.5f);
178 const int img_w = std::floor(_bbinfo.
img_width() / _bbinfo.
scale() + 0.5f);
180 const auto scale_after = (_bbinfo.
apply_scale() ? T(_bbinfo.
scale()) : T(1));
181 const auto scale_before = T(_bbinfo.
scale());
188 Iterator box_it(_boxes,
window);
191 const auto ptr = reinterpret_cast<T *>(box_it.ptr());
192 const auto b0 = *ptr;
193 const auto b1 = *(ptr + 1);
194 const auto b2 = *(ptr + 2);
195 const auto b3 = *(ptr + 3);
196 const T width = (b2 / scale_before) - (b0 / scale_before) + T(1.f);
197 const T height = (b3 / scale_before) - (b1 / scale_before) + T(1.f);
198 const T ctr_x = (b0 / scale_before) + T(0.5f) * width;
199 const T ctr_y = (b1 / scale_before) + T(0.5f) * height;
200 for(
size_t j = 0; j < num_classes; ++j)
203 const size_t delta_id =
id.y() * deltas_width + 4u * j;
204 const T dx = delta_ptr[delta_id] / T(_bbinfo.
weights()[0]);
205 const T dy = delta_ptr[delta_id + 1] / T(_bbinfo.
weights()[1]);
206 T dw = delta_ptr[delta_id + 2] / T(_bbinfo.
weights()[2]);
207 T dh = delta_ptr[delta_id + 3] / T(_bbinfo.
weights()[3]);
212 const T pred_ctr_x = dx * width + ctr_x;
213 const T pred_ctr_y = dy * height + ctr_y;
214 const T pred_w = std::exp(dw) * width;
215 const T pred_h = std::exp(dh) * height;
217 pred_ptr[delta_id] = scale_after * utility::clamp<T>(pred_ctr_x - T(0.5f) * pred_w, T(0), T(img_w - 1));
218 pred_ptr[delta_id + 1] = scale_after * utility::clamp<T>(pred_ctr_y - T(0.5f) * pred_h, T(0), T(img_h - 1));
219 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));
220 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));
235 internal_run<float>(
window);
240 internal_run<uint16_t>(
window);
243 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 246 internal_run<float16_t>(
window);
249 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC __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.
#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 CPU tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Copyright (c) 2017-2021 Arm Limited.
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.
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...
#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)