arm_compute v19.08
diff --git a/src/runtime/CPP/functions/CPPDetectionOutputLayer.cpp b/src/runtime/CPP/functions/CPPDetectionOutputLayer.cpp
index 9a141cb..13a34b4 100644
--- a/src/runtime/CPP/functions/CPPDetectionOutputLayer.cpp
+++ b/src/runtime/CPP/functions/CPPDetectionOutputLayer.cpp
@@ -34,7 +34,7 @@
{
namespace
{
-Status detection_layer_validate_arguments(const ITensorInfo *input_loc, const ITensorInfo *input_conf, const ITensorInfo *input_priorbox, const ITensorInfo *output, DetectionOutputLayerInfo info)
+Status validate_arguments(const ITensorInfo *input_loc, const ITensorInfo *input_conf, const ITensorInfo *input_priorbox, const ITensorInfo *output, DetectionOutputLayerInfo info)
{
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input_loc, input_conf, input_priorbox, output);
ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input_loc, 1, DataType::F32);
@@ -166,9 +166,9 @@
* @param[out] all_location_predictions All the location predictions.
*
*/
-void retrieve_all_priorbox(const ITensor *input_priorbox,
- const int num_priors,
- std::vector<NormalizedBBox> &all_prior_bboxes,
+void retrieve_all_priorbox(const ITensor *input_priorbox,
+ const int num_priors,
+ std::vector<BBox> &all_prior_bboxes,
std::vector<std::array<float, 4>> &all_prior_variances)
{
for(int i = 0; i < num_priors; ++i)
@@ -206,9 +206,9 @@
* @param[out] decode_bbox The decoded bboxes.
*
*/
-void DecodeBBox(const NormalizedBBox &prior_bbox, const std::array<float, 4> &prior_variance,
+void DecodeBBox(const BBox &prior_bbox, const std::array<float, 4> &prior_variance,
const DetectionOutputLayerCodeType code_type, const bool variance_encoded_in_target,
- const bool clip_bbox, const NormalizedBBox &bbox, NormalizedBBox &decode_bbox)
+ const bool clip_bbox, const BBox &bbox, BBox &decode_bbox)
{
// if the variance is encoded in target, we simply need to add the offset predictions
// otherwise we need to scale the offset accordingly.
@@ -287,7 +287,7 @@
* @param[out] indices The kept indices of bboxes after nms.
*
*/
-void ApplyNMSFast(const std::vector<NormalizedBBox> &bboxes,
+void ApplyNMSFast(const std::vector<BBox> &bboxes,
const std::vector<float> &scores, const float score_threshold,
const float nms_threshold, const float eta, const int top_k,
std::vector<int> &indices)
@@ -329,7 +329,7 @@
if(keep)
{
// Compute the jaccard (intersection over union IoU) overlap between two bboxes.
- NormalizedBBox intersect_bbox = std::array<float, 4>({ { 0, 0, 0, 0 } });
+ BBox intersect_bbox = std::array<float, 4>({ 0, 0, 0, 0 });
if(bboxes[kept_idx][0] > bboxes[idx][2] || bboxes[kept_idx][2] < bboxes[idx][0] || bboxes[kept_idx][1] > bboxes[idx][3] || bboxes[kept_idx][3] < bboxes[idx][1])
{
intersect_bbox = std::array<float, 4>({ { 0, 0, 0, 0 } });
@@ -380,97 +380,8 @@
}
}
}
-
-Status non_max_suppression_validate_arguments(const ITensorInfo *bboxes, const ITensorInfo *scores, const ITensorInfo *indices, unsigned int max_output_size,
- const float score_threshold, const float nms_threshold)
-{
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(bboxes, scores, indices);
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(bboxes, 1, DataType::F32);
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(scores, 1, DataType::F32);
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(indices, 1, DataType::S32);
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(bboxes->num_dimensions() > 2, "The bboxes tensor must be a 2-D float tensor of shape [4, num_boxes].");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(scores->num_dimensions() > 1, "The scores tensor must be a 1-D float tensor of shape [num_boxes].");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(indices->num_dimensions() > 1, "The indices must be 1-D integer tensor of shape [M], where max_output_size <= M");
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(bboxes, scores);
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(scores->num_dimensions() > 1, "Scores must be a 1D float tensor");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(indices->dimension(0) == 0, "Indices tensor must be bigger than 0");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(max_output_size == 0, "Max size cannot be 0");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(nms_threshold < 0.f || nms_threshold > 1.f, "Threshould must be in [0,1]");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(score_threshold < 0.f || score_threshold > 1.f, "Threshould must be in [0,1]");
-
- return Status{};
-}
} // namespace
-CPPNonMaximumSuppression::CPPNonMaximumSuppression()
- : _bboxes(nullptr), _scores(nullptr), _indices(nullptr), _max_output_size(0), _score_threshold(0.f), _nms_threshold(0.f)
-{
-}
-
-void CPPNonMaximumSuppression::configure(
- const ITensor *bboxes, const ITensor *scores, ITensor *indices, unsigned int max_output_size,
- const float score_threshold, const float nms_threshold)
-{
- ARM_COMPUTE_ERROR_ON_NULLPTR(bboxes, scores, indices);
- ARM_COMPUTE_ERROR_THROW_ON(non_max_suppression_validate_arguments(bboxes->info(), scores->info(), indices->info(), max_output_size, score_threshold, nms_threshold));
-
- // copy scores also to a vector
- _bboxes = bboxes;
- _scores = scores;
- _indices = indices;
-
- _nms_threshold = nms_threshold;
- _max_output_size = max_output_size;
- _score_threshold = score_threshold;
-}
-
-Status CPPNonMaximumSuppression::validate(
- const ITensorInfo *bboxes, const ITensorInfo *scores, const ITensorInfo *indices, unsigned int max_output_size,
- const float score_threshold, const float nms_threshold)
-{
- ARM_COMPUTE_RETURN_ON_ERROR(non_max_suppression_validate_arguments(bboxes, scores, indices, max_output_size, score_threshold, nms_threshold));
- return Status{};
-}
-
-void extract_bounding_boxes_from_tensor(const ITensor *bboxes, std::vector<NormalizedBBox> &bboxes_vector)
-{
- Window input_win;
- input_win.use_tensor_dimensions(bboxes->info()->tensor_shape());
- input_win.set_dimension_step(0U, 4U);
- input_win.set_dimension_step(1U, 1U);
- Iterator input(bboxes, input_win);
- auto f = [&bboxes_vector, &input](const Coordinates &)
- {
- const auto input_ptr = reinterpret_cast<const float *>(input.ptr());
- bboxes_vector.push_back(NormalizedBBox({ { *input_ptr, *(input_ptr + 1), *(2 + input_ptr), *(3 + input_ptr) } }));
- };
- execute_window_loop(input_win, f, input);
-}
-
-void extract_scores_from_tensor(const ITensor *scores, std::vector<float> &scores_vector)
-{
- Window window;
- window.use_tensor_dimensions(scores->info()->tensor_shape());
- Iterator it(scores, window);
- auto f = [&it, &scores_vector](const Coordinates &)
- {
- const auto input_ptr = reinterpret_cast<const float *>(it.ptr());
- scores_vector.push_back(*input_ptr);
- };
- execute_window_loop(window, f, it);
-}
-
-void CPPNonMaximumSuppression::run()
-{
- std::vector<NormalizedBBox> bboxes_vector;
- std::vector<float> scores_vector;
- std::vector<int> indices_vector;
- extract_bounding_boxes_from_tensor(_bboxes, bboxes_vector);
- extract_scores_from_tensor(_scores, scores_vector);
- ApplyNMSFast(bboxes_vector, scores_vector, _score_threshold, _nms_threshold, 1, -1 /* disable top_k */, indices_vector);
- std::copy_n(indices_vector.begin(), std::min(indices_vector.size(), _indices->info()->dimension(0)), reinterpret_cast<int *>(_indices->ptr_to_element(Coordinates(0))));
-}
-
CPPDetectionOutputLayer::CPPDetectionOutputLayer()
: _input_loc(nullptr), _input_conf(nullptr), _input_priorbox(nullptr), _output(nullptr), _info(), _num_priors(), _num(), _all_location_predictions(), _all_confidence_scores(), _all_prior_bboxes(),
_all_prior_variances(), _all_decode_bboxes(), _all_indices()
@@ -488,7 +399,7 @@
auto_init_if_empty(*output->info(), input_loc->info()->clone()->set_tensor_shape(TensorShape(7U, max_size)));
// Perform validation step
- ARM_COMPUTE_ERROR_THROW_ON(detection_layer_validate_arguments(input_loc->info(), input_conf->info(), input_priorbox->info(), output->info(), info));
+ ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input_loc->info(), input_conf->info(), input_priorbox->info(), output->info(), info));
_input_loc = input_loc;
_input_conf = input_conf;
@@ -526,7 +437,7 @@
Status CPPDetectionOutputLayer::validate(const ITensorInfo *input_loc, const ITensorInfo *input_conf, const ITensorInfo *input_priorbox, const ITensorInfo *output, DetectionOutputLayerInfo info)
{
- ARM_COMPUTE_RETURN_ON_ERROR(detection_layer_validate_arguments(input_loc, input_conf, input_priorbox, output, info));
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input_loc, input_conf, input_priorbox, output, info));
return Status{};
}
@@ -555,7 +466,7 @@
}
ARM_COMPUTE_ERROR_ON_MSG(_all_location_predictions[i].find(label) == _all_location_predictions[i].end(), "Could not find location predictions for label %d.", label);
- const std::vector<NormalizedBBox> &label_loc_preds = _all_location_predictions[i].find(label)->second;
+ const std::vector<BBox> &label_loc_preds = _all_location_predictions[i].find(label)->second;
const int num_bboxes = _all_prior_bboxes.size();
ARM_COMPUTE_ERROR_ON(_all_prior_variances[i].size() != 4);
@@ -588,8 +499,8 @@
{
ARM_COMPUTE_ERROR("Could not find predictions for label %d.", label);
}
- const std::vector<float> &scores = conf_scores.find(c)->second;
- const std::vector<NormalizedBBox> &bboxes = decode_bboxes.find(label)->second;
+ const std::vector<float> &scores = conf_scores.find(c)->second;
+ const std::vector<BBox> &bboxes = decode_bboxes.find(label)->second;
ApplyNMSFast(bboxes, scores, _info.confidence_threshold(), _info.nms_threshold(), _info.eta(), _info.top_k(), indices[c]);
@@ -661,8 +572,8 @@
// or there are no location predictions for current label.
ARM_COMPUTE_ERROR("Could not find predictions for the label %d.", label);
}
- const std::vector<NormalizedBBox> &bboxes = decode_bboxes.find(loc_label)->second;
- const std::vector<int> &indices = it.second;
+ const std::vector<BBox> &bboxes = decode_bboxes.find(loc_label)->second;
+ const std::vector<int> &indices = it.second;
for(auto idx : indices)
{