From dc9b52867b26e59ba34365f53820ddd7edf01ded Mon Sep 17 00:00:00 2001 From: George Wort Date: Wed, 16 Jan 2019 11:39:57 +0000 Subject: COMPMID-1795: Add support for NHWC in CLGenerateProposalsLayer Change-Id: Idd805513783fa1323e239eac8a899d8ab04fb14f Reviewed-on: https://review.mlplatform.org/536 Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio --- tests/validation/CL/GenerateProposalsLayer.cpp | 47 ++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/validation/CL/GenerateProposalsLayer.cpp b/tests/validation/CL/GenerateProposalsLayer.cpp index b4772fcf79..ac2d0ef969 100644 --- a/tests/validation/CL/GenerateProposalsLayer.cpp +++ b/tests/validation/CL/GenerateProposalsLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -24,6 +24,7 @@ #include "arm_compute/runtime/CL/CLScheduler.h" #include "arm_compute/runtime/CL/functions/CLComputeAllAnchors.h" #include "arm_compute/runtime/CL/functions/CLGenerateProposalsLayer.h" +#include "arm_compute/runtime/CL/functions/CLPermute.h" #include "arm_compute/runtime/CL/functions/CLSlice.h" #include "tests/CL/CLAccessor.h" #include "tests/CL/CLArrayAccessor.h" @@ -48,6 +49,31 @@ inline void fill_tensor(U &&tensor, const std::vector &v) std::memcpy(tensor.data(), v.data(), sizeof(T) * v.size()); } +template +inline void fill_tensor(CLAccessor &&tensor, const std::vector &v) +{ + if(tensor.data_layout() == DataLayout::NCHW) + { + std::memcpy(tensor.data(), v.data(), sizeof(T) * v.size()); + } + else + { + const int channels = tensor.shape()[0]; + const int width = tensor.shape()[1]; + const int height = tensor.shape()[2]; + for(int x = 0; x < width; ++x) + { + for(int y = 0; y < height; ++y) + { + for(int c = 0; c < channels; ++c) + { + *(reinterpret_cast(tensor(Coordinates(c, x, y)))) = *(reinterpret_cast(v.data() + x + y * width + c * height * width)); + } + } + } + } +} + const auto ComputeAllInfoDataset = framework::dataset::make("ComputeAllInfo", { ComputeAnchorsInfo(10U, 10U, 1. / 16.f), @@ -165,8 +191,9 @@ DATA_TEST_CASE(IntegrationTestCaseAllAnchors, framework::DatasetMode::ALL, frame validate(CLAccessor(all_anchors), anchors_expected); } -DATA_TEST_CASE(IntegrationTestCaseGenerateProposals, framework::DatasetMode::ALL, framework::dataset::make("DataType", { DataType::F32 }), - data_type) +DATA_TEST_CASE(IntegrationTestCaseGenerateProposals, framework::DatasetMode::ALL, combine(framework::dataset::make("DataType", { DataType::F32 }), + framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), + data_type, data_layout) { const int values_per_roi = 4; const int num_anchors = 2; @@ -260,9 +287,17 @@ DATA_TEST_CASE(IntegrationTestCaseGenerateProposals, framework::DatasetMode::ALL 8.91025957e-06f }); + TensorShape scores_shape = TensorShape(feature_width, feature_height, num_anchors); + TensorShape deltas_shape = TensorShape(feature_width, feature_height, values_per_roi * num_anchors); + if(data_layout == DataLayout::NHWC) + { + permute(scores_shape, PermutationVector(2U, 0U, 1U)); + permute(deltas_shape, PermutationVector(2U, 0U, 1U)); + } + // Inputs - CLTensor scores = create_tensor(TensorShape(feature_width, feature_height, num_anchors), data_type); - CLTensor bbox_deltas = create_tensor(TensorShape(feature_width, feature_height, values_per_roi * num_anchors), data_type); + CLTensor scores = create_tensor(scores_shape, data_type, 1, QuantizationInfo(), data_layout); + CLTensor bbox_deltas = create_tensor(deltas_shape, data_type, 1, QuantizationInfo(), data_layout); CLTensor anchors = create_tensor(TensorShape(values_per_roi, num_anchors), data_type); // Outputs @@ -282,7 +317,6 @@ DATA_TEST_CASE(IntegrationTestCaseGenerateProposals, framework::DatasetMode::ALL proposals.allocator()->allocate(); num_valid_proposals.allocator()->allocate(); scores_out.allocator()->allocate(); - // Fill inputs fill_tensor(CLAccessor(scores), scores_vector); fill_tensor(CLAccessor(bbox_deltas), bbx_vector); @@ -290,7 +324,6 @@ DATA_TEST_CASE(IntegrationTestCaseGenerateProposals, framework::DatasetMode::ALL // Run operator generate_proposals.run(); - // Gather num_valid_proposals num_valid_proposals.map(); const uint32_t N = *reinterpret_cast(num_valid_proposals.ptr_to_element(Coordinates(0, 0))); -- cgit v1.2.1