38 Status
validate_arguments(
const ITensorInfo *bboxes,
const ITensorInfo *scores,
const ITensorInfo *output_indices,
unsigned int max_output_size,
39 const float score_threshold,
const float iou_threshold)
46 ARM_COMPUTE_RETURN_ERROR_ON_MSG(output_indices->num_dimensions() > 1,
"The indices must be 1-D integer tensor of shape [M], where max_output_size <= M");
58 : _input_bboxes(nullptr), _input_scores(nullptr), _output_indices(nullptr), _max_output_size(0), _score_threshold(0.f), _iou_threshold(0.f), _num_boxes(0)
63 unsigned int max_output_size,
const float score_threshold,
const float iou_threshold)
70 _input_bboxes = input_bboxes;
71 _input_scores = input_scores;
72 _output_indices = output_indices;
73 _score_threshold = score_threshold;
74 _iou_threshold = iou_threshold;
75 _max_output_size = max_output_size;
82 ICPPKernel::configure(win);
86 unsigned int max_output_size,
const float score_threshold,
const float iou_threshold)
100 std::vector<int> indices_above_thd;
101 std::vector<float> scores_above_thd;
102 for(
unsigned int i = 0; i < _num_boxes; ++i)
105 if(score_i >= _score_threshold)
107 scores_above_thd.emplace_back(score_i);
108 indices_above_thd.emplace_back(i);
113 const unsigned int num_above_thd = indices_above_thd.size();
114 std::vector<unsigned int> sorted_indices;
115 sorted_indices.resize(num_above_thd);
116 std::iota(sorted_indices.data(), sorted_indices.data() + num_above_thd, 0);
117 std::sort(std::begin(sorted_indices),
119 [&](
unsigned int first,
unsigned int second)
121 return scores_above_thd[first] > scores_above_thd[second];
125 const unsigned int num_output = std::min(_max_output_size, num_above_thd);
126 unsigned int output_idx = 0;
127 std::vector<bool> visited(num_above_thd,
false);
130 for(
unsigned int i = 0; i < num_above_thd; ++i)
133 if(output_idx >= num_output)
139 if(!visited[sorted_indices[i]])
141 *(reinterpret_cast<int *>(_output_indices->
ptr_to_element(
Coordinates(output_idx)))) = indices_above_thd[sorted_indices[i]];
142 visited[sorted_indices[i]] =
true;
151 for(
unsigned int j = i + 1; j < num_above_thd; ++j)
153 if(!visited[sorted_indices[j]])
156 const unsigned int i_index = indices_above_thd[sorted_indices[i]];
157 const unsigned int j_index = indices_above_thd[sorted_indices[j]];
169 const float area_i = (box_i_xmax - box_i_xmin) * (box_i_ymax - box_i_ymin);
170 const float area_j = (box_j_xmax - box_j_xmin) * (box_j_ymax - box_j_ymin);
172 if(area_i <= 0 || area_j <= 0)
178 const auto y_min_intersection = std::max<float>(box_i_ymin, box_j_ymin);
179 const auto x_min_intersection = std::max<float>(box_i_xmin, box_j_xmin);
180 const auto y_max_intersection = std::min<float>(box_i_ymax, box_j_ymax);
181 const auto x_max_intersection = std::min<float>(box_i_xmax, box_j_xmax);
182 const auto area_intersection = std::max<float>(y_max_intersection - y_min_intersection, 0.0f) * std::max<float>(x_max_intersection - x_min_intersection, 0.0f);
183 overlap = area_intersection / (area_i + area_j - area_intersection);
186 if(overlap > _iou_threshold)
188 visited[sorted_indices[j]] =
true;
195 for(; output_idx < _max_output_size; ++output_idx)
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.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
1 channel, 1 U8 per channel
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
static Status validate(const ITensorInfo *input_bboxes, const ITensorInfo *input_scores, const ITensorInfo *output_indices, unsigned int max_output_size, const float score_threshold, const float iou_threshold)
Static function to check if given arguments will lead to a valid configuration of CPPNonMaximumSuppre...
1 channel, 1 F32 per channel
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Interface for CPU tensor.
Copyright (c) 2017-2021 Arm Limited.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
1 channel, 1 S32 per channel
Quantization information.
CPPNonMaximumSuppressionKernel()
Default constructor.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Class to describe a number of elements in each dimension.
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 ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void end(TokenStream &in, bool &valid)
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
void configure(const ITensor *input_bboxes, const ITensor *input_scores, ITensor *output_indices, unsigned int max_output_size, const float score_threshold, const float iou_threshold)
Configure the kernel to perform non maximal suppression.
#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_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Describe a multidimensional execution window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)