aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Tello <pablo.tello@arm.com>2019-09-13 10:20:25 +0100
committerPablo Marquez <pablo.tello@arm.com>2019-09-20 09:27:12 +0000
commitc9564cb3850b6675cef663d7cc0722567b55cc25 (patch)
tree1ab16f4e24240fed839967c6e1b7a34597adce18
parent7b9d7ca0d207d9f4d4b96222940eb96c2e10a0f1 (diff)
downloadComputeLibrary-c9564cb3850b6675cef663d7cc0722567b55cc25.tar.gz
COMPMID-2257: Implement NEGenerateProposals.
Change-Id: I8d751f8b09f842a214c305a4530a71d82f16db8f Signed-off-by: Pablo Tello <pablo.tello@arm.com> Reviewed-on: https://review.mlplatform.org/c/1943 Tested-by: Arm Jenkins <bsgcomp@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
-rw-r--r--arm_compute/core/NEON/NEKernels.h1
-rw-r--r--arm_compute/core/NEON/kernels/NECopyKernel.h17
-rw-r--r--arm_compute/core/NEON/kernels/NEGenerateProposalsLayerKernel.h82
-rw-r--r--arm_compute/runtime/NEON/NEFunctions.h2
-rw-r--r--arm_compute/runtime/NEON/functions/NEComputeAllAnchors.h62
-rw-r--r--arm_compute/runtime/NEON/functions/NEGenerateProposalsLayer.h147
-rw-r--r--src/core/NEON/kernels/NECopyKernel.cpp116
-rw-r--r--src/core/NEON/kernels/NEGenerateProposalsLayerKernel.cpp131
-rw-r--r--src/runtime/NEON/functions/NEComputeAllAnchors.cpp42
-rw-r--r--src/runtime/NEON/functions/NEGenerateProposalsLayer.cpp264
-rw-r--r--tests/validation/NEON/GenerateProposalsLayer.cpp403
-rw-r--r--tests/validation/fixtures/ComputeAllAnchorsFixture.h2
12 files changed, 1241 insertions, 28 deletions
diff --git a/arm_compute/core/NEON/NEKernels.h b/arm_compute/core/NEON/NEKernels.h
index 80bc74e135..5eaf8ad445 100644
--- a/arm_compute/core/NEON/NEKernels.h
+++ b/arm_compute/core/NEON/NEKernels.h
@@ -94,6 +94,7 @@
#include "arm_compute/core/NEON/kernels/NEGaussian3x3Kernel.h"
#include "arm_compute/core/NEON/kernels/NEGaussian5x5Kernel.h"
#include "arm_compute/core/NEON/kernels/NEGaussianPyramidKernel.h"
+#include "arm_compute/core/NEON/kernels/NEGenerateProposalsLayerKernel.h"
#include "arm_compute/core/NEON/kernels/NEHOGDescriptorKernel.h"
#include "arm_compute/core/NEON/kernels/NEHOGDetectorKernel.h"
#include "arm_compute/core/NEON/kernels/NEHarrisCornersKernel.h"
diff --git a/arm_compute/core/NEON/kernels/NECopyKernel.h b/arm_compute/core/NEON/kernels/NECopyKernel.h
index c6df9bafae..ddf1bb41fb 100644
--- a/arm_compute/core/NEON/kernels/NECopyKernel.h
+++ b/arm_compute/core/NEON/kernels/NECopyKernel.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018 ARM Limited.
+ * Copyright (c) 2018-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -51,18 +51,20 @@ public:
NECopyKernel &operator=(NECopyKernel &&) = default;
/** Initialize the kernel's input, output.
*
- * @param[in] input Source tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
- * @param[out] output Destination tensor. Data types supported: same as @p input.
+ * @param[in] input Source tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
+ * @param[out] output Destination tensor. Data types supported: same as @p input.
+ * @param[in] padding (Optional) Padding to be applied to the input tensor
*/
- void configure(const ITensor *input, ITensor *output);
+ void configure(const ITensor *input, ITensor *output, const PaddingList &padding = PaddingList());
/** Static function to check if given info will lead to a valid configuration of @ref NECopyKernel
*
- * @param[in] input Source tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
- * @param[in] output Destination tensor. Data types supported: same as @p input.
+ * @param[in] input Source tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
+ * @param[in] output Destination tensor. Data types supported: same as @p input.
+ * @param[in] padding (Optional) Padding to be applied to the input tensor
*
* @return a status
*/
- static Status validate(const ITensorInfo *input, const ITensorInfo *output);
+ static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding = PaddingList());
// Inherited methods overridden:
void run(const Window &window, const ThreadInfo &info) override;
@@ -70,6 +72,7 @@ public:
private:
const ITensor *_input;
ITensor *_output;
+ PaddingList _padding;
};
} // namespace arm_compute
#endif /*__ARM_COMPUTE_NECOPYKERNEL_H__ */
diff --git a/arm_compute/core/NEON/kernels/NEGenerateProposalsLayerKernel.h b/arm_compute/core/NEON/kernels/NEGenerateProposalsLayerKernel.h
new file mode 100644
index 0000000000..a7b2603648
--- /dev/null
+++ b/arm_compute/core/NEON/kernels/NEGenerateProposalsLayerKernel.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2019 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_NEGENERATEPROPOSALSLAYERKERNEL_H__
+#define __ARM_COMPUTE_NEGENERATEPROPOSALSLAYERKERNEL_H__
+
+#include "arm_compute/core/NEON/INEKernel.h"
+namespace arm_compute
+{
+class ITensor;
+
+/** Interface for Compute All Anchors kernel */
+class NEComputeAllAnchorsKernel : public INEKernel
+{
+public:
+ const char *name() const override
+ {
+ return "NEComputeAllAnchorsKernel";
+ }
+
+ /** Default constructor */
+ NEComputeAllAnchorsKernel();
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ NEComputeAllAnchorsKernel(const NEComputeAllAnchorsKernel &) = delete;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ NEComputeAllAnchorsKernel &operator=(const NEComputeAllAnchorsKernel &) = delete;
+ /** Allow instances of this class to be moved */
+ NEComputeAllAnchorsKernel(NEComputeAllAnchorsKernel &&) = default;
+ /** Allow instances of this class to be moved */
+ NEComputeAllAnchorsKernel &operator=(NEComputeAllAnchorsKernel &&) = default;
+ /** Default destructor */
+ ~NEComputeAllAnchorsKernel() = default;
+
+ /** Set the input and output tensors.
+ *
+ * @param[in] anchors Source tensor. Original set of anchors of size (4, A), where A is the number of anchors. Data types supported: F16/F32
+ * @param[out] all_anchors Destination tensor. Destination anchors of size (4, H*W*A) where H and W are the height and width of the feature map and A is the number of anchors. Data types supported: Same as @p input
+ * @param[in] info Contains Compute Anchors operation information described in @ref ComputeAnchorsInfo
+ *
+ */
+ void configure(const ITensor *anchors, ITensor *all_anchors, const ComputeAnchorsInfo &info);
+
+ /** Static function to check if given info will lead to a valid configuration of @ref NEComputeAllAnchorsKernel
+ *
+ * @param[in] anchors Source tensor info. Original set of anchors of size (4, A), where A is the number of anchors. Data types supported: F16/F32
+ * @param[in] all_anchors Destination tensor info. Destination anchors of size (4, H*W*A) where H and W are the height and width of the feature map and A is the number of anchors. Data types supported: Same as @p input
+ * @param[in] info Contains Compute Anchors operation information described in @ref ComputeAnchorsInfo
+ *
+ * @return a Status
+ */
+ static Status validate(const ITensorInfo *anchors, const ITensorInfo *all_anchors, const ComputeAnchorsInfo &info);
+
+ // Inherited methods overridden:
+ void run(const Window &window, const ThreadInfo &info) override;
+
+private:
+ const ITensor *_anchors;
+ ITensor *_all_anchors;
+ ComputeAnchorsInfo _anchors_info;
+};
+} // arm_compute
+#endif // __ARM_COMPUTE_NEGENERATEPROPOSALSLAYERKERNEL_H__
diff --git a/arm_compute/runtime/NEON/NEFunctions.h b/arm_compute/runtime/NEON/NEFunctions.h
index 09d3c65e25..28fd7f37b9 100644
--- a/arm_compute/runtime/NEON/NEFunctions.h
+++ b/arm_compute/runtime/NEON/NEFunctions.h
@@ -46,6 +46,7 @@
#include "arm_compute/runtime/NEON/functions/NEChannelShuffleLayer.h"
#include "arm_compute/runtime/NEON/functions/NECol2Im.h"
#include "arm_compute/runtime/NEON/functions/NEColorConvert.h"
+#include "arm_compute/runtime/NEON/functions/NEComputeAllAnchors.h"
#include "arm_compute/runtime/NEON/functions/NEConcatenateLayer.h"
#include "arm_compute/runtime/NEON/functions/NEConvertFullyConnectedWeights.h"
#include "arm_compute/runtime/NEON/functions/NEConvolution.h"
@@ -85,6 +86,7 @@
#include "arm_compute/runtime/NEON/functions/NEGaussian3x3.h"
#include "arm_compute/runtime/NEON/functions/NEGaussian5x5.h"
#include "arm_compute/runtime/NEON/functions/NEGaussianPyramid.h"
+#include "arm_compute/runtime/NEON/functions/NEGenerateProposalsLayer.h"
#include "arm_compute/runtime/NEON/functions/NEHOGDescriptor.h"
#include "arm_compute/runtime/NEON/functions/NEHOGDetector.h"
#include "arm_compute/runtime/NEON/functions/NEHOGGradient.h"
diff --git a/arm_compute/runtime/NEON/functions/NEComputeAllAnchors.h b/arm_compute/runtime/NEON/functions/NEComputeAllAnchors.h
new file mode 100644
index 0000000000..5f24b3e618
--- /dev/null
+++ b/arm_compute/runtime/NEON/functions/NEComputeAllAnchors.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2019 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_NECOMPUTEALLANCHORS_H__
+#define __ARM_COMPUTE_NECOMPUTEALLANCHORS_H__
+
+#include "arm_compute/core/NEON/kernels/NEGenerateProposalsLayerKernel.h"
+#include "arm_compute/runtime/NEON/INESimpleFunction.h"
+
+namespace arm_compute
+{
+class ITensor;
+
+/** Basic function to run @ref NEComputeAllAnchorsKernel.
+ *
+ * This function calls the following NEON kernels:
+ * -# @ref NEComputeAllAnchorsKernel
+ */
+class NEComputeAllAnchors : public INESimpleFunction
+{
+public:
+ /** Set the input and output tensors.
+ *
+ * @param[in] anchors Source tensor. Original set of anchors of size (4, A) where A is the number of anchors. Data types supported: F16/F32
+ * @param[out] all_anchors Destination tensor. Destination anchors of size (4, H*W*A) where H and W are the height and width of the feature map and A is the number of anchors. Data types supported: Same as @p input
+ * @param[in] info Contains Compute Anchors operation information described in @ref ComputeAnchorsInfo
+ *
+ */
+ void configure(const ITensor *anchors, ITensor *all_anchors, const ComputeAnchorsInfo &info);
+
+ /** Static function to check if given info will lead to a valid configuration of @ref NEComputeAllAnchorsKernel
+ *
+ * @param[in] anchors Source tensor info. Original set of anchors of size (4, A) where A is the number of anchors. Data types supported: F16/F32
+ * @param[in] all_anchors Destination tensor info. Destination anchors of size (4, H*W*A) where H and W are the height and width of the feature map and A is the number of anchors. Data types supported: Same as @p input
+ * @param[in] info Contains Compute Anchors operation information described in @ref ComputeAnchorsInfo
+ *
+ * @return a Status
+ */
+ static Status validate(const ITensorInfo *anchors, const ITensorInfo *all_anchors, const ComputeAnchorsInfo &info);
+};
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_NECOMPUTEALLANCHORS_H__ */
diff --git a/arm_compute/runtime/NEON/functions/NEGenerateProposalsLayer.h b/arm_compute/runtime/NEON/functions/NEGenerateProposalsLayer.h
new file mode 100644
index 0000000000..0e6601e4f9
--- /dev/null
+++ b/arm_compute/runtime/NEON/functions/NEGenerateProposalsLayer.h
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2019 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_NEGENERATEPROPOSALSLAYER_H__
+#define __ARM_COMPUTE_NEGENERATEPROPOSALSLAYER_H__
+#include "arm_compute/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.h"
+#include "arm_compute/core/NEON/kernels/NEBoundingBoxTransformKernel.h"
+#include "arm_compute/core/NEON/kernels/NECopyKernel.h"
+#include "arm_compute/core/NEON/kernels/NEGenerateProposalsLayerKernel.h"
+#include "arm_compute/core/NEON/kernels/NEMemsetKernel.h"
+#include "arm_compute/core/NEON/kernels/NEPermuteKernel.h"
+#include "arm_compute/core/NEON/kernels/NEReshapeLayerKernel.h"
+#include "arm_compute/core/NEON/kernels/NEStridedSliceKernel.h"
+#include "arm_compute/core/Types.h"
+#include "arm_compute/runtime/CPP/CPPScheduler.h"
+#include "arm_compute/runtime/IFunction.h"
+#include "arm_compute/runtime/MemoryGroup.h"
+#include "arm_compute/runtime/Tensor.h"
+
+namespace arm_compute
+{
+class ITensor;
+
+/** Basic function to generate proposals for a RPN (Region Proposal Network)
+ *
+ * This function calls the following Neon kernels:
+ * -# @ref NEComputeAllAnchors
+ * -# @ref NEPermute x 2
+ * -# @ref NEReshapeLayer x 2
+ * -# @ref NEStridedSlice x 3
+ * -# @ref NEBoundingBoxTransform
+ * -# @ref NECopyKernel
+ * -# @ref NEMemsetKernel
+ * And the following CPP kernels:
+ * -# @ref CPPBoxWithNonMaximaSuppressionLimit
+ */
+class NEGenerateProposalsLayer : public IFunction
+{
+public:
+ /** Default constructor
+ *
+ * @param[in] memory_manager (Optional) Memory manager.
+ */
+ NEGenerateProposalsLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ NEGenerateProposalsLayer(const NEGenerateProposalsLayer &) = delete;
+ /** Default move constructor */
+ NEGenerateProposalsLayer(NEGenerateProposalsLayer &&) = default;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ NEGenerateProposalsLayer &operator=(const NEGenerateProposalsLayer &) = delete;
+ /** Default move assignment operator */
+ NEGenerateProposalsLayer &operator=(NEGenerateProposalsLayer &&) = default;
+
+ /** Set the input and output tensors.
+ *
+ * @param[in] scores Scores from convolution layer of size (W, H, A), where H and W are the height and width of the feature map, and A is the number of anchors. Data types supported: F16/F32
+ * @param[in] deltas Bounding box deltas from convolution layer of size (W, H, 4*A). Data types supported: Same as @p scores
+ * @param[in] anchors Anchors tensor of size (4, A). Data types supported: Same as @p input
+ * @param[out] proposals Box proposals output tensor of size (5, W*H*A). Data types supported: Same as @p input
+ * @param[out] scores_out Box scores output tensor of size (W*H*A). Data types supported: Same as @p input
+ * @param[out] num_valid_proposals Scalar output tensor which says which of the first proposals are valid. Data types supported: U32
+ * @param[in] info Contains GenerateProposals operation information described in @ref GenerateProposalsInfo
+ *
+ * @note Only single image prediction is supported. Height and Width (and scale) of the image will be contained in the @ref GenerateProposalsInfo struct.
+ * @note Proposals contains all the proposals. Of those, only the first num_valid_proposals are valid.
+ */
+ void configure(const ITensor *scores, const ITensor *deltas, const ITensor *anchors, ITensor *proposals, ITensor *scores_out, ITensor *num_valid_proposals,
+ const GenerateProposalsInfo &info);
+
+ /** Static function to check if given info will lead to a valid configuration of @ref NEGenerateProposalsLayer
+ *
+ * @param[in] scores Scores info from convolution layer of size (W, H, A), where H and W are the height and width of the feature map, and A is the number of anchors. Data types supported: F16/F32
+ * @param[in] deltas Bounding box deltas info from convolution layer of size (W, H, 4*A). Data types supported: Same as @p scores
+ * @param[in] anchors Anchors tensor info of size (4, A). Data types supported: Same as @p input
+ * @param[in] proposals Box proposals info output tensor of size (5, W*H*A). Data types supported: Data types supported: U32
+ * @param[in] scores_out Box scores output tensor info of size (W*H*A). Data types supported: Same as @p input
+ * @param[in] num_valid_proposals Scalar output tensor info which says which of the first proposals are valid. Data types supported: Same as @p input
+ * @param[in] info Contains GenerateProposals operation information described in @ref GenerateProposalsInfo
+ *
+ * @return a Status
+ */
+ static Status validate(const ITensorInfo *scores, const ITensorInfo *deltas, const ITensorInfo *anchors, const ITensorInfo *proposals, const ITensorInfo *scores_out,
+ const ITensorInfo *num_valid_proposals,
+ const GenerateProposalsInfo &info);
+
+ // Inherited methods overridden:
+ void run() override;
+
+private:
+ // Memory group manager
+ MemoryGroup _memory_group;
+
+ // Neon kernels
+ NEPermuteKernel _permute_deltas_kernel;
+ NEReshapeLayerKernel _flatten_deltas_kernel;
+ NEPermuteKernel _permute_scores_kernel;
+ NEReshapeLayerKernel _flatten_scores_kernel;
+ NEComputeAllAnchorsKernel _compute_anchors_kernel;
+ NEBoundingBoxTransformKernel _bounding_box_kernel;
+ NEMemsetKernel _memset_kernel;
+ NECopyKernel _padded_copy_kernel;
+
+ // CPP kernels
+ CPPBoxWithNonMaximaSuppressionLimitKernel _cpp_nms_kernel;
+
+ bool _is_nhwc;
+
+ // Temporary tensors
+ Tensor _deltas_permuted;
+ Tensor _deltas_flattened;
+ Tensor _scores_permuted;
+ Tensor _scores_flattened;
+ Tensor _all_anchors;
+ Tensor _all_proposals;
+ Tensor _keeps_nms_unused;
+ Tensor _classes_nms_unused;
+ Tensor _proposals_4_roi_values;
+
+ // Output tensor pointers
+ ITensor *_num_valid_proposals;
+ ITensor *_scores_out;
+
+ /** Internal function to run the CPP BoxWithNMS kernel */
+ void run_cpp_nms_kernel();
+};
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_NEGENERATEPROPOSALSLAYER_H__ */
diff --git a/src/core/NEON/kernels/NECopyKernel.cpp b/src/core/NEON/kernels/NECopyKernel.cpp
index 4722c05507..83f3dded4f 100644
--- a/src/core/NEON/kernels/NECopyKernel.cpp
+++ b/src/core/NEON/kernels/NECopyKernel.cpp
@@ -29,28 +29,88 @@
#include "arm_compute/core/TensorInfo.h"
#include "arm_compute/core/Validate.h"
#include "arm_compute/core/Window.h"
+#include "arm_compute/core/utils/misc/ShapeCalculator.h"
-using namespace arm_compute;
+namespace arm_compute
+{
+namespace
+{
+Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding = PaddingList())
+{
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output);
+ ARM_COMPUTE_RETURN_ERROR_ON(padding.size() > 4);
+
+ // Validate output if initialized
+ if(output->total_size() != 0)
+ {
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(misc::shape_calculator::compute_padded_shape(input->tensor_shape(), padding), output->tensor_shape());
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
+ }
+
+ return Status{};
+}
+
+std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output)
+{
+ // Output auto inizialitation if not yet initialized
+ auto_init_if_empty(*output, *input);
+ return std::make_pair(Status{}, calculate_max_window(*output));
+}
+
+std::pair<Status, Window> validate_and_configure_window_with_padding(ITensorInfo *input, ITensorInfo *output, const PaddingList &padding)
+{
+ const TensorShape input_shape = input->tensor_shape();
+ const TensorShape padded_shape = misc::shape_calculator::compute_padded_shape(input_shape, padding);
+ auto_init_if_empty(*output, input->clone()->set_tensor_shape(padded_shape));
+ // Configure window
+ const Window win = calculate_max_window(*output, output->dimension(0));
+ return std::make_pair(Status{}, win);
+}
+
+} // namespace
NECopyKernel::NECopyKernel()
- : _input(nullptr), _output(nullptr)
+ : _input(nullptr), _output(nullptr), _padding()
{
}
-void NECopyKernel::configure(const ITensor *input, ITensor *output)
+void NECopyKernel::configure(const ITensor *input, ITensor *output, const PaddingList &padding)
{
ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
+ ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), padding));
+
+ _input = input;
+ _output = output;
+ _padding = padding;
- _input = input;
- _output = output;
+ std::pair<Status, Window> win_config;
- INEKernel::configure(calculate_max_window(*output->info()));
+ if(padding.empty())
+ {
+ win_config = validate_and_configure_window(input->info(), output->info());
+ }
+ else
+ {
+ win_config = validate_and_configure_window_with_padding(input->info(), output->info(), padding);
+ }
+
+ ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
+ INEKernel::configure(win_config.second);
}
-Status NECopyKernel::validate(const arm_compute::ITensorInfo *input, const arm_compute::ITensorInfo *output)
+Status NECopyKernel::validate(const arm_compute::ITensorInfo *input, const arm_compute::ITensorInfo *output, const PaddingList &padding)
{
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, padding));
+
+ if(padding.empty())
+ {
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first);
+ }
+ else
+ {
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_with_padding(input->clone().get(), output->clone().get(), padding).first);
+ }
+
return Status{};
}
@@ -60,22 +120,38 @@ void NECopyKernel::run(const Window &window, const ThreadInfo &info)
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
- Window output_window{ window };
- output_window.set(Window::DimX, Window::Dimension(output_window.x().start(), output_window.x().end(), _input->info()->dimension(0)));
-
- Window out_slice = output_window.first_slice_window_1D();
+ if(_padding.empty())
+ {
+ Window output_window{ window };
+ output_window.set(Window::DimX, Window::Dimension(output_window.x().start(), output_window.x().end(), _input->info()->dimension(0)));
+ Window out_slice = output_window.first_slice_window_1D();
+ do
+ {
+ Iterator input_it(_input, out_slice);
+ Iterator output_it(_output, out_slice);
- do
+ execute_window_loop(out_slice, [&](const Coordinates &)
+ {
+ memcpy(output_it.ptr(), input_it.ptr(), _output->info()->dimension(0) * _output->info()->element_size());
+ },
+ input_it, output_it);
+ }
+ while(output_window.slide_window_slice_1D(out_slice));
+ }
+ else
{
- Iterator input_it(_input, out_slice);
- Iterator output_it(_output, out_slice);
+ Window input_window{ window };
+ input_window.set(Window::DimX, Window::Dimension(0, window.x().end() - _padding[0].first, _input->info()->dimension(0)));
- execute_window_loop(out_slice, [&](const Coordinates &)
+ Iterator input_it(_input, input_window);
+ Iterator output_it(_output, window);
+ const size_t row_size_in_bytes = _input->info()->dimension(0) * _input->info()->element_size();
+ execute_window_loop(window, [&](const Coordinates &)
{
- memcpy(output_it.ptr(), input_it.ptr(), _output->info()->dimension(0) * _output->info()->element_size());
+ auto dst_ptr = output_it.ptr() + _padding[0].first * _output->info()->element_size();
+ std::memcpy(dst_ptr, input_it.ptr(), row_size_in_bytes);
},
input_it, output_it);
-
}
- while(output_window.slide_window_slice_1D(out_slice));
}
+} // namespace arm_compute
diff --git a/src/core/NEON/kernels/NEGenerateProposalsLayerKernel.cpp b/src/core/NEON/kernels/NEGenerateProposalsLayerKernel.cpp
new file mode 100644
index 0000000000..4a585b70fd
--- /dev/null
+++ b/src/core/NEON/kernels/NEGenerateProposalsLayerKernel.cpp
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2019 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/core/NEON/kernels/NEGenerateProposalsLayerKernel.h"
+
+#include "arm_compute/core/AccessWindowStatic.h"
+#include "arm_compute/core/CPP/Validate.h"
+#include "arm_compute/core/Helpers.h"
+#include "arm_compute/core/TensorInfo.h"
+#include "arm_compute/core/Utils.h"
+#include "arm_compute/core/Window.h"
+
+namespace arm_compute
+{
+namespace
+{
+Status validate_arguments(const ITensorInfo *anchors, const ITensorInfo *all_anchors, const ComputeAnchorsInfo &info)
+{
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(anchors, all_anchors);
+ ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(anchors);
+ ARM_COMPUTE_RETURN_ERROR_ON(anchors->dimension(0) != info.values_per_roi());
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(anchors, DataType::F16, DataType::F32);
+ ARM_COMPUTE_RETURN_ERROR_ON(anchors->num_dimensions() > 2);
+ if(all_anchors->total_size() > 0)
+ {
+ const size_t feature_height = info.feat_height();
+ const size_t feature_width = info.feat_width();
+ const size_t num_anchors = anchors->dimension(1);
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(all_anchors, anchors);
+ ARM_COMPUTE_RETURN_ERROR_ON(all_anchors->num_dimensions() > 2);
+ ARM_COMPUTE_RETURN_ERROR_ON(all_anchors->dimension(0) != info.values_per_roi());
+ ARM_COMPUTE_RETURN_ERROR_ON(all_anchors->dimension(1) != feature_height * feature_width * num_anchors);
+ }
+ return Status{};
+}
+
+} // namespace
+
+NEComputeAllAnchorsKernel::NEComputeAllAnchorsKernel()
+ : _anchors(nullptr), _all_anchors(nullptr), _anchors_info(0.f, 0.f, 0.f)
+{
+}
+
+void NEComputeAllAnchorsKernel::configure(const ITensor *anchors, ITensor *all_anchors, const ComputeAnchorsInfo &info)
+{
+ ARM_COMPUTE_ERROR_ON_NULLPTR(anchors, all_anchors);
+ ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(anchors->info(), all_anchors->info(), info));
+
+ // Metadata
+ const size_t num_anchors = anchors->info()->dimension(1);
+ const DataType data_type = anchors->info()->data_type();
+ const float width = info.feat_width();
+ const float height = info.feat_height();
+
+ // Initialize the output if empty
+ const TensorShape output_shape(info.values_per_roi(), width * height * num_anchors);
+ auto_init_if_empty(*all_anchors->info(), output_shape, 1, data_type);
+
+ // Set instance variables
+ _anchors = anchors;
+ _all_anchors = all_anchors;
+ _anchors_info = info;
+
+ Window win = calculate_max_window(*all_anchors->info(), Steps(info.values_per_roi()));
+
+ INEKernel::configure(win);
+}
+
+Status NEComputeAllAnchorsKernel::validate(const ITensorInfo *anchors, const ITensorInfo *all_anchors, const ComputeAnchorsInfo &info)
+{
+ ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(anchors, all_anchors, info));
+ return Status{};
+}
+
+void NEComputeAllAnchorsKernel::run(const Window &window, const ThreadInfo &info)
+{
+ ARM_COMPUTE_UNUSED(info);
+ ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
+ ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
+
+ Iterator all_anchors_it(_all_anchors, window);
+ Iterator anchors_it(_all_anchors, window);
+
+ const size_t num_anchors = _anchors->info()->dimension(1);
+ const float stride = 1.f / _anchors_info.spatial_scale();
+ const size_t feat_width = _anchors_info.feat_width();
+
+ execute_window_loop(window, [&](const Coordinates & id)
+ {
+ const size_t anchor_offset = id.y() % num_anchors;
+
+ const auto out_anchor_ptr = reinterpret_cast<float *>(all_anchors_it.ptr());
+ const auto anchor_ptr = reinterpret_cast<float *>(_anchors->ptr_to_element(Coordinates(0, anchor_offset)));
+
+ *out_anchor_ptr = *anchor_ptr;
+ *(1 + out_anchor_ptr) = *(1 + anchor_ptr);
+ *(2 + out_anchor_ptr) = *(2 + anchor_ptr);
+ *(3 + out_anchor_ptr) = *(3 + anchor_ptr);
+
+ const size_t shift_idy = id.y() / num_anchors;
+ const float shiftx = (shift_idy % feat_width) * stride;
+ const float shifty = (shift_idy / feat_width) * stride;
+
+ *out_anchor_ptr += shiftx;
+ *(out_anchor_ptr + 1) += shifty;
+ *(out_anchor_ptr + 2) += shiftx;
+ *(out_anchor_ptr + 3) += shifty;
+ },
+ all_anchors_it);
+}
+} // namespace arm_compute
diff --git a/src/runtime/NEON/functions/NEComputeAllAnchors.cpp b/src/runtime/NEON/functions/NEComputeAllAnchors.cpp
new file mode 100644
index 0000000000..7702fb026d
--- /dev/null
+++ b/src/runtime/NEON/functions/NEComputeAllAnchors.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2019 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/runtime/NEON/functions/NEComputeAllAnchors.h"
+
+#include "support/ToolchainSupport.h"
+
+namespace arm_compute
+{
+void NEComputeAllAnchors::configure(const ITensor *anchors, ITensor *all_anchors, const ComputeAnchorsInfo &info)
+{
+ // Configure ComputeAllAnchors kernel
+ auto k = arm_compute::support::cpp14::make_unique<NEComputeAllAnchorsKernel>();
+ k->configure(anchors, all_anchors, info);
+ _kernel = std::move(k);
+}
+
+Status NEComputeAllAnchors::validate(const ITensorInfo *anchors, const ITensorInfo *all_anchors, const ComputeAnchorsInfo &info)
+{
+ return NEComputeAllAnchorsKernel::validate(anchors, all_anchors, info);
+}
+} // namespace arm_compute
diff --git a/src/runtime/NEON/functions/NEGenerateProposalsLayer.cpp b/src/runtime/NEON/functions/NEGenerateProposalsLayer.cpp
new file mode 100644
index 0000000000..6e5da43a94
--- /dev/null
+++ b/src/runtime/NEON/functions/NEGenerateProposalsLayer.cpp
@@ -0,0 +1,264 @@
+/*
+ * Copyright (c) 2019 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/runtime/NEON/functions/NEGenerateProposalsLayer.h"
+
+#include "arm_compute/core/Types.h"
+#include "arm_compute/runtime/NEON/NEScheduler.h"
+#include "support/ToolchainSupport.h"
+
+namespace arm_compute
+{
+NEGenerateProposalsLayer::NEGenerateProposalsLayer(std::shared_ptr<IMemoryManager> memory_manager)
+ : _memory_group(std::move(memory_manager)),
+ _permute_deltas_kernel(),
+ _flatten_deltas_kernel(),
+ _permute_scores_kernel(),
+ _flatten_scores_kernel(),
+ _compute_anchors_kernel(),
+ _bounding_box_kernel(),
+ _memset_kernel(),
+ _padded_copy_kernel(),
+ _cpp_nms_kernel(),
+ _is_nhwc(false),
+ _deltas_permuted(),
+ _deltas_flattened(),
+ _scores_permuted(),
+ _scores_flattened(),
+ _all_anchors(),
+ _all_proposals(),
+ _keeps_nms_unused(),
+ _classes_nms_unused(),
+ _proposals_4_roi_values(),
+ _num_valid_proposals(nullptr),
+ _scores_out(nullptr)
+{
+}
+
+void NEGenerateProposalsLayer::configure(const ITensor *scores, const ITensor *deltas, const ITensor *anchors, ITensor *proposals, ITensor *scores_out, ITensor *num_valid_proposals,
+ const GenerateProposalsInfo &info)
+{
+ ARM_COMPUTE_ERROR_ON_NULLPTR(scores, deltas, anchors, proposals, scores_out, num_valid_proposals);
+ ARM_COMPUTE_ERROR_THROW_ON(NEGenerateProposalsLayer::validate(scores->info(), deltas->info(), anchors->info(), proposals->info(), scores_out->info(), num_valid_proposals->info(), info));
+
+ _is_nhwc = scores->info()->data_layout() == DataLayout::NHWC;
+ const DataType data_type = deltas->info()->data_type();
+ const int num_anchors = scores->info()->dimension(get_data_layout_dimension_index(scores->info()->data_layout(), DataLayoutDimension::CHANNEL));
+ const int feat_width = scores->info()->dimension(get_data_layout_dimension_index(scores->info()->data_layout(), DataLayoutDimension::WIDTH));
+ const int feat_height = scores->info()->dimension(get_data_layout_dimension_index(scores->info()->data_layout(), DataLayoutDimension::HEIGHT));
+ const int total_num_anchors = num_anchors * feat_width * feat_height;
+ const int pre_nms_topN = info.pre_nms_topN();
+ const int post_nms_topN = info.post_nms_topN();
+ const size_t values_per_roi = info.values_per_roi();
+
+ // Compute all the anchors
+ _memory_group.manage(&_all_anchors);
+ _compute_anchors_kernel.configure(anchors, &_all_anchors, ComputeAnchorsInfo(feat_width, feat_height, info.spatial_scale()));
+
+ const TensorShape flatten_shape_deltas(values_per_roi, total_num_anchors);
+ _deltas_flattened.allocator()->init(TensorInfo(flatten_shape_deltas, 1, data_type));
+ _memory_group.manage(&_deltas_flattened);
+
+ // Permute and reshape deltas
+ if(!_is_nhwc)
+ {
+ _memory_group.manage(&_deltas_permuted);
+ _permute_deltas_kernel.configure(deltas, &_deltas_permuted, PermutationVector{ 2, 0, 1 });
+ _flatten_deltas_kernel.configure(&_deltas_permuted, &_deltas_flattened);
+ _deltas_permuted.allocator()->allocate();
+ }
+ else
+ {
+ _flatten_deltas_kernel.configure(deltas, &_deltas_flattened);
+ }
+
+ const TensorShape flatten_shape_scores(1, total_num_anchors);
+ _scores_flattened.allocator()->init(TensorInfo(flatten_shape_scores, 1, data_type));
+ _memory_group.manage(&_scores_flattened);
+ // Permute and reshape scores
+ if(!_is_nhwc)
+ {
+ _memory_group.manage(&_scores_permuted);
+ _permute_scores_kernel.configure(scores, &_scores_permuted, PermutationVector{ 2, 0, 1 });
+ _flatten_scores_kernel.configure(&_scores_permuted, &_scores_flattened);
+ _scores_permuted.allocator()->allocate();
+ }
+ else
+ {
+ _flatten_scores_kernel.configure(scores, &_scores_flattened);
+ }
+
+ // Bounding box transform
+ _memory_group.manage(&_all_proposals);
+ BoundingBoxTransformInfo bbox_info(info.im_width(), info.im_height(), 1.f);
+ _bounding_box_kernel.configure(&_all_anchors, &_all_proposals, &_deltas_flattened, bbox_info);
+ _deltas_flattened.allocator()->allocate();
+ _all_anchors.allocator()->allocate();
+
+ // The original layer implementation first selects the best pre_nms_topN anchors (thus having a lightweight sort)
+ // that are then transformed by bbox_transform. The boxes generated are then fed into a non-sorting NMS operation.
+ // Since we are reusing the NMS layer and we don't implement any CL/sort, we let NMS do the sorting (of all the input)
+ // and the filtering
+ const int scores_nms_size = std::min<int>(std::min<int>(post_nms_topN, pre_nms_topN), total_num_anchors);
+ const float min_size_scaled = info.min_size() * info.im_scale();
+ _memory_group.manage(&_classes_nms_unused);
+ _memory_group.manage(&_keeps_nms_unused);
+
+ // Note that NMS needs outputs preinitialized.
+ auto_init_if_empty(*scores_out->info(), TensorShape(scores_nms_size), 1, data_type);
+ auto_init_if_empty(*_proposals_4_roi_values.info(), TensorShape(values_per_roi, scores_nms_size), 1, data_type);
+ auto_init_if_empty(*num_valid_proposals->info(), TensorShape(scores_nms_size), 1, DataType::U32);
+
+ // Initialize temporaries (unused) outputs
+ _classes_nms_unused.allocator()->init(TensorInfo(TensorShape(8, 1), 1, data_type));
+ _keeps_nms_unused.allocator()->init(*scores_out->info());
+
+ // Save the output (to map and unmap them at run)
+ _scores_out = scores_out;
+ _num_valid_proposals = num_valid_proposals;
+
+ _memory_group.manage(&_proposals_4_roi_values);
+
+ const BoxNMSLimitInfo box_nms_info(0.0f, info.nms_thres(), scores_nms_size, false, NMSType::LINEAR, 0.5f, 0.001f, true, min_size_scaled, info.im_width(), info.im_height());
+ _cpp_nms_kernel.configure(&_scores_flattened /*scores_in*/,
+ &_all_proposals /*boxes_in,*/,
+ nullptr /* batch_splits_in*/,
+ scores_out /* scores_out*/,
+ &_proposals_4_roi_values /*boxes_out*/,
+ &_classes_nms_unused /*classes*/,
+ nullptr /*batch_splits_out*/,
+ &_keeps_nms_unused /*keeps*/,
+ num_valid_proposals /* keeps_size*/,
+ box_nms_info);
+
+ _keeps_nms_unused.allocator()->allocate();
+ _classes_nms_unused.allocator()->allocate();
+ _all_proposals.allocator()->allocate();
+ _scores_flattened.allocator()->allocate();
+
+ // Add the first column that represents the batch id. This will be all zeros, as we don't support multiple images
+ _padded_copy_kernel.configure(&_proposals_4_roi_values, proposals, PaddingList{ { 1, 0 } });
+ _proposals_4_roi_values.allocator()->allocate();
+
+ _memset_kernel.configure(proposals, PixelValue());
+}
+
+Status NEGenerateProposalsLayer::validate(const ITensorInfo *scores, const ITensorInfo *deltas, const ITensorInfo *anchors, const ITensorInfo *proposals, const ITensorInfo *scores_out,
+ const ITensorInfo *num_valid_proposals, const GenerateProposalsInfo &info)
+{
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(scores, deltas, anchors, proposals, scores_out, num_valid_proposals);
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(scores, DataLayout::NCHW, DataLayout::NHWC);
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(scores, deltas);
+
+ const int num_anchors = scores->dimension(get_data_layout_dimension_index(scores->data_layout(), DataLayoutDimension::CHANNEL));
+ const int feat_width = scores->dimension(get_data_layout_dimension_index(scores->data_layout(), DataLayoutDimension::WIDTH));
+ const int feat_height = scores->dimension(get_data_layout_dimension_index(scores->data_layout(), DataLayoutDimension::HEIGHT));
+ const int num_images = scores->dimension(3);
+ const int total_num_anchors = num_anchors * feat_width * feat_height;
+ const int values_per_roi = info.values_per_roi();
+
+ ARM_COMPUTE_RETURN_ERROR_ON(num_images > 1);
+
+ TensorInfo all_anchors_info(anchors->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEComputeAllAnchorsKernel::validate(anchors, &all_anchors_info, ComputeAnchorsInfo(feat_width, feat_height, info.spatial_scale())));
+
+ TensorInfo deltas_permuted_info = deltas->clone()->set_tensor_shape(TensorShape(values_per_roi * num_anchors, feat_width, feat_height)).set_is_resizable(true);
+ TensorInfo scores_permuted_info = scores->clone()->set_tensor_shape(TensorShape(num_anchors, feat_width, feat_height)).set_is_resizable(true);
+ if(scores->data_layout() == DataLayout::NHWC)
+ {
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(deltas, &deltas_permuted_info);
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(scores, &scores_permuted_info);
+ }
+ else
+ {
+ ARM_COMPUTE_RETURN_ON_ERROR(NEPermuteKernel::validate(deltas, &deltas_permuted_info, PermutationVector{ 2, 0, 1 }));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEPermuteKernel::validate(scores, &scores_permuted_info, PermutationVector{ 2, 0, 1 }));
+ }
+
+ TensorInfo deltas_flattened_info(deltas->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEReshapeLayerKernel::validate(&deltas_permuted_info, &deltas_flattened_info));
+
+ TensorInfo scores_flattened_info(scores->clone()->set_tensor_shape(TensorShape(1, total_num_anchors)).set_is_resizable(true));
+ TensorInfo proposals_4_roi_values(deltas->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true));
+
+ ARM_COMPUTE_RETURN_ON_ERROR(NEReshapeLayerKernel::validate(&scores_permuted_info, &scores_flattened_info));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEBoundingBoxTransformKernel::validate(&all_anchors_info, &proposals_4_roi_values, &deltas_flattened_info, BoundingBoxTransformInfo(info.im_width(), info.im_height(),
+ 1.f)));
+
+ ARM_COMPUTE_RETURN_ON_ERROR(NECopyKernel::validate(&proposals_4_roi_values, proposals, PaddingList{ { 0, 1 } }));
+
+ if(num_valid_proposals->total_size() > 0)
+ {
+ ARM_COMPUTE_RETURN_ERROR_ON(num_valid_proposals->num_dimensions() > 1);
+ ARM_COMPUTE_RETURN_ERROR_ON(num_valid_proposals->dimension(0) > 1);
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(num_valid_proposals, 1, DataType::U32);
+ }
+
+ if(proposals->total_size() > 0)
+ {
+ ARM_COMPUTE_RETURN_ERROR_ON(proposals->num_dimensions() > 2);
+ ARM_COMPUTE_RETURN_ERROR_ON(proposals->dimension(0) != size_t(values_per_roi) + 1);
+ ARM_COMPUTE_RETURN_ERROR_ON(proposals->dimension(1) != size_t(total_num_anchors));
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(proposals, deltas);
+ }
+
+ if(scores_out->total_size() > 0)
+ {
+ ARM_COMPUTE_RETURN_ERROR_ON(scores_out->num_dimensions() > 1);
+ ARM_COMPUTE_RETURN_ERROR_ON(scores_out->dimension(0) != size_t(total_num_anchors));
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(scores_out, scores);
+ }
+
+ return Status{};
+}
+
+void NEGenerateProposalsLayer::run()
+{
+ // Acquire all the temporaries
+ MemoryGroupResourceScope scope_mg(_memory_group);
+
+ // Compute all the anchors
+ NEScheduler::get().schedule(&_compute_anchors_kernel, Window::DimY);
+
+ // Transpose and reshape the inputs
+ if(!_is_nhwc)
+ {
+ NEScheduler::get().schedule(&_permute_deltas_kernel, Window::DimY);
+ NEScheduler::get().schedule(&_permute_scores_kernel, Window::DimY);
+ }
+
+ NEScheduler::get().schedule(&_flatten_deltas_kernel, Window::DimY);
+ NEScheduler::get().schedule(&_flatten_scores_kernel, Window::DimY);
+
+ // Build the boxes
+ NEScheduler::get().schedule(&_bounding_box_kernel, Window::DimY);
+
+ // Non maxima suppression
+ CPPScheduler::get().schedule(&_cpp_nms_kernel, Window::DimX);
+
+ // Add dummy batch indexes
+
+ NEScheduler::get().schedule(&_memset_kernel, Window::DimY);
+ NEScheduler::get().schedule(&_padded_copy_kernel, Window::DimY);
+}
+} // namespace arm_compute
diff --git a/tests/validation/NEON/GenerateProposalsLayer.cpp b/tests/validation/NEON/GenerateProposalsLayer.cpp
new file mode 100644
index 0000000000..ea99bb3107
--- /dev/null
+++ b/tests/validation/NEON/GenerateProposalsLayer.cpp
@@ -0,0 +1,403 @@
+/*
+ * Copyright (c) 2019 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/runtime/NEON/NEScheduler.h"
+#include "arm_compute/runtime/NEON/functions/NEComputeAllAnchors.h"
+#include "arm_compute/runtime/NEON/functions/NEGenerateProposalsLayer.h"
+#include "arm_compute/runtime/NEON/functions/NEPermute.h"
+#include "arm_compute/runtime/NEON/functions/NESlice.h"
+#include "tests/Globals.h"
+#include "tests/NEON/Accessor.h"
+#include "tests/NEON/ArrayAccessor.h"
+#include "tests/framework/Macros.h"
+#include "tests/framework/datasets/Datasets.h"
+#include "tests/validation/Validation.h"
+#include "tests/validation/fixtures/ComputeAllAnchorsFixture.h"
+#include "utils/TypePrinter.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace
+{
+template <typename U, typename T>
+inline void fill_tensor(U &&tensor, const std::vector<T> &v)
+{
+ std::memcpy(tensor.data(), v.data(), sizeof(T) * v.size());
+}
+
+template <typename T>
+inline void fill_tensor(Accessor &&tensor, const std::vector<T> &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<T *>(tensor(Coordinates(c, x, y)))) = *(reinterpret_cast<const T *>(v.data() + x + y * width + c * height * width));
+ }
+ }
+ }
+ }
+}
+
+const auto ComputeAllInfoDataset = framework::dataset::make("ComputeAllInfo",
+{
+ ComputeAnchorsInfo(10U, 10U, 1. / 16.f),
+ ComputeAnchorsInfo(100U, 1U, 1. / 2.f),
+ ComputeAnchorsInfo(100U, 1U, 1. / 4.f),
+ ComputeAnchorsInfo(100U, 100U, 1. / 4.f),
+
+});
+} // namespace
+
+TEST_SUITE(NEON)
+TEST_SUITE(GenerateProposals)
+
+// *INDENT-OFF*
+// clang-format off
+DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(
+ framework::dataset::make("scores", { TensorInfo(TensorShape(100U, 100U, 9U), 1, DataType::F32),
+ TensorInfo(TensorShape(100U, 100U, 9U), 1, DataType::F16), // Mismatching types
+ TensorInfo(TensorShape(100U, 100U, 9U), 1, DataType::F16), // Wrong deltas (number of transformation non multiple of 4)
+ TensorInfo(TensorShape(100U, 100U, 9U), 1, DataType::F16), // Wrong anchors (number of values per roi != 5)
+ TensorInfo(TensorShape(100U, 100U, 9U), 1, DataType::F16), // Output tensor num_valid_proposals not scalar
+ TensorInfo(TensorShape(100U, 100U, 9U), 1, DataType::F16)}), // num_valid_proposals not U32
+ framework::dataset::make("deltas",{ TensorInfo(TensorShape(100U, 100U, 36U), 1, DataType::F32),
+ TensorInfo(TensorShape(100U, 100U, 36U), 1, DataType::F32),
+ TensorInfo(TensorShape(100U, 100U, 38U), 1, DataType::F32),
+ TensorInfo(TensorShape(100U, 100U, 38U), 1, DataType::F32),
+ TensorInfo(TensorShape(100U, 100U, 38U), 1, DataType::F32),
+ TensorInfo(TensorShape(100U, 100U, 38U), 1, DataType::F32)})),
+ framework::dataset::make("anchors", { TensorInfo(TensorShape(4U, 9U), 1, DataType::F32),
+ TensorInfo(TensorShape(4U, 9U), 1, DataType::F32),
+ TensorInfo(TensorShape(4U, 9U), 1, DataType::F32),
+ TensorInfo(TensorShape(5U, 9U), 1, DataType::F32),
+ TensorInfo(TensorShape(4U, 9U), 1, DataType::F32),
+ TensorInfo(TensorShape(4U, 9U), 1, DataType::F32)})),
+ framework::dataset::make("proposals", { TensorInfo(TensorShape(5U, 100U*100U*9U), 1, DataType::F32),
+ TensorInfo(TensorShape(5U, 100U*100U*9U), 1, DataType::F32),
+ TensorInfo(TensorShape(5U, 100U*100U*9U), 1, DataType::F32),
+ TensorInfo(TensorShape(5U, 100U*100U*9U), 1, DataType::F32),
+ TensorInfo(TensorShape(5U, 100U*100U*9U), 1, DataType::F32),
+ TensorInfo(TensorShape(5U, 100U*100U*9U), 1, DataType::F32)})),
+ framework::dataset::make("scores_out", { TensorInfo(TensorShape(100U*100U*9U), 1, DataType::F32),
+ TensorInfo(TensorShape(100U*100U*9U), 1, DataType::F32),
+ TensorInfo(TensorShape(100U*100U*9U), 1, DataType::F32),
+ TensorInfo(TensorShape(100U*100U*9U), 1, DataType::F32),
+ TensorInfo(TensorShape(100U*100U*9U), 1, DataType::F32),
+ TensorInfo(TensorShape(100U*100U*9U), 1, DataType::F32)})),
+ framework::dataset::make("num_valid_proposals", { TensorInfo(TensorShape(1U, 1U), 1, DataType::U32),
+ TensorInfo(TensorShape(1U, 1U), 1, DataType::U32),
+ TensorInfo(TensorShape(1U, 1U), 1, DataType::U32),
+ TensorInfo(TensorShape(1U, 1U), 1, DataType::U32),
+ TensorInfo(TensorShape(1U, 10U), 1, DataType::U32),
+ TensorInfo(TensorShape(1U, 1U), 1, DataType::F16)})),
+ framework::dataset::make("generate_proposals_info", { GenerateProposalsInfo(10.f, 10.f, 1.f),
+ GenerateProposalsInfo(10.f, 10.f, 1.f),
+ GenerateProposalsInfo(10.f, 10.f, 1.f),
+ GenerateProposalsInfo(10.f, 10.f, 1.f),
+ GenerateProposalsInfo(10.f, 10.f, 1.f),
+ GenerateProposalsInfo(10.f, 10.f, 1.f)})),
+ framework::dataset::make("Expected", { true, false, false, false, false, false })),
+ scores, deltas, anchors, proposals, scores_out, num_valid_proposals, generate_proposals_info, expected)
+{
+ ARM_COMPUTE_EXPECT(bool(NEGenerateProposalsLayer::validate(&scores.clone()->set_is_resizable(true),
+ &deltas.clone()->set_is_resizable(true),
+ &anchors.clone()->set_is_resizable(true),
+ &proposals.clone()->set_is_resizable(true),
+ &scores_out.clone()->set_is_resizable(true),
+ &num_valid_proposals.clone()->set_is_resizable(true),
+ generate_proposals_info)) == expected, framework::LogLevel::ERRORS);
+}
+// clang-format on
+// *INDENT-ON*
+
+template <typename T>
+using NEComputeAllAnchorsFixture = ComputeAllAnchorsFixture<Tensor, Accessor, NEComputeAllAnchors, T>;
+
+TEST_SUITE(Float)
+TEST_SUITE(FP32)
+DATA_TEST_CASE(IntegrationTestCaseAllAnchors, framework::DatasetMode::ALL, framework::dataset::make("DataType", { DataType::F32 }),
+ data_type)
+{
+ const int values_per_roi = 4;
+ const int num_anchors = 3;
+ const int feature_height = 4;
+ const int feature_width = 3;
+
+ SimpleTensor<float> anchors_expected(TensorShape(values_per_roi, feature_width * feature_height * num_anchors), DataType::F32);
+ fill_tensor(anchors_expected, std::vector<float> { -26, -19, 87, 86,
+ -81, -27, 58, 63,
+ -44, -15, 55, 36,
+ -10, -19, 103, 86,
+ -65, -27, 74, 63,
+ -28, -15, 71, 36,
+ 6, -19, 119, 86,
+ -49, -27, 90, 63,
+ -12, -15, 87, 36,
+ -26, -3, 87, 102,
+ -81, -11, 58, 79,
+ -44, 1, 55, 52,
+ -10, -3, 103, 102,
+ -65, -11, 74, 79,
+ -28, 1, 71, 52,
+ 6, -3, 119, 102,
+ -49, -11, 90, 79,
+ -12, 1, 87, 52,
+ -26, 13, 87, 118,
+ -81, 5, 58, 95,
+ -44, 17, 55, 68,
+ -10, 13, 103, 118,
+ -65, 5, 74, 95,
+ -28, 17, 71, 68,
+ 6, 13, 119, 118,
+ -49, 5, 90, 95,
+ -12, 17, 87, 68,
+ -26, 29, 87, 134,
+ -81, 21, 58, 111,
+ -44, 33, 55, 84,
+ -10, 29, 103, 134,
+ -65, 21, 74, 111,
+ -28, 33, 71, 84,
+ 6, 29, 119, 134,
+ -49, 21, 90, 111,
+ -12, 33, 87, 84
+ });
+
+ Tensor all_anchors;
+ Tensor anchors = create_tensor<Tensor>(TensorShape(4, num_anchors), data_type);
+
+ // Create and configure function
+ NEComputeAllAnchors compute_anchors;
+ compute_anchors.configure(&anchors, &all_anchors, ComputeAnchorsInfo(feature_width, feature_height, 1. / 16.0));
+ anchors.allocator()->allocate();
+ all_anchors.allocator()->allocate();
+
+ fill_tensor(Accessor(anchors), std::vector<float> { -26, -19, 87, 86,
+ -81, -27, 58, 63,
+ -44, -15, 55, 36
+ });
+ // Compute function
+ compute_anchors.run();
+ validate(Accessor(all_anchors), anchors_expected);
+}
+
+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;
+ const int feature_height = 4;
+ const int feature_width = 5;
+
+ std::vector<float> scores_vector
+ {
+ 5.055894435664012e-04f, 1.270304909820112e-03f, 2.492271113912067e-03f, 5.951663827809190e-03f,
+ 7.846917156877404e-03f, 6.776275276294789e-03f, 6.761571012891965e-03f, 4.898292096237725e-03f,
+ 6.044472332578605e-04f, 3.203334118759474e-03f, 2.947527908919908e-03f, 6.313238560015770e-03f,
+ 7.931767757095738e-03f, 8.764345805102866e-03f, 7.325012199914913e-03f, 4.317069470446271e-03f,
+ 2.372537409795522e-03f, 1.589227460352735e-03f, 7.419477503600818e-03f, 3.157690354133824e-05f,
+ 1.125915135986472e-03f, 9.865363483872330e-03f, 2.429454743386769e-03f, 2.724460564167563e-03f,
+ 7.670409838207963e-03f, 5.558891552328172e-03f, 7.876904873099614e-03f, 6.824746047239291e-03f,
+ 7.023817548067892e-03f, 3.651314909238673e-04f, 6.720443709032501e-03f, 5.935615511606155e-03f,
+ 2.837349642759774e-03f, 1.787235113610299e-03f, 4.538568889918262e-03f, 3.391510678188818e-03f,
+ 7.328474239481874e-03f, 6.306967923936016e-03f, 8.102218904895860e-04f, 3.366646521610209e-03f
+ };
+
+ std::vector<float> bbx_vector
+ {
+ 5.066650471856862e-03, -7.638671742936328e-03, 2.549596503988635e-03, -8.316416756423296e-03,
+ -2.397471917924575e-04, 7.370595187754891e-03, -2.771880178185262e-03, 3.958364873973579e-03,
+ 4.493661094712284e-03, 2.016487051533088e-03, -5.893883038142033e-03, 7.570636080807809e-03,
+ -1.395511229386785e-03, 3.686686052704696e-03, -7.738166245767079e-03, -1.947306329828059e-03,
+ -9.299719716045681e-03, -3.476410493413708e-03, -2.390761190919604e-03, 4.359281254364210e-03,
+ -2.135251160164030e-04, 9.203299843371962e-03, 4.042322775006053e-03, -9.464271243910754e-03,
+ 2.566239543229305e-03, -9.691093900220627e-03, -4.019283034310979e-03, 8.145470429508792e-03,
+ 7.345087308315662e-04, 7.049642787384043e-03, -2.768492313674294e-03, 6.997160053405803e-03,
+ 6.675346697112969e-03, 2.353293365652274e-03, -3.612002585241749e-04, 1.592076522068768e-03,
+ -8.354188900818149e-04, -5.232515333564140e-04, 6.946683728847089e-03, -8.469757407935994e-03,
+ -8.985324496496555e-03, 4.885832859017961e-03, -7.662967577576512e-03, 7.284124004335807e-03,
+ -5.812167510299458e-03, -5.760336800482398e-03, 6.040416930336549e-03, 5.861508595443691e-03,
+ -5.509243096133549e-04, -2.006142470055888e-03, -7.205925340416066e-03, -1.117459082969758e-03,
+ 4.233247017623154e-03, 8.079257498201178e-03, 2.962639022639513e-03, 7.069474943472751e-03,
+ -8.562946284971293e-03, -8.228634642768271e-03, -6.116245322799971e-04, -7.213122000180859e-03,
+ 1.693094399433209e-03, -4.287504459132290e-03, 8.740365683925144e-03, 3.751788160720638e-03,
+ 7.006764222862830e-03, 9.676754678358187e-03, -6.458757235812945e-03, -4.486506575589758e-03,
+ -4.371087196816259e-03, 3.542166755953152e-03, -2.504808998699504e-03, 5.666601724512010e-03,
+ -3.691862724546129e-03, 3.689809719085287e-03, 9.079930264704458e-03, 6.365127787359476e-03,
+ 2.881681788246101e-06, 9.991866069315165e-03, -1.104757466496565e-03, -2.668455405633477e-03,
+ -1.225748887087659e-03, 6.530536159094015e-03, 3.629468917975644e-03, 1.374426066950348e-03,
+ -2.404098881570632e-03, -4.791365049441602e-03, -2.970654027009094e-03, 7.807553690294366e-03,
+ -1.198321129505323e-03, -3.574885336949881e-03, -5.380848303732298e-03, 9.705151282165116e-03,
+ -1.005217683242201e-03, 9.178094036278405e-03, -5.615977269541644e-03, 5.333533158509859e-03,
+ -2.817116206168516e-03, 6.672609782000503e-03, 6.575769501651313e-03, 8.987596634989362e-03,
+ -1.283530791296188e-03, 1.687717120057778e-03, 3.242391851439037e-03, -7.312060454341677e-03,
+ 4.735335326324270e-03, -6.832367028817463e-03, -5.414854835884652e-03, -9.352380213755996e-03,
+ -3.682662043703889e-03, -6.127508590419776e-04, -7.682256596819467e-03, 9.569532628790246e-03,
+ -1.572157284518933e-03, -6.023034366859191e-03, -5.110873282582924e-03, -8.697072236660256e-03,
+ -3.235150419663566e-03, -8.286320236471386e-03, -5.229472409112913e-03, 9.920785896115053e-03,
+ -2.478413362126123e-03, -9.261324796935007e-03, 1.718512310840434e-04, 3.015875488208480e-03,
+ -6.172932549255669e-03, -4.031715551985103e-03, -9.263878005853677e-03, -2.815310738453385e-03,
+ 7.075307462133643e-03, 1.404611747938669e-03, -1.518548732533266e-03, -9.293430941655778e-03,
+ 6.382186966633246e-03, 8.256835789169248e-03, 3.196907843506736e-03, 8.821615689753433e-03,
+ -7.661543424832439e-03, 1.636273081822326e-03, -8.792373335756125e-03, 2.958775812049877e-03,
+ -6.269300278071262e-03, 6.248285790856450e-03, -3.675414624536002e-03, -1.692616700318762e-03,
+ 4.126007647815893e-03, -9.155291689759584e-03, -8.432616039924004e-03, 4.899980636213323e-03,
+ 3.511535019681671e-03, -1.582745757177339e-03, -2.703657774917963e-03, 6.738168990840388e-03,
+ 4.300455303937919e-03, 9.618312854781494e-03, 2.762142918402472e-03, -6.590025003382154e-03,
+ -2.071168373801788e-03, 8.613893943683627e-03, 9.411190295341036e-03, -6.129018930548372e-03
+ };
+
+ const std::vector<float> anchors_vector{ -26, -19, 87, 86, -81, -27, 58, 63 };
+ ;
+
+ SimpleTensor<float> proposals_expected(TensorShape(5, 9), DataType::F32);
+ fill_tensor(proposals_expected, std::vector<float>
+ {
+ 0, 0, 0, 75.269, 64.4388,
+ 0, 21.9579, 13.0535, 119, 99,
+ 0, 38.303, 0, 119, 87.6447,
+ 0, 0, 0, 119, 64.619,
+ 0, 0, 20.7997, 74.0714, 99,
+ 0, 0, 0, 91.8963, 79.3724,
+ 0, 0, 4.42377, 58.1405, 95.1781,
+ 0, 0, 13.4405, 104.799, 99,
+ 0, 38.9066, 28.2434, 119, 99,
+
+ });
+
+ SimpleTensor<float> scores_expected(TensorShape(9), DataType::F32);
+ fill_tensor(scores_expected, std::vector<float>
+ {
+ 0.00986536,
+ 0.00876435,
+ 0.00784692,
+ 0.00767041,
+ 0.00732847,
+ 0.00682475,
+ 0.00672044,
+ 0.00631324,
+ 3.15769e-05
+ });
+
+ 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
+ Tensor scores = create_tensor<Tensor>(scores_shape, data_type, 1, QuantizationInfo(), data_layout);
+ Tensor bbox_deltas = create_tensor<Tensor>(deltas_shape, data_type, 1, QuantizationInfo(), data_layout);
+ Tensor anchors = create_tensor<Tensor>(TensorShape(values_per_roi, num_anchors), data_type);
+
+ // Outputs
+ Tensor proposals;
+ Tensor num_valid_proposals;
+ Tensor scores_out;
+ num_valid_proposals.allocator()->init(TensorInfo(TensorShape(1), 1, DataType::U32));
+
+ NEGenerateProposalsLayer generate_proposals;
+ generate_proposals.configure(&scores, &bbox_deltas, &anchors, &proposals, &scores_out, &num_valid_proposals,
+ GenerateProposalsInfo(120, 100, 0.166667f, 1 / 16.0, 6000, 300, 0.7f, 16.0f));
+
+ // Allocate memory for input/output tensors
+ scores.allocator()->allocate();
+ bbox_deltas.allocator()->allocate();
+ anchors.allocator()->allocate();
+ proposals.allocator()->allocate();
+ num_valid_proposals.allocator()->allocate();
+ scores_out.allocator()->allocate();
+ // Fill inputs
+ fill_tensor(Accessor(scores), scores_vector);
+ fill_tensor(Accessor(bbox_deltas), bbx_vector);
+ fill_tensor(Accessor(anchors), anchors_vector);
+
+ // Run operator
+ generate_proposals.run();
+ // Gather num_valid_proposals
+ const uint32_t N = *reinterpret_cast<uint32_t *>(num_valid_proposals.ptr_to_element(Coordinates(0, 0)));
+
+ // Select the first N entries of the proposals
+ Tensor proposals_final;
+ NESlice select_proposals;
+ select_proposals.configure(&proposals, &proposals_final, Coordinates(0, 0), Coordinates(values_per_roi + 1, N));
+
+ proposals_final.allocator()->allocate();
+ select_proposals.run();
+
+ // Select the first N entries of the proposals
+ Tensor scores_final;
+ NESlice select_scores;
+ select_scores.configure(&scores_out, &scores_final, Coordinates(0), Coordinates(N));
+ scores_final.allocator()->allocate();
+ select_scores.run();
+
+ const RelativeTolerance<float> tolerance_f32(1e-5f);
+ // Validate the output
+ validate(Accessor(proposals_final), proposals_expected, tolerance_f32);
+ validate(Accessor(scores_final), scores_expected, tolerance_f32);
+}
+
+FIXTURE_DATA_TEST_CASE(ComputeAllAnchors, NEComputeAllAnchorsFixture<float>, framework::DatasetMode::ALL,
+ combine(combine(framework::dataset::make("NumAnchors", { 2, 4, 8 }), ComputeAllInfoDataset), framework::dataset::make("DataType", { DataType::F32 })))
+{
+ // Validate output
+ validate(Accessor(_target), _reference);
+}
+TEST_SUITE_END() // FP32
+#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
+TEST_SUITE(FP16)
+FIXTURE_DATA_TEST_CASE(ComputeAllAnchors, NEComputeAllAnchorsFixture<half>, framework::DatasetMode::ALL,
+ combine(combine(framework::dataset::make("NumAnchors", { 2, 4, 8 }), ComputeAllInfoDataset), framework::dataset::make("DataType", { DataType::F16 })))
+{
+ // Validate output
+ validate(Accessor(_target), _reference);
+}
+TEST_SUITE_END() // FP16
+#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
+
+TEST_SUITE_END() // Float
+
+TEST_SUITE_END() // GenerateProposals
+TEST_SUITE_END() // NEON
+
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/validation/fixtures/ComputeAllAnchorsFixture.h b/tests/validation/fixtures/ComputeAllAnchorsFixture.h
index bfa43ceafc..6f2db3e623 100644
--- a/tests/validation/fixtures/ComputeAllAnchorsFixture.h
+++ b/tests/validation/fixtures/ComputeAllAnchorsFixture.h
@@ -78,7 +78,7 @@ protected:
ARM_COMPUTE_EXPECT(!all_anchors.info()->is_resizable(), framework::LogLevel::ERRORS);
// Fill tensors
- fill(CLAccessor(anchors));
+ fill(AccessorType(anchors));
// Compute function
compute_all_anchors.run();