diff options
author | Manuel Bottini <manuel.bottini@arm.com> | 2018-10-24 17:27:02 +0100 |
---|---|---|
committer | Georgios Pinitas <georgios.pinitas@arm.com> | 2018-11-15 10:13:15 +0000 |
commit | 60f0a41c45813fa9c85cd4f8fbed57c4c9284a5c (patch) | |
tree | c3bda2f1f34a4a602875ddbe9b814b50365db192 /tests/validation | |
parent | 0cc37c31a36e7b146cf9640ad69925d7c06b71b4 (diff) | |
download | ComputeLibrary-60f0a41c45813fa9c85cd4f8fbed57c4c9284a5c.tar.gz |
COMPMID-1676: Change CLROIAlign interface to accept ROIs as tensors
Change-Id: I69e995973597ba3927d29e4f6ed5438560e53d77
Diffstat (limited to 'tests/validation')
-rw-r--r-- | tests/validation/CL/ROIAlignLayer.cpp | 48 | ||||
-rw-r--r-- | tests/validation/fixtures/ROIAlignLayerFixture.h | 80 | ||||
-rw-r--r-- | tests/validation/reference/ROIAlignLayer.cpp | 35 | ||||
-rw-r--r-- | tests/validation/reference/ROIAlignLayer.h | 2 |
4 files changed, 114 insertions, 51 deletions
diff --git a/tests/validation/CL/ROIAlignLayer.cpp b/tests/validation/CL/ROIAlignLayer.cpp index acea6d447c..f3fc3818f2 100644 --- a/tests/validation/CL/ROIAlignLayer.cpp +++ b/tests/validation/CL/ROIAlignLayer.cpp @@ -24,9 +24,8 @@ #include "arm_compute/runtime/CL/CLScheduler.h" #include "arm_compute/runtime/CL/functions/CLROIAlignLayer.h" #include "tests/CL/CLAccessor.h" -#include "tests/CL/CLArrayAccessor.h" #include "tests/Globals.h" -#include "tests/datasets/ROIPoolingLayerDataset.h" +#include "tests/datasets/ROIAlignLayerDataset.h" #include "tests/datasets/ShapeDatasets.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" @@ -43,7 +42,10 @@ namespace validation namespace { RelativeTolerance<float> relative_tolerance_f32(0.01f); -RelativeTolerance<float> absolute_tolerance_f32(0.001f); +AbsoluteTolerance<float> absolute_tolerance_f32(0.001f); + +RelativeTolerance<float> relative_tolerance_f16(0.01f); +AbsoluteTolerance<float> absolute_tolerance_f16(0.001f); } // namespace TEST_SUITE(CL) @@ -53,17 +55,28 @@ TEST_SUITE(RoiAlign) // clang-format off DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( framework::dataset::make("InputInfo", { TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), + TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching data type input/rois TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Mismatching data type input/output TensorInfo(TensorShape(250U, 128U, 2U), 1, DataType::F32), // Mismatching depth size input/output TensorInfo(TensorShape(250U, 128U, 2U), 1, DataType::F32), // Mismatching number of rois and output batch size + TensorInfo(TensorShape(250U, 128U, 3U), 1, DataType::F32), // Invalid number of values per ROIS TensorInfo(TensorShape(250U, 128U, 2U), 1, DataType::F32), // Mismatching height and width input/output }), - framework::dataset::make("NumRois", { 3U, 3U, 4U, 10U, 4U})), + framework::dataset::make("RoisInfo", { TensorInfo(TensorShape(5, 3U), 1, DataType::F32), + TensorInfo(TensorShape(5, 3U), 1, DataType::F16), + TensorInfo(TensorShape(5, 3U), 1, DataType::F32), + TensorInfo(TensorShape(5, 4U), 1, DataType::F32), + TensorInfo(TensorShape(5, 10U), 1, DataType::F32), + TensorInfo(TensorShape(4, 3U), 1, DataType::F32), + TensorInfo(TensorShape(5, 4U), 1, DataType::F32), + })), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(7U, 7U, 3U, 3U), 1, DataType::F32), + TensorInfo(TensorShape(7U, 7U, 3U, 3U), 1, DataType::F32), TensorInfo(TensorShape(7U, 7U, 3U, 3U), 1, DataType::F16), TensorInfo(TensorShape(7U, 7U, 4U, 3U), 1, DataType::F32), TensorInfo(TensorShape(7U, 7U, 2U, 3U), 1, DataType::F32), + TensorInfo(TensorShape(7U, 7U, 3U, 3U), 1, DataType::F32), TensorInfo(TensorShape(5U, 5U, 2U, 4U), 1, DataType::F32), })), framework::dataset::make("PoolInfo", { ROIPoolingLayerInfo(7U, 7U, 1./8), @@ -71,30 +84,35 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( ROIPoolingLayerInfo(7U, 7U, 1./8), ROIPoolingLayerInfo(7U, 7U, 1./8), ROIPoolingLayerInfo(7U, 7U, 1./8), + ROIPoolingLayerInfo(7U, 7U, 1./8), + ROIPoolingLayerInfo(7U, 7U, 1./8), })), - framework::dataset::make("Expected", { true, false, false, false, false })), - input_info, num_rois, output_info, pool_info, expected) + framework::dataset::make("Expected", { true, false, false, false, false, false, false })), + input_info, rois_info, output_info, pool_info, expected) { - ARM_COMPUTE_EXPECT(bool(CLROIAlignLayer::validate(&input_info.clone()->set_is_resizable(true), num_rois, &output_info.clone()->set_is_resizable(true), pool_info)) == expected, framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(bool(CLROIAlignLayer::validate(&input_info.clone()->set_is_resizable(true), &rois_info.clone()->set_is_resizable(true), &output_info.clone()->set_is_resizable(true), pool_info)) == expected, framework::LogLevel::ERRORS); } // clang-format on // *INDENT-ON* template <typename T> -using CLROIAlignLayerFixture = ROIAlignLayerFixture<CLTensor, CLAccessor, CLROIAlignLayer, CLArray<ROI>, CLArrayAccessor<ROI>, T>; +using CLROIAlignLayerFixture = ROIAlignLayerFixture<CLTensor, CLAccessor, CLROIAlignLayer, T>; TEST_SUITE(Float) -TEST_SUITE(FP32) -FIXTURE_DATA_TEST_CASE(SmallROIAlignLayer, CLROIAlignLayerFixture<float>, framework::DatasetMode::ALL, - framework::dataset::combine(framework::dataset::combine(datasets::SmallROIPoolingLayerDataset(), - framework::dataset::make("DataType", { DataType::F32 })), - framework::dataset::make("Batches", { 1, 4, 8 }))) +FIXTURE_DATA_TEST_CASE(SmallROIAlignLayerFloat, CLROIAlignLayerFixture<float>, framework::DatasetMode::ALL, + framework::dataset::combine(datasets::SmallROIAlignLayerDataset(), + framework::dataset::make("DataType", { DataType::F32 }))) { // Validate output validate(CLAccessor(_target), _reference, relative_tolerance_f32, .02f, absolute_tolerance_f32); } -TEST_SUITE_END() // FP32 - +FIXTURE_DATA_TEST_CASE(SmallROIAlignLayerHalf, CLROIAlignLayerFixture<half>, framework::DatasetMode::ALL, + framework::dataset::combine(datasets::SmallROIAlignLayerDataset(), + framework::dataset::make("DataType", { DataType::F16 }))) +{ + // Validate output + validate(CLAccessor(_target), _reference, relative_tolerance_f16, .02f, absolute_tolerance_f16); +} TEST_SUITE_END() // Float TEST_SUITE_END() // RoiAlign diff --git a/tests/validation/fixtures/ROIAlignLayerFixture.h b/tests/validation/fixtures/ROIAlignLayerFixture.h index d327b0914e..c029fbae8a 100644 --- a/tests/validation/fixtures/ROIAlignLayerFixture.h +++ b/tests/validation/fixtures/ROIAlignLayerFixture.h @@ -41,18 +41,15 @@ namespace test { namespace validation { -template <typename TensorType, typename AccessorType, typename FunctionType, typename Array_T, typename ArrayAccessor, typename T> +template <typename TensorType, typename AccessorType, typename FunctionType, typename T> class ROIAlignLayerFixture : public framework::Fixture { public: template <typename...> - void setup(TensorShape input_shape, const ROIPoolingLayerInfo pool_info, unsigned int num_rois, DataType data_type, int batches) + void setup(TensorShape input_shape, const ROIPoolingLayerInfo pool_info, TensorShape rois_shape, DataType data_type) { - input_shape.set(2, batches); - std::vector<ROI> rois = generate_random_rois(input_shape, pool_info, num_rois, 0U); - - _target = compute_target(input_shape, data_type, rois, pool_info); - _reference = compute_reference(input_shape, data_type, rois, pool_info); + _target = compute_target(input_shape, data_type, pool_info, rois_shape); + _reference = compute_reference(input_shape, data_type, pool_info, rois_shape); } protected: @@ -62,37 +59,78 @@ protected: library->fill_tensor_uniform(tensor, 0); } + template <typename U> + void generate_rois(U &&rois, const TensorShape &shape, const ROIPoolingLayerInfo &pool_info, TensorShape rois_shape) + { + const size_t values_per_roi = rois_shape.x(); + const size_t num_rois = rois_shape.y(); + + std::mt19937 gen(library->seed()); + T *rois_ptr = static_cast<T *>(rois.data()); + + const float pool_width = pool_info.pooled_width(); + const float pool_height = pool_info.pooled_height(); + const float roi_scale = pool_info.spatial_scale(); + + // Calculate distribution bounds + const auto scaled_width = static_cast<T>((shape.x() / roi_scale) / pool_width); + const auto scaled_height = static_cast<T>((shape.y() / roi_scale) / pool_height); + const auto min_width = static_cast<T>(pool_width / roi_scale); + const auto min_height = static_cast<T>(pool_height / roi_scale); + + // Create distributions + std::uniform_int_distribution<int> dist_batch(0, shape[3] - 1); + std::uniform_int_distribution<> dist_x1(0, scaled_width); + std::uniform_int_distribution<> dist_y1(0, scaled_height); + std::uniform_int_distribution<> dist_w(min_width, std::max(float(min_width), (pool_width - 2) * scaled_width)); + std::uniform_int_distribution<> dist_h(min_height, std::max(float(min_height), (pool_height - 2) * scaled_height)); + + for(unsigned int pw = 0; pw < num_rois; ++pw) + { + const auto batch_idx = dist_batch(gen); + const auto x1 = dist_x1(gen); + const auto y1 = dist_y1(gen); + const auto x2 = x1 + dist_w(gen); + const auto y2 = y1 + dist_h(gen); + + rois_ptr[values_per_roi * pw] = batch_idx; + rois_ptr[values_per_roi * pw + 1] = x1; + rois_ptr[values_per_roi * pw + 2] = y1; + rois_ptr[values_per_roi * pw + 3] = x2; + rois_ptr[values_per_roi * pw + 4] = y2; + } + } + TensorType compute_target(const TensorShape &input_shape, DataType data_type, - std::vector<ROI> const &rois, - const ROIPoolingLayerInfo &pool_info) + const ROIPoolingLayerInfo &pool_info, + const TensorShape rois_shape) { // Create tensors - TensorType src = create_tensor<TensorType>(input_shape, data_type); + TensorType src = create_tensor<TensorType>(input_shape, data_type); + TensorType rois_tensor = create_tensor<TensorType>(rois_shape, data_type); TensorType dst; - size_t num_rois = rois.size(); - - // Create roi arrays - std::unique_ptr<Array_T> rois_array = arm_compute::support::cpp14::make_unique<Array_T>(num_rois); - fill_array(ArrayAccessor(*rois_array), rois); - // Create and configure function FunctionType roi_align_layer; - roi_align_layer.configure(&src, rois_array.get(), &dst, pool_info); + roi_align_layer.configure(&src, &rois_tensor, &dst, pool_info); ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(rois_tensor.info()->is_resizable(), framework::LogLevel::ERRORS); ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); // Allocate tensors src.allocator()->allocate(); + rois_tensor.allocator()->allocate(); dst.allocator()->allocate(); ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!rois_tensor.info()->is_resizable(), framework::LogLevel::ERRORS); ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); // Fill tensors fill(AccessorType(src)); + generate_rois(AccessorType(rois_tensor), input_shape, pool_info, rois_shape); // Compute function roi_align_layer.run(); @@ -102,16 +140,18 @@ protected: SimpleTensor<T> compute_reference(const TensorShape &input_shape, DataType data_type, - std::vector<ROI> const &rois, - const ROIPoolingLayerInfo &pool_info) + const ROIPoolingLayerInfo &pool_info, + const TensorShape rois_shape) { // Create reference tensor SimpleTensor<T> src{ input_shape, data_type }; + SimpleTensor<T> rois_tensor{ rois_shape, data_type }; // Fill reference tensor fill(src); + generate_rois(rois_tensor, input_shape, pool_info, rois_shape); - return reference::roi_align_layer(src, rois, pool_info); + return reference::roi_align_layer(src, rois_tensor, pool_info); } TensorType _target{}; diff --git a/tests/validation/reference/ROIAlignLayer.cpp b/tests/validation/reference/ROIAlignLayer.cpp index 68a465d18f..8a76983d44 100644 --- a/tests/validation/reference/ROIAlignLayer.cpp +++ b/tests/validation/reference/ROIAlignLayer.cpp @@ -114,30 +114,35 @@ T clamp(T value, T lower, T upper) } } // namespace template <typename T> -SimpleTensor<T> roi_align_layer(const SimpleTensor<T> &src, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info) +SimpleTensor<T> roi_align_layer(const SimpleTensor<T> &src, const SimpleTensor<T> &rois, const ROIPoolingLayerInfo &pool_info) { - const size_t num_rois = rois.size(); - DataType dst_data_type = src.data_type(); + const size_t values_per_roi = rois.shape()[0]; + const size_t num_rois = rois.shape()[1]; + DataType dst_data_type = src.data_type(); + + const auto *rois_ptr = static_cast<const T *>(rois.data()); TensorShape input_shape = src.shape(); TensorShape output_shape(pool_info.pooled_width(), pool_info.pooled_height(), src.shape()[2], num_rois); SimpleTensor<T> dst(output_shape, dst_data_type); // Iterate over every pixel of the input image - for(size_t px = 0; px < pool_info.pooled_width(); px++) + for(size_t px = 0; px < pool_info.pooled_width(); ++px) { - for(size_t py = 0; py < pool_info.pooled_height(); py++) + for(size_t py = 0; py < pool_info.pooled_height(); ++py) { - for(size_t pw = 0; pw < num_rois; pw++) + for(size_t pw = 0; pw < num_rois; ++pw) { - ROI roi = rois[pw]; - const int roi_batch = roi.batch_idx; + const unsigned int roi_batch = rois_ptr[values_per_roi * pw]; + const auto x1 = float(rois_ptr[values_per_roi * pw + 1]); + const auto y1 = float(rois_ptr[values_per_roi * pw + 2]); + const auto x2 = float(rois_ptr[values_per_roi * pw + 3]); + const auto y2 = float(rois_ptr[values_per_roi * pw + 4]); - const float roi_anchor_x = roi.rect.x * pool_info.spatial_scale(); - const float roi_anchor_y = roi.rect.y * pool_info.spatial_scale(); - const float roi_dims_x = std::max(roi.rect.width * pool_info.spatial_scale(), 1.0f); - const float roi_dims_y = std::max(roi.rect.height * pool_info.spatial_scale(), 1.0f); - ; + const float roi_anchor_x = x1 * pool_info.spatial_scale(); + const float roi_anchor_y = y1 * pool_info.spatial_scale(); + const float roi_dims_x = std::max((x2 - x1) * pool_info.spatial_scale(), 1.0f); + const float roi_dims_y = std::max((y2 - y1) * pool_info.spatial_scale(), 1.0f); float bin_size_x = roi_dims_x / pool_info.pooled_width(); float bin_size_y = roi_dims_y / pool_info.pooled_height(); @@ -178,8 +183,8 @@ SimpleTensor<T> roi_align_layer(const SimpleTensor<T> &src, const std::vector<RO } return dst; } -template SimpleTensor<float> roi_align_layer(const SimpleTensor<float> &src, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info); -template SimpleTensor<half> roi_align_layer(const SimpleTensor<half> &src, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info); +template SimpleTensor<float> roi_align_layer(const SimpleTensor<float> &src, const SimpleTensor<float> &rois, const ROIPoolingLayerInfo &pool_info); +template SimpleTensor<half> roi_align_layer(const SimpleTensor<half> &src, const SimpleTensor<half> &rois, const ROIPoolingLayerInfo &pool_info); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/ROIAlignLayer.h b/tests/validation/reference/ROIAlignLayer.h index 818f9b147c..b67ff42166 100644 --- a/tests/validation/reference/ROIAlignLayer.h +++ b/tests/validation/reference/ROIAlignLayer.h @@ -37,7 +37,7 @@ namespace validation namespace reference { template <typename T> -SimpleTensor<T> roi_align_layer(const SimpleTensor<T> &src, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info); +SimpleTensor<T> roi_align_layer(const SimpleTensor<T> &src, const SimpleTensor<T> &rois, const ROIPoolingLayerInfo &pool_info); } // namespace reference } // namespace validation } // namespace test |