From d696cb6d18c2fe66f1abce88bbd14faf2137ef89 Mon Sep 17 00:00:00 2001 From: giuros01 Date: Fri, 16 Nov 2018 10:39:59 +0000 Subject: COMPMID-1451: Fixes for BoundingBoxTransform - Fixing a bug for which we did not scale the boxes before transforming them - Adding the correct_transform_coords option to BoundingBoxTransformInfo Change-Id: I40281254bcf87e7c8583c119e99562414fe59822 --- tests/validation/CL/BoundingBoxTransform.cpp | 15 ++++++++++----- tests/validation/reference/BoundingBoxTransform.cpp | 21 ++++++++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/validation/CL/BoundingBoxTransform.cpp b/tests/validation/CL/BoundingBoxTransform.cpp index dba3a0eabe..c5856cae3d 100644 --- a/tests/validation/CL/BoundingBoxTransform.cpp +++ b/tests/validation/CL/BoundingBoxTransform.cpp @@ -50,7 +50,8 @@ const auto BboxInfoDataset = framework::dataset::make("BboxInfo", { BoundingBoxT BoundingBoxTransformInfo(128U, 128U, 4U, true), BoundingBoxTransformInfo(800U, 600U, 1U, false), BoundingBoxTransformInfo(800U, 600U, 2U, true, { 1.0, 0.5, 1.5, 2.0 }), - BoundingBoxTransformInfo(800U, 600U, 4U, false, { 1.0, 0.5, 1.5, 2.0 }) + BoundingBoxTransformInfo(800U, 600U, 4U, false, { 1.0, 0.5, 1.5, 2.0 }), + BoundingBoxTransformInfo(800U, 600U, 4U, false, { 1.0, 0.5, 1.5, 2.0 }, true) }); const auto DeltaDataset = framework::dataset::make("DeltasShape", { TensorShape(36U, 1U), @@ -74,22 +75,26 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( TensorInfo(TensorShape(5U, 128U), 1, DataType::F32), // Wrong number of box fields TensorInfo(TensorShape(4U, 128U), 1, DataType::F16), // Wrong data type TensorInfo(TensorShape(4U, 128U), 1, DataType::F32), // Wrong number of classes - TensorInfo(TensorShape(4U, 128U), 1, DataType::F32)}), // Deltas and predicted boxes have different dimensions + TensorInfo(TensorShape(4U, 128U), 1, DataType::F32), // Deltas and predicted boxes have different dimensions + TensorInfo(TensorShape(4U, 128U), 1, DataType::F32)}), // Scaling is zero framework::dataset::make("PredBoxesInfo",{ TensorInfo(TensorShape(128U, 128U), 1, DataType::F32), TensorInfo(TensorShape(128U, 128U), 1, DataType::F32), TensorInfo(TensorShape(127U, 128U), 1, DataType::F32), TensorInfo(TensorShape(128U, 100U), 1, DataType::F32), - TensorInfo(TensorShape(128U, 100U), 1, DataType::F32)})), + TensorInfo(TensorShape(128U, 100U), 1, DataType::F32), + TensorInfo(TensorShape(128U, 128U), 1, DataType::F32)})), framework::dataset::make("DeltasInfo", { TensorInfo(TensorShape(128U, 128U), 1, DataType::F32), TensorInfo(TensorShape(128U, 128U), 1, DataType::F32), TensorInfo(TensorShape(127U, 128U), 1, DataType::F32), TensorInfo(TensorShape(128U, 100U), 1, DataType::F32), + TensorInfo(TensorShape(128U, 128U), 1, DataType::F32), TensorInfo(TensorShape(128U, 128U), 1, DataType::F32)})), framework::dataset::make("BoundingBoxTransofmInfo", { BoundingBoxTransformInfo(800.f, 600.f, 1.f), BoundingBoxTransformInfo(800.f, 600.f, 1.f), BoundingBoxTransformInfo(800.f, 600.f, 1.f), - BoundingBoxTransformInfo(800.f, 600.f, 1.f)})), - framework::dataset::make("Expected", { true, false, false, false, false })), + BoundingBoxTransformInfo(800.f, 600.f, 1.f), + BoundingBoxTransformInfo(800.f, 600.f, 0.f)})), + framework::dataset::make("Expected", { true, false, false, false, false, false})), boxes_info, pred_boxes_info, deltas_info, bbox_info, expected) { ARM_COMPUTE_EXPECT(bool(CLBoundingBoxTransform::validate(&boxes_info.clone()->set_is_resizable(true), &pred_boxes_info.clone()->set_is_resizable(true), &deltas_info.clone()->set_is_resizable(true), bbox_info)) == expected, framework::LogLevel::ERRORS); diff --git a/tests/validation/reference/BoundingBoxTransform.cpp b/tests/validation/reference/BoundingBoxTransform.cpp index 9918ff68c5..55dd165b51 100644 --- a/tests/validation/reference/BoundingBoxTransform.cpp +++ b/tests/validation/reference/BoundingBoxTransform.cpp @@ -50,7 +50,10 @@ SimpleTensor bounding_box_transform(const SimpleTensor &boxes, const Simpl const int img_h = floor(info.img_height() / info.scale() + 0.5f); const int img_w = floor(info.img_width() / info.scale() + 0.5f); - const T scale = (info.apply_scale() ? T(info.scale()) : T(1)); + const auto scale_after = (info.apply_scale() ? T(info.scale()) : T(1)); + const auto scale_before = T(info.scale()); + ARM_COMPUTE_ERROR_ON(scale_before <= 0); + const auto offset = (info.correct_transform_coords() ? T(1.f) : T(0.f)); const size_t box_fields = 4; const size_t class_fields = 4; @@ -59,10 +62,10 @@ SimpleTensor bounding_box_transform(const SimpleTensor &boxes, const Simpl { // Extract ROI information const size_t start_box = box_fields * i; - const T width = boxes[start_box + 2] - boxes[start_box] + T(1.0); - const T height = boxes[start_box + 3] - boxes[start_box + 1] + T(1.0); - const T ctr_x = boxes[start_box] + T(0.5) * width; - const T ctr_y = boxes[start_box + 1] + T(0.5) * height; + const T width = (boxes[start_box + 2] / scale_before) - (boxes[start_box] / scale_before) + T(1.f); + const T height = (boxes[start_box + 3] / scale_before) - (boxes[start_box + 1] / scale_before) + T(1.f); + const T ctr_x = (boxes[start_box] / scale_before) + T(0.5f) * width; + const T ctr_y = (boxes[start_box + 1] / scale_before) + T(0.5f) * height; for(size_t j = 0; j < num_classes; ++j) { @@ -84,10 +87,10 @@ SimpleTensor bounding_box_transform(const SimpleTensor &boxes, const Simpl const T pred_h = T(std::exp(dh)) * height; // Store the prediction into the output tensor - pred_boxes_ptr[start_delta] = scale * utility::clamp(pred_ctr_x - T(0.5) * pred_w, T(0), T(img_w - 1)); - pred_boxes_ptr[start_delta + 1] = scale * utility::clamp(pred_ctr_y - T(0.5) * pred_h, T(0), T(img_h - 1)); - pred_boxes_ptr[start_delta + 2] = scale * utility::clamp(pred_ctr_x + T(0.5) * pred_w, T(0), T(img_w - 1)); - pred_boxes_ptr[start_delta + 3] = scale * utility::clamp(pred_ctr_y + T(0.5) * pred_h, T(0), T(img_h - 1)); + pred_boxes_ptr[start_delta] = scale_after * utility::clamp(pred_ctr_x - T(0.5f) * pred_w, T(0), T(img_w - 1)); + pred_boxes_ptr[start_delta + 1] = scale_after * utility::clamp(pred_ctr_y - T(0.5f) * pred_h, T(0), T(img_h - 1)); + pred_boxes_ptr[start_delta + 2] = scale_after * utility::clamp(pred_ctr_x + T(0.5f) * pred_w - offset, T(0), T(img_w - 1)); + pred_boxes_ptr[start_delta + 3] = scale_after * utility::clamp(pred_ctr_y + T(0.5f) * pred_h - offset, T(0), T(img_h - 1)); } } return pred_boxes; -- cgit v1.2.1