aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Bottini <manuel.bottini@arm.com>2019-02-13 16:34:56 +0000
committerGeorgios Pinitas <georgios.pinitas@arm.com>2019-02-18 13:42:17 +0000
commitec5f85f85c0195b16c0e7714d1f89f23c75cf2bc (patch)
treed68ec135bbac7982b8d69eca7de27cee904ce473
parentef382fdb19fb1d453e72166dc8b511858cdf5159 (diff)
downloadComputeLibrary-ec5f85f85c0195b16c0e7714d1f89f23c75cf2bc.tar.gz
COMPMID-1999: Add support for GenerateProposals operator in CL
Change-Id: Ie08a6874347085f96b00f25bdb605eee7d683c25 Signed-off-by: giuros01 <giuseppe.rossini@arm.com> Reviewed-on: https://review.mlplatform.org/719 Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Reviewed-by: Michalis Spyrou <michalis.spyrou@arm.com>
-rw-r--r--arm_compute/core/CL/CLKernels.h1
-rw-r--r--arm_compute/core/CL/kernels/CLGenerateProposalsLayerKernel.h76
-rw-r--r--arm_compute/core/Types.h163
-rw-r--r--arm_compute/graph/GraphBuilder.h13
-rw-r--r--arm_compute/graph/TypePrinter.h3
-rw-r--r--arm_compute/graph/Types.h1
-rw-r--r--arm_compute/graph/backends/FunctionHelpers.h49
-rw-r--r--arm_compute/graph/backends/ValidateHelpers.h27
-rw-r--r--arm_compute/graph/frontend/Layers.h38
-rw-r--r--arm_compute/graph/nodes/GenerateProposalsLayerNode.h60
-rw-r--r--arm_compute/graph/nodes/Nodes.h1
-rw-r--r--arm_compute/graph/nodes/NodesFwd.h1
-rw-r--r--arm_compute/runtime/CL/CLFunctions.h2
-rw-r--r--arm_compute/runtime/CL/functions/CLComputeAllAnchors.h62
-rw-r--r--arm_compute/runtime/CL/functions/CLGenerateProposalsLayer.h148
-rw-r--r--docs/00_introduction.dox3
-rw-r--r--docs/05_functions_list.dox2
-rw-r--r--src/core/CL/CLKernelLibrary.cpp5
-rw-r--r--src/core/CL/cl_kernels/bounding_box_transform.cl4
-rw-r--r--src/core/CL/cl_kernels/generate_proposals.cl88
-rw-r--r--src/core/CL/kernels/CLGenerateProposalsLayerKernel.cpp128
-rw-r--r--src/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.cpp35
-rw-r--r--src/graph/GraphBuilder.cpp16
-rw-r--r--src/graph/backends/CL/CLFunctionsFactory.cpp2
-rw-r--r--src/graph/backends/CL/CLNodeValidator.cpp2
-rw-r--r--src/graph/backends/GLES/GCNodeValidator.cpp2
-rw-r--r--src/graph/backends/NEON/NENodeValidator.cpp2
-rw-r--r--src/graph/nodes/GenerateProposalsLayerNode.cpp102
-rw-r--r--src/runtime/CL/functions/CLComputeAllAnchors.cpp42
-rw-r--r--src/runtime/CL/functions/CLGenerateProposalsLayer.cpp284
-rw-r--r--tests/validation/CL/GenerateProposalsLayer.cpp403
-rw-r--r--tests/validation/fixtures/ComputeAllAnchorsFixture.h107
-rw-r--r--tests/validation/reference/ComputeAllAnchors.cpp79
-rw-r--r--tests/validation/reference/ComputeAllAnchors.h45
-rw-r--r--utils/TypePrinter.h52
35 files changed, 2029 insertions, 19 deletions
diff --git a/arm_compute/core/CL/CLKernels.h b/arm_compute/core/CL/CLKernels.h
index d8b9934313..cc4888c663 100644
--- a/arm_compute/core/CL/CLKernels.h
+++ b/arm_compute/core/CL/CLKernels.h
@@ -89,6 +89,7 @@
#include "arm_compute/core/CL/kernels/CLGaussian3x3Kernel.h"
#include "arm_compute/core/CL/kernels/CLGaussian5x5Kernel.h"
#include "arm_compute/core/CL/kernels/CLGaussianPyramidKernel.h"
+#include "arm_compute/core/CL/kernels/CLGenerateProposalsLayerKernel.h"
#include "arm_compute/core/CL/kernels/CLHOGDescriptorKernel.h"
#include "arm_compute/core/CL/kernels/CLHOGDetectorKernel.h"
#include "arm_compute/core/CL/kernels/CLHarrisCornersKernel.h"
diff --git a/arm_compute/core/CL/kernels/CLGenerateProposalsLayerKernel.h b/arm_compute/core/CL/kernels/CLGenerateProposalsLayerKernel.h
new file mode 100644
index 0000000000..5900d79821
--- /dev/null
+++ b/arm_compute/core/CL/kernels/CLGenerateProposalsLayerKernel.h
@@ -0,0 +1,76 @@
+/*
+ * 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_CLGENERATEPROPOSALSLAYERKERNEL_H__
+#define __ARM_COMPUTE_CLGENERATEPROPOSALSLAYERKERNEL_H__
+
+#include "arm_compute/core/CL/ICLKernel.h"
+namespace arm_compute
+{
+class ICLTensor;
+
+/** Interface for Compute All Anchors kernel */
+class CLComputeAllAnchorsKernel : public ICLKernel
+{
+public:
+ /** Default constructor */
+ CLComputeAllAnchorsKernel();
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLComputeAllAnchorsKernel(const CLComputeAllAnchorsKernel &) = delete;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLComputeAllAnchorsKernel &operator=(const CLComputeAllAnchorsKernel &) = delete;
+ /** Allow instances of this class to be moved */
+ CLComputeAllAnchorsKernel(CLComputeAllAnchorsKernel &&) = default;
+ /** Allow instances of this class to be moved */
+ CLComputeAllAnchorsKernel &operator=(CLComputeAllAnchorsKernel &&) = default;
+ /** Default destructor */
+ ~CLComputeAllAnchorsKernel() = 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 ICLTensor *anchors, ICLTensor *all_anchors, const ComputeAnchorsInfo &info);
+
+ /** Static function to check if given info will lead to a valid configuration of @ref CLComputeAllAnchorsKernel
+ *
+ * @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, cl::CommandQueue &queue) override;
+
+private:
+ const ICLTensor *_anchors;
+ ICLTensor *_all_anchors;
+};
+} // arm_compute
+#endif // __ARM_COMPUTE_CLGENERATEPROSPOSALSLAYERKERNEL_H__
diff --git a/arm_compute/core/Types.h b/arm_compute/core/Types.h
index b0f792e92b..1ce44ee2e8 100644
--- a/arm_compute/core/Types.h
+++ b/arm_compute/core/Types.h
@@ -634,13 +634,17 @@ public:
* @param[in] soft_nms_method (Optional) Soft NMS method
* @param[in] soft_nms_sigma (Optional) Soft NMS sigma value
* @param[in] soft_nms_min_score_thres (Optional) Soft NMS minimum score threshold
+ * @param[in] suppress_size (Optional) Filter out boxes based on their size. Defaults to false
+ * @param[in] min_size (Optional) Smaller boxes than min_size will be filtered out. Defaults to 1
+ * @param[in] im_width (Optional) Boxes whose centers (on the x axis) is beyond im_width will be filtered. Defaults to 1
+ * @param[in] im_height (Optional) Boxes whose centers (on the y axis) is beyond im_height will be filtered. Defaults to 1
*/
BoxNMSLimitInfo(float score_thresh = 0.05f, float nms = 0.3f,
int detections = 100, bool soft_nms_enabled = false,
NMSType soft_nms_method = NMSType::LINEAR,
- float soft_nms_sigma = 0.5f, float soft_nms_min_score_thres = 0.001f)
+ float soft_nms_sigma = 0.5f, float soft_nms_min_score_thres = 0.001f, bool suppress_size = false, float min_size = 1.0f, float im_width = 1.0f, float im_height = 1.0f)
: _score_thresh(score_thresh), _nms(nms), _detections_per_im(detections), _soft_nms_enabled(soft_nms_enabled), _soft_nms_method(soft_nms_method), _soft_nms_sigma(soft_nms_sigma),
- _soft_nms_min_score_thres(soft_nms_min_score_thres)
+ _soft_nms_min_score_thres(soft_nms_min_score_thres), _suppress_size(suppress_size), _min_size(min_size), _im_width(im_width), _im_height(im_height)
{
}
/** Get the score threshold */
@@ -678,6 +682,26 @@ public:
{
return _soft_nms_min_score_thres;
}
+ /** Get if NMS will suppress boxes based on their size/position */
+ bool suppress_size() const
+ {
+ return _suppress_size;
+ }
+ /** Get size suppression threshold */
+ float min_size() const
+ {
+ return _min_size;
+ }
+ /** Get image width (NMS may suppress boxes whose center sits beyond the image width) */
+ float im_width() const
+ {
+ return _im_width;
+ }
+ /** Get image height (NMS may suppress boxes whose center sits beyond the image height) */
+ float im_height() const
+ {
+ return _im_height;
+ }
private:
float _score_thresh;
@@ -687,6 +711,10 @@ private:
NMSType _soft_nms_method;
float _soft_nms_sigma;
float _soft_nms_min_score_thres;
+ bool _suppress_size;
+ float _min_size;
+ float _im_width;
+ float _im_height;
};
/** Padding and stride information class */
@@ -1217,6 +1245,137 @@ private:
unsigned int _sampling_ratio;
};
+/** Generate Proposals Information class */
+class GenerateProposalsInfo
+{
+public:
+ /** Constructor
+ *
+ * @param[in] im_width Width of the original image
+ * @param[in] im_height Height of the original image
+ * @param[in] im_scale Scale applied to the original image
+ * @param[in] spatial_scale (Optional)Scale applied to the feature map. Defaults to 1.0
+ * @param[in] pre_nms_topN (Optional)Number of the best scores to be selected from the transformations. Defaults to 6000.
+ * @param[in] post_nms_topN (Optional)Number of the best scores to be selected from the NMS operation. Defaults to 300.
+ * @param[in] nms_thres (Optional)NMS overlap threshold. Defaults to 0.7.
+ * @param[in] min_size (Optional)Size used to validate the anchors produced. Defaults to 16.
+ * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region of interest). Defaults to 4.
+ */
+ GenerateProposalsInfo(float im_width, float im_height, float im_scale, float spatial_scale = 1.0, int pre_nms_topN = 6000, int post_nms_topN = 300, float nms_thres = 0.7, float min_size = 16.0,
+ size_t values_per_roi = 4)
+ : _im_height(im_height), _im_width(im_width), _im_scale(im_scale), _spatial_scale(spatial_scale), _pre_nms_topN(pre_nms_topN), _post_nms_topN(post_nms_topN), _nms_thres(nms_thres),
+ _min_size(min_size), _values_per_roi(values_per_roi)
+ {
+ }
+
+ /* Get the original height */
+ float im_height() const
+ {
+ return _im_height;
+ }
+ /* Get the original width */
+ float im_width() const
+ {
+ return _im_width;
+ }
+ /* Get the image scale */
+ float im_scale() const
+ {
+ return _im_scale;
+ }
+ /* Get the value of how many best scores to select (before NMS) */
+ int pre_nms_topN() const
+ {
+ return _pre_nms_topN;
+ }
+ /* Get the value of how many best scores to select (after NMS) */
+ int post_nms_topN() const
+ {
+ return _post_nms_topN;
+ }
+ /* Get the NMS overlap threshold */
+ float nms_thres() const
+ {
+ return _nms_thres;
+ }
+ /* Get the minimal size */
+ float min_size() const
+ {
+ return _min_size;
+ }
+ /* Get the spatial scale to be applied to the feature maps */
+ float spatial_scale() const
+ {
+ return _spatial_scale;
+ }
+ /* Get the values used to represent a ROI(Region of interest)*/
+ size_t values_per_roi() const
+ {
+ return _values_per_roi;
+ }
+
+private:
+ float _im_height;
+ float _im_width;
+ float _im_scale;
+ float _spatial_scale;
+ int _pre_nms_topN;
+ int _post_nms_topN;
+ float _nms_thres;
+ float _min_size;
+ size_t _values_per_roi;
+};
+
+/** ComputeAnchors information class */
+class ComputeAnchorsInfo
+{
+public:
+ /** Constructor
+ *
+ * @param[in] feat_width Feature map width
+ * @param[in] feat_height Feature map height
+ * @param[in] spatial_scale Feature map scale
+ * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region Of Interest). Defaults to 4
+ */
+ ComputeAnchorsInfo(float feat_width, float feat_height, float spatial_scale, size_t values_per_roi = 4)
+ : _feat_height(feat_height),
+ _feat_width(feat_width),
+ _spatial_scale(spatial_scale),
+ _values_per_roi(values_per_roi)
+ {
+ }
+
+ /* Get the height of the feature map */
+ float feat_height() const
+ {
+ return _feat_height;
+ }
+
+ /* Get the width of the feature map */
+ float feat_width() const
+ {
+ return _feat_width;
+ }
+
+ /* Get the scale of the feature map */
+ float spatial_scale() const
+ {
+ return _spatial_scale;
+ }
+
+ /* Get the values used to represent a ROI(Region Of Interest)*/
+ size_t values_per_roi() const
+ {
+ return _values_per_roi;
+ }
+
+private:
+ float _feat_height;
+ float _feat_width;
+ float _spatial_scale;
+ size_t _values_per_roi;
+};
+
/** Bounding Box Transform information class */
class BoundingBoxTransformInfo final
{
diff --git a/arm_compute/graph/GraphBuilder.h b/arm_compute/graph/GraphBuilder.h
index cf213e4e51..1296f56482 100644
--- a/arm_compute/graph/GraphBuilder.h
+++ b/arm_compute/graph/GraphBuilder.h
@@ -253,6 +253,19 @@ public:
const FullyConnectedLayerInfo fc_info = FullyConnectedLayerInfo(),
const QuantizationInfo weights_quant_info = QuantizationInfo(),
const QuantizationInfo out_quant_info = QuantizationInfo());
+ /** Adds a generate proposals layer node to the graph
+ *
+ * @param[in] g Graph to add the layer to
+ * @param[in] params Common node parameters
+ * @param[in] scores Input scores to the generate proposals layer node as a NodeID-Index pair
+ * @param[in] deltas Input deltas to the generate proposals layer node as a NodeID-Index pair
+ * @param[in] anchors Input anchors to the generate proposals layer node as a NodeID-Index pair
+ * @param[in] info Generate proposals operation information
+ *
+ * @return Node ID of the created node, EmptyNodeID in case of error
+ */
+ static NodeID add_generate_proposals_node(Graph &g, NodeParams params, NodeIdxPair scores, NodeIdxPair deltas,
+ NodeIdxPair anchors, GenerateProposalsInfo info);
/** Adds a normalization layer node to the graph
*
* @param[in] g Graph to add the node to
diff --git a/arm_compute/graph/TypePrinter.h b/arm_compute/graph/TypePrinter.h
index faa7f31911..ca62d4ec17 100644
--- a/arm_compute/graph/TypePrinter.h
+++ b/arm_compute/graph/TypePrinter.h
@@ -98,6 +98,9 @@ inline ::std::ostream &operator<<(::std::ostream &os, const NodeType &node_type)
case NodeType::FullyConnectedLayer:
os << "FullyConnectedLayer";
break;
+ case NodeType::GenerateProposalsLayer:
+ os << "GenerateProposalsLayer";
+ break;
case NodeType::NormalizationLayer:
os << "NormalizationLayer";
break;
diff --git a/arm_compute/graph/Types.h b/arm_compute/graph/Types.h
index ee136e2a1e..8377253338 100644
--- a/arm_compute/graph/Types.h
+++ b/arm_compute/graph/Types.h
@@ -138,6 +138,7 @@ enum class NodeType
EltwiseLayer,
FlattenLayer,
FullyConnectedLayer,
+ GenerateProposalsLayer,
NormalizationLayer,
NormalizePlanarYUVLayer,
PadLayer,
diff --git a/arm_compute/graph/backends/FunctionHelpers.h b/arm_compute/graph/backends/FunctionHelpers.h
index 548afd27c5..7242bc6ede 100644
--- a/arm_compute/graph/backends/FunctionHelpers.h
+++ b/arm_compute/graph/backends/FunctionHelpers.h
@@ -688,6 +688,55 @@ std::unique_ptr<IFunction> create_fully_connected_layer(FullyConnectedLayerNode
return std::move(func);
}
+/** Create a backend generate proposals layer function
+ *
+ * @tparam GenerateProposalsLayerFunction Backend generate proposals function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ * @param[in] ctx Graph context
+ *
+ * @return Backend generate proposals layer function
+ */
+template <typename GenerateProposalsLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_generate_proposals_layer(GenerateProposalsLayerNode &node, GraphContext &ctx)
+{
+ validate_node<TargetInfo>(node, 3 /* expected inputs */, 3 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *scores = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *deltas = get_backing_tensor<TargetInfo>(node.input(1));
+ typename TargetInfo::TensorType *anchors = get_backing_tensor<TargetInfo>(node.input(2));
+ typename TargetInfo::TensorType *proposals = get_backing_tensor<TargetInfo>(node.output(0));
+ typename TargetInfo::TensorType *scores_out = get_backing_tensor<TargetInfo>(node.output(1));
+ typename TargetInfo::TensorType *num_valid_proposals = get_backing_tensor<TargetInfo>(node.output(2));
+ const GenerateProposalsInfo info = node.info();
+
+ ARM_COMPUTE_ERROR_ON(scores == nullptr);
+ ARM_COMPUTE_ERROR_ON(deltas == nullptr);
+ ARM_COMPUTE_ERROR_ON(anchors == nullptr);
+ ARM_COMPUTE_ERROR_ON(proposals == nullptr);
+ ARM_COMPUTE_ERROR_ON(scores_out == nullptr);
+
+ // Create and configure function
+ auto func = support::cpp14::make_unique<GenerateProposalsLayerFunction>(get_memory_manager(ctx, TargetInfo::TargetType));
+ func->configure(scores, deltas, anchors, proposals, scores_out, num_valid_proposals, info);
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << scores->info()->data_type()
+ << " Scores shape: " << scores->info()->tensor_shape()
+ << " Deltas shape: " << deltas->info()->tensor_shape()
+ << " Anchors shape: " << anchors->info()->tensor_shape()
+ << " Proposals shape: " << proposals->info()->tensor_shape()
+ << " Num valid proposals shape: " << num_valid_proposals->info()->tensor_shape()
+ << " Scores Out shape: " << scores_out->info()->tensor_shape()
+ << std::endl);
+
+ return std::move(func);
+}
+
/** Create a backend normalization layer function
*
* @tparam NormalizationLayerFunction Backend normalization function
diff --git a/arm_compute/graph/backends/ValidateHelpers.h b/arm_compute/graph/backends/ValidateHelpers.h
index 1b06f31bed..8942be2da8 100644
--- a/arm_compute/graph/backends/ValidateHelpers.h
+++ b/arm_compute/graph/backends/ValidateHelpers.h
@@ -228,6 +228,33 @@ Status validate_detection_output_layer(DetectionOutputLayerNode &node)
return DetectionOutputLayer::validate(input0, input1, input2, output, detect_info);
}
+/** Validates a Generate Proposals layer node
+ *
+ * @tparam GenerateProposalsLayer Generate Proposals layer type
+ *
+ * @param[in] node Node to validate
+ *
+ * @return Status
+ */
+template <typename GenerateProposalsLayer>
+Status validate_generate_proposals_layer(GenerateProposalsLayerNode &node)
+{
+ ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating GenerateProposalsLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
+ ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
+ ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 3);
+
+ // Extract IO and info
+ arm_compute::ITensorInfo *scores = detail::get_backing_tensor_info(node.input(0));
+ arm_compute::ITensorInfo *deltas = detail::get_backing_tensor_info(node.input(1));
+ arm_compute::ITensorInfo *anchors = detail::get_backing_tensor_info(node.input(2));
+ arm_compute::ITensorInfo *proposals = get_backing_tensor_info(node.output(0));
+ arm_compute::ITensorInfo *scores_out = get_backing_tensor_info(node.output(1));
+ arm_compute::ITensorInfo *num_valid_proposals = get_backing_tensor_info(node.output(2));
+ const GenerateProposalsInfo info = node.info();
+
+ return GenerateProposalsLayer::validate(scores, deltas, anchors, proposals, scores_out, num_valid_proposals, info);
+}
+
/** Validates a NormalizePlanarYUV layer node
*
* @tparam NormalizePlanarYUVLayer layer type
diff --git a/arm_compute/graph/frontend/Layers.h b/arm_compute/graph/frontend/Layers.h
index d10fa7f27a..1a71c89e54 100644
--- a/arm_compute/graph/frontend/Layers.h
+++ b/arm_compute/graph/frontend/Layers.h
@@ -608,6 +608,44 @@ private:
const QuantizationInfo _out_quant_info;
};
+/** Generate Proposals Layer */
+class GenerateProposalsLayer final : public ILayer
+{
+public:
+ /** Construct a generate proposals layer.
+ *
+ * @param[in] ss_scores Graph sub-stream for the scores.
+ * @param[in] ss_deltas Graph sub-stream for the deltas.
+ * @param[in] ss_anchors Graph sub-stream for the anchors.
+ * @param[in] info Generate Proposals operation information.
+ */
+ GenerateProposalsLayer(SubStream &&ss_scores, SubStream &&ss_deltas, SubStream &&ss_anchors, GenerateProposalsInfo info)
+ : _ss_scores(std::move(ss_scores)), _ss_deltas(std::move(ss_deltas)), _ss_anchors(std::move(ss_anchors)), _info(info)
+ {
+ }
+
+ /** Create layer and add to the given stream.
+ *
+ * @param[in] s Stream to add layer to.
+ *
+ * @return ID of the created node.
+ */
+ NodeID create_layer(IStream &s) override
+ {
+ NodeParams common_params = { name(), s.hints().target_hint };
+ NodeIdxPair scores = { _ss_scores.tail_node(), 0 };
+ NodeIdxPair deltas = { _ss_deltas.tail_node(), 0 };
+ NodeIdxPair anchors = { _ss_anchors.tail_node(), 0 };
+ return GraphBuilder::add_generate_proposals_node(s.graph(), common_params, scores, deltas, anchors, _info);
+ }
+
+private:
+ SubStream _ss_scores;
+ SubStream _ss_deltas;
+ SubStream _ss_anchors;
+ GenerateProposalsInfo _info;
+};
+
/** Normalization Layer */
class NormalizationLayer final : public ILayer
{
diff --git a/arm_compute/graph/nodes/GenerateProposalsLayerNode.h b/arm_compute/graph/nodes/GenerateProposalsLayerNode.h
new file mode 100644
index 0000000000..d8c0c78f22
--- /dev/null
+++ b/arm_compute/graph/nodes/GenerateProposalsLayerNode.h
@@ -0,0 +1,60 @@
+/*
+ * 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_GENERATE_PROPOSALS_NODE_H__
+#define __ARM_COMPUTE_GENERATE_PROPOSALS_NODE_H__
+
+#include "arm_compute/graph/INode.h"
+
+namespace arm_compute
+{
+namespace graph
+{
+/** Generate Proposals Layer node */
+class GenerateProposalsLayerNode final : public INode
+{
+public:
+ /** Constructor
+ *
+ * @param[in] info Generate proposals operation information.
+ */
+ GenerateProposalsLayerNode(GenerateProposalsInfo &info);
+ /** GenerateProposalsInfo accessor
+ *
+ * @return GenerateProposalsInfo
+ */
+ const GenerateProposalsInfo &info() const;
+
+ // Inherited overridden methods:
+ NodeType type() const override;
+ bool forward_descriptors() override;
+ TensorDescriptor configure_output(size_t idx) const override;
+ void accept(INodeVisitor &v) override;
+
+private:
+ GenerateProposalsInfo _info;
+};
+} // namespace graph
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GENERATE_PROPOSALS_NODE_H__ */
diff --git a/arm_compute/graph/nodes/Nodes.h b/arm_compute/graph/nodes/Nodes.h
index 79ae5d4ae7..24064855e8 100644
--- a/arm_compute/graph/nodes/Nodes.h
+++ b/arm_compute/graph/nodes/Nodes.h
@@ -38,6 +38,7 @@
#include "arm_compute/graph/nodes/EltwiseLayerNode.h"
#include "arm_compute/graph/nodes/FlattenLayerNode.h"
#include "arm_compute/graph/nodes/FullyConnectedLayerNode.h"
+#include "arm_compute/graph/nodes/GenerateProposalsLayerNode.h"
#include "arm_compute/graph/nodes/InputNode.h"
#include "arm_compute/graph/nodes/NormalizationLayerNode.h"
#include "arm_compute/graph/nodes/NormalizePlanarYUVLayerNode.h"
diff --git a/arm_compute/graph/nodes/NodesFwd.h b/arm_compute/graph/nodes/NodesFwd.h
index 6a0be1bf59..cbda3092fd 100644
--- a/arm_compute/graph/nodes/NodesFwd.h
+++ b/arm_compute/graph/nodes/NodesFwd.h
@@ -44,6 +44,7 @@ class DummyNode;
class EltwiseLayerNode;
class FlattenLayerNode;
class FullyConnectedLayerNode;
+class GenerateProposalsLayerNode;
class InputNode;
class NormalizationLayerNode;
class NormalizePlanarYUVLayerNode;
diff --git a/arm_compute/runtime/CL/CLFunctions.h b/arm_compute/runtime/CL/CLFunctions.h
index 504443e806..686d266557 100644
--- a/arm_compute/runtime/CL/CLFunctions.h
+++ b/arm_compute/runtime/CL/CLFunctions.h
@@ -44,6 +44,7 @@
#include "arm_compute/runtime/CL/functions/CLChannelShuffleLayer.h"
#include "arm_compute/runtime/CL/functions/CLColorConvert.h"
#include "arm_compute/runtime/CL/functions/CLComparison.h"
+#include "arm_compute/runtime/CL/functions/CLComputeAllAnchors.h"
#include "arm_compute/runtime/CL/functions/CLConcatenateLayer.h"
#include "arm_compute/runtime/CL/functions/CLConvertFullyConnectedWeights.h"
#include "arm_compute/runtime/CL/functions/CLConvolution.h"
@@ -79,6 +80,7 @@
#include "arm_compute/runtime/CL/functions/CLGaussian3x3.h"
#include "arm_compute/runtime/CL/functions/CLGaussian5x5.h"
#include "arm_compute/runtime/CL/functions/CLGaussianPyramid.h"
+#include "arm_compute/runtime/CL/functions/CLGenerateProposalsLayer.h"
#include "arm_compute/runtime/CL/functions/CLHOGDescriptor.h"
#include "arm_compute/runtime/CL/functions/CLHOGDetector.h"
#include "arm_compute/runtime/CL/functions/CLHOGGradient.h"
diff --git a/arm_compute/runtime/CL/functions/CLComputeAllAnchors.h b/arm_compute/runtime/CL/functions/CLComputeAllAnchors.h
new file mode 100644
index 0000000000..39d9b553b8
--- /dev/null
+++ b/arm_compute/runtime/CL/functions/CLComputeAllAnchors.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_CLCOMPUTEALLANCHORS_H__
+#define __ARM_COMPUTE_CLCOMPUTEALLANCHORS_H__
+
+#include "arm_compute/core/CL/kernels/CLGenerateProposalsLayerKernel.h"
+#include "arm_compute/runtime/CL/ICLSimpleFunction.h"
+
+namespace arm_compute
+{
+class ICLTensor;
+
+/** Basic function to run @ref CLComputeAllAnchorsKernel.
+ *
+ * This function calls the following OpenCL kernels:
+ * -# @ref CLComputeAllAnchorsKernel
+ */
+class CLComputeAllAnchors : public ICLSimpleFunction
+{
+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 ICLTensor *anchors, ICLTensor *all_anchors, const ComputeAnchorsInfo &info);
+
+ /** Static function to check if given info will lead to a valid configuration of @ref CLComputeAllAnchorsKernel
+ *
+ * @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_CLCOMPUTEALLANCOHORS_H__ */
diff --git a/arm_compute/runtime/CL/functions/CLGenerateProposalsLayer.h b/arm_compute/runtime/CL/functions/CLGenerateProposalsLayer.h
new file mode 100644
index 0000000000..26da0bfd7e
--- /dev/null
+++ b/arm_compute/runtime/CL/functions/CLGenerateProposalsLayer.h
@@ -0,0 +1,148 @@
+/*
+ * 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_CLGENERATEPROPOSALSLAYER_H__
+#define __ARM_COMPUTE_CLGENERATEPROPOSALSLAYER_H__
+#include "arm_compute/core/CL/kernels/CLBoundingBoxTransformKernel.h"
+#include "arm_compute/core/CL/kernels/CLCopyKernel.h"
+#include "arm_compute/core/CL/kernels/CLGenerateProposalsLayerKernel.h"
+#include "arm_compute/core/CL/kernels/CLMemsetKernel.h"
+#include "arm_compute/core/CL/kernels/CLPermuteKernel.h"
+#include "arm_compute/core/CL/kernels/CLReshapeLayerKernel.h"
+#include "arm_compute/core/CL/kernels/CLStridedSliceKernel.h"
+#include "arm_compute/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.h"
+#include "arm_compute/core/Types.h"
+#include "arm_compute/runtime/CL/CLMemoryGroup.h"
+#include "arm_compute/runtime/CL/CLScheduler.h"
+#include "arm_compute/runtime/CL/CLTensor.h"
+#include "arm_compute/runtime/CPP/CPPScheduler.h"
+#include "arm_compute/runtime/IFunction.h"
+
+namespace arm_compute
+{
+class ICLTensor;
+
+/** Basic function to generate proposals for a RPN (Region Proposal Network)
+ *
+ * This function calls the following OpenCL kernels:
+ * -# @ref CLComputeAllAnchors
+ * -# @ref CLPermute x 2
+ * -# @ref CLReshapeLayer x 2
+ * -# @ref CLStridedSlice x 3
+ * -# @ref CLBoundingBoxTransform
+ * -# @ref CLCopyKernel
+ * -# @ref CLMemsetKernel
+ * And the following CPP kernels:
+ * -# @ref CPPBoxWithNonMaximaSuppressionLimit
+ */
+class CLGenerateProposalsLayer : public IFunction
+{
+public:
+ /** Default constructor
+ *
+ * @param[in] memory_manager (Optional) Memory manager.
+ */
+ CLGenerateProposalsLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLGenerateProposalsLayer(const CLGenerateProposalsLayer &) = delete;
+ /** Default move constructor */
+ CLGenerateProposalsLayer(CLGenerateProposalsLayer &&) = default;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ CLGenerateProposalsLayer &operator=(const CLGenerateProposalsLayer &) = delete;
+ /** Default move assignment operator */
+ CLGenerateProposalsLayer &operator=(CLGenerateProposalsLayer &&) = 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 ICLTensor *scores, const ICLTensor *deltas, const ICLTensor *anchors, ICLTensor *proposals, ICLTensor *scores_out, ICLTensor *num_valid_proposals,
+ const GenerateProposalsInfo &info);
+
+ /** Static function to check if given info will lead to a valid configuration of @ref CLGenerateProposalsLayer
+ *
+ * @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
+ CLMemoryGroup _memory_group;
+
+ // OpenCL kernels
+ CLPermuteKernel _permute_deltas_kernel;
+ CLReshapeLayerKernel _flatten_deltas_kernel;
+ CLPermuteKernel _permute_scores_kernel;
+ CLReshapeLayerKernel _flatten_scores_kernel;
+ CLComputeAllAnchorsKernel _compute_anchors_kernel;
+ CLBoundingBoxTransformKernel _bounding_box_kernel;
+ CLMemsetKernel _memset_kernel;
+ CLCopyKernel _padded_copy_kernel;
+
+ // CPP kernels
+ CPPBoxWithNonMaximaSuppressionLimitKernel _cpp_nms_kernel;
+
+ bool _is_nhwc;
+
+ // Temporary tensors
+ CLTensor _deltas_permuted;
+ CLTensor _deltas_flattened;
+ CLTensor _scores_permuted;
+ CLTensor _scores_flattened;
+ CLTensor _all_anchors;
+ CLTensor _all_proposals;
+ CLTensor _keeps_nms_unused;
+ CLTensor _classes_nms_unused;
+ CLTensor _proposals_4_roi_values;
+
+ // Output tensor pointers
+ ICLTensor *_num_valid_proposals;
+ ICLTensor *_scores_out;
+
+ /** Internal function to run the CPP BoxWithNMS kernel */
+ void run_cpp_nms_kernel();
+};
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_CLGENERATEPROPOSALSLAYER_H__ */
diff --git a/docs/00_introduction.dox b/docs/00_introduction.dox
index 75a8bf9ab4..f6eae146d6 100644
--- a/docs/00_introduction.dox
+++ b/docs/00_introduction.dox
@@ -313,6 +313,7 @@ v19.02 Public major release
- @ref NEL2NormalizeLayer for FP32/FP16
- @ref NENormalizationLayer IN_MAP_2D for FP32/FP16
- @ref CLROIAlignLayer
+ - @ref CLGenerateProposalsLayer
- Added QASYMM8 support to the following kernels:
- @ref NEArithmeticAdditionKernel
- @ref NEScale
@@ -333,6 +334,8 @@ v18.11 Public major release
- New OpenCL kernels / functions:
- @ref CLBatchToSpaceLayer / @ref CLBatchToSpaceLayerKernel
- @ref CLBoundingBoxTransform / @ref CLBoundingBoxTransformKernel
+ - @ref CLComputeAllAnchorsKernel
+ - @ref CLGenerateProposalsLayer
- @ref CLNormalizePlanarYUVLayer / @ref CLNormalizePlanarYUVLayerKernel
- @ref CLReorgLayer / @ref CLReorgLayerKernel
- @ref CLSpaceToBatchLayer / @ref CLSpaceToBatchLayerKernel
diff --git a/docs/05_functions_list.dox b/docs/05_functions_list.dox
index 3493e8aeba..e82e47204f 100644
--- a/docs/05_functions_list.dox
+++ b/docs/05_functions_list.dox
@@ -195,6 +195,7 @@ namespace arm_compute
- @ref CLGEMM
- @ref CLGEMMConvolutionLayer
- @ref CLGEMMLowpMatrixMultiplyCore
+ - @ref CLGenerateProposalsLayer
- @ref CLHarrisCorners
- @ref CLHistogram
- @ref CLHOGDescriptor
@@ -250,6 +251,7 @@ namespace arm_compute
- @ref CLColorConvert
- @ref CLComparison
- @ref CLComparisonStatic
+ - @ref CLComputeAllAnchors
- @ref CLConvertFullyConnectedWeights
- @ref CLConvolution3x3
- @ref CLConvolutionRectangle
diff --git a/src/core/CL/CLKernelLibrary.cpp b/src/core/CL/CLKernelLibrary.cpp
index a7d371dabc..4ecb885440 100644
--- a/src/core/CL/CLKernelLibrary.cpp
+++ b/src/core/CL/CLKernelLibrary.cpp
@@ -307,6 +307,7 @@ const std::map<std::string, std::string> CLKernelLibrary::_kernel_program_map =
{ "gemmlowp_output_stage_quantize_down", "gemmlowp.cl" },
{ "gemmlowp_output_stage_quantize_down_fixedpoint", "gemmlowp.cl" },
{ "gemmlowp_output_stage_quantize_down_float", "gemmlowp.cl" },
+ { "generate_proposals_compute_all_anchors", "generate_proposals.cl" },
{ "harris_score_3x3", "harris_corners.cl" },
{ "harris_score_5x5", "harris_corners.cl" },
{ "harris_score_7x7", "harris_corners.cl" },
@@ -706,6 +707,10 @@ const std::map<std::string, std::string> CLKernelLibrary::_program_source_map =
#include "./cl_kernels/gemv.clembed"
},
{
+ "generate_proposals.cl",
+#include "./cl_kernels/generate_proposals.clembed"
+ },
+ {
"harris_corners.cl",
#include "./cl_kernels/harris_corners.clembed"
},
diff --git a/src/core/CL/cl_kernels/bounding_box_transform.cl b/src/core/CL/cl_kernels/bounding_box_transform.cl
index 77db5d9311..e6f470a962 100644
--- a/src/core/CL/cl_kernels/bounding_box_transform.cl
+++ b/src/core/CL/cl_kernels/bounding_box_transform.cl
@@ -28,11 +28,11 @@
/** Perform a padded copy of input tensor to the output tensor. Padding values are defined at compile time
*
* @attention The following variables must be passed at compile time:
- * -# -DDATA_TYPE = Tensor data type. Supported data types: F16/F32
+ * -# -DDATA_TYPE= Tensor data type. Supported data types: F16/F32
* -# -DWEIGHT{X,Y,W,H}= Weights [wx, wy, ww, wh] for the deltas
* -# -DIMG_WIDTH= Original image width
* -# -DIMG_HEIGHT= Original image height
- * -# -DBOX_FIELDS=Number of fields that are used to represent a box in boxes
+ * -# -DBOX_FIELDS= Number of fields that are used to represent a box in boxes
*
* @param[in] boxes_ptr Pointer to the boxes tensor. Supported data types: F16/F32
* @param[in] boxes_stride_x Stride of the boxes tensor in X dimension (in bytes)
diff --git a/src/core/CL/cl_kernels/generate_proposals.cl b/src/core/CL/cl_kernels/generate_proposals.cl
new file mode 100644
index 0000000000..a947dad523
--- /dev/null
+++ b/src/core/CL/cl_kernels/generate_proposals.cl
@@ -0,0 +1,88 @@
+/*
+ * 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 "helpers.h"
+
+/** Generate all the region of interests based on the image size and the anchors passed in. For each element (x,y) of the
+ * grid, it will generate NUM_ANCHORS rois, given by shifting the grid position to match the anchor.
+ *
+ * @attention The following variables must be passed at compile time:
+ * -# -DDATA_TYPE= Tensor data type. Supported data types: F16/F32
+ * -# -DHEIGHT= Height of the feature map on which this kernel is applied
+ * -# -DWIDTH= Width of the feature map on which this kernel is applied
+ * -# -DNUM_ANCHORS= Number of anchors to be used to generate the rois per each pixel
+ * -# -DSTRIDE= Stride to be applied at each different pixel position (i.e., x_range = (1:WIDTH)*STRIDE and y_range = (1:HEIGHT)*STRIDE
+ * -# -DNUM_ROI_FIELDS= Number of fields used to represent a roi
+ *
+ * @param[in] anchors_ptr Pointer to the anchors tensor. Supported data types: F16/F32
+ * @param[in] anchors_stride_x Stride of the anchors tensor in X dimension (in bytes)
+ * @param[in] anchors_step_x anchors_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] anchors_stride_y Stride of the anchors tensor in Y dimension (in bytes)
+ * @param[in] anchors_step_y anchors_stride_y * number of elements along Y processed per workitem(in bytes)
+ * @param[in] anchors_stride_z Stride of the source tensor in Z dimension (in bytes)
+ * @param[in] anchors_step_z anchors_stride_z * number of elements along Z processed per workitem(in bytes)
+ * @param[in] anchors_offset_first_element_in_bytes The offset of the first element in the boxes tensor
+ * @param[out] rois_ptr Pointer to the rois. Supported data types: same as @p in_ptr
+ * @param[out] rois_stride_x Stride of the rois in X dimension (in bytes)
+ * @param[out] rois_step_x pred_boxes_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[out] rois_stride_y Stride of the rois in Y dimension (in bytes)
+ * @param[out] rois_step_y pred_boxes_stride_y * number of elements along Y processed per workitem(in bytes)
+ * @param[out] rois_stride_z Stride of the rois in Z dimension (in bytes)
+ * @param[out] rois_step_z pred_boxes_stride_z * number of elements along Z processed per workitem(in bytes)
+ * @param[out] rois_offset_first_element_in_bytes The offset of the first element in the rois
+ */
+#if defined(DATA_TYPE) && defined(WIDTH) && defined(HEIGHT) && defined(NUM_ANCHORS) && defined(STRIDE) && defined(NUM_ROI_FIELDS)
+__kernel void generate_proposals_compute_all_anchors(
+ VECTOR_DECLARATION(anchors),
+ VECTOR_DECLARATION(rois))
+{
+ Vector anchors = CONVERT_TO_VECTOR_STRUCT_NO_STEP(anchors);
+ Vector rois = CONVERT_TO_VECTOR_STRUCT(rois);
+
+ const size_t idx = get_global_id(0);
+ // Find the index of the anchor
+ const size_t anchor_idx = idx % NUM_ANCHORS;
+
+ // Find which shift is this thread using
+ const size_t shift_idx = idx / NUM_ANCHORS;
+
+ // Compute the shift on the X and Y direction (the shift depends exclusively by the index thread id)
+ const DATA_TYPE
+ shift_x = (DATA_TYPE)(shift_idx % WIDTH) * STRIDE;
+ const DATA_TYPE
+ shift_y = (DATA_TYPE)(shift_idx / WIDTH) * STRIDE;
+
+ const VEC_DATA_TYPE(DATA_TYPE, NUM_ROI_FIELDS)
+ shift = (VEC_DATA_TYPE(DATA_TYPE, NUM_ROI_FIELDS))(shift_x, shift_y, shift_x, shift_y);
+
+ // Read the given anchor
+ const VEC_DATA_TYPE(DATA_TYPE, NUM_ROI_FIELDS)
+ anchor = vload4(0, (__global DATA_TYPE *)vector_offset(&anchors, anchor_idx * NUM_ROI_FIELDS));
+
+ // Apply the shift to the anchor
+ const VEC_DATA_TYPE(DATA_TYPE, NUM_ROI_FIELDS)
+ shifted_anchor = anchor + shift;
+
+ vstore4(shifted_anchor, 0, (__global DATA_TYPE *)rois.ptr);
+}
+#endif //defined(DATA_TYPE) && defined(WIDTH) && defined(HEIGHT) && defined(NUM_ANCHORS) && defined(STRIDE) && defined(NUM_ROI_FIELDS)
diff --git a/src/core/CL/kernels/CLGenerateProposalsLayerKernel.cpp b/src/core/CL/kernels/CLGenerateProposalsLayerKernel.cpp
new file mode 100644
index 0000000000..f16422f815
--- /dev/null
+++ b/src/core/CL/kernels/CLGenerateProposalsLayerKernel.cpp
@@ -0,0 +1,128 @@
+/*
+ * 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/CL/kernels/CLGenerateProposalsLayerKernel.h"
+
+#include "arm_compute/core/AccessWindowStatic.h"
+#include "arm_compute/core/CL/CLHelpers.h"
+#include "arm_compute/core/CL/CLKernelLibrary.h"
+#include "arm_compute/core/CL/CLValidate.h"
+#include "arm_compute/core/CL/ICLArray.h"
+#include "arm_compute/core/CL/ICLTensor.h"
+#include "arm_compute/core/CL/OpenCL.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(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)
+ {
+ size_t feature_height = info.feat_height();
+ size_t feature_width = info.feat_width();
+ 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
+
+CLComputeAllAnchorsKernel::CLComputeAllAnchorsKernel()
+ : _anchors(nullptr), _all_anchors(nullptr)
+{
+}
+
+void CLComputeAllAnchorsKernel::configure(const ICLTensor *anchors, ICLTensor *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;
+
+ // Set build options
+ CLBuildOptions build_opts;
+ build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
+ build_opts.add_option("-DWIDTH=" + float_to_string_with_full_precision(width));
+ build_opts.add_option("-DHEIGHT=" + float_to_string_with_full_precision(height));
+ build_opts.add_option("-DSTRIDE=" + float_to_string_with_full_precision(1.f / info.spatial_scale()));
+ build_opts.add_option("-DNUM_ANCHORS=" + support::cpp11::to_string(num_anchors));
+ build_opts.add_option("-DNUM_ROI_FIELDS=" + support::cpp11::to_string(info.values_per_roi()));
+
+ // Create kernel
+ _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("generate_proposals_compute_all_anchors", build_opts.options()));
+
+ // The tensor all_anchors can be interpreted as an array of structs (each structs has values_per_roi fields).
+ // This means we don't need to pad on the X dimension, as we know in advance how many fields
+ // compose the struct.
+ Window win = calculate_max_window(*all_anchors->info(), Steps(info.values_per_roi()));
+ ICLKernel::configure_internal(win);
+}
+
+Status CLComputeAllAnchorsKernel::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 CLComputeAllAnchorsKernel::run(const Window &window, cl::CommandQueue &queue)
+{
+ ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
+ ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
+
+ // Collapse everything on the first dimension
+ Window collapsed = window.collapse(ICLKernel::window(), Window::DimX);
+
+ // Set arguments
+ unsigned int idx = 0;
+ add_1D_tensor_argument(idx, _anchors, collapsed);
+ add_1D_tensor_argument(idx, _all_anchors, collapsed);
+
+ // Note that we don't need to loop over the slices, as we are launching exactly
+ // as many threads as all the anchors generated
+ enqueue(queue, *this, collapsed);
+}
+} // namespace arm_compute
diff --git a/src/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.cpp b/src/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.cpp
index 5e4b80aa5a..02150ff275 100644
--- a/src/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.cpp
+++ b/src/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.cpp
@@ -54,7 +54,7 @@ std::vector<int> SoftNMS(const ITensor *proposals, std::vector<std::vector<T>> &
areas[i] = (x2[i] - x1[i] + 1.0) * (y2[i] - y1[i] + 1.0);
}
- // Note: Soft NMS scores have already been initialize with input scores
+ // Note: Soft NMS scores have already been initialized with input scores
while(!inds.empty())
{
@@ -150,17 +150,21 @@ std::vector<int> NonMaximaSuppression(const ITensor *proposals, std::vector<int>
for(unsigned int j = 0; j < sorted_indices_temp.size(); ++j)
{
- const auto xx1 = std::max(x1[sorted_indices_temp.at(j)], x1[i]);
- const auto yy1 = std::max(y1[sorted_indices_temp.at(j)], y1[i]);
- const auto xx2 = std::min(x2[sorted_indices_temp.at(j)], x2[i]);
- const auto yy2 = std::min(y2[sorted_indices_temp.at(j)], y2[i]);
-
- const auto w = std::max((xx2 - xx1 + 1.f), 0.f);
- const auto h = std::max((yy2 - yy1 + 1.f), 0.f);
- const auto inter = w * h;
- const auto ovr = inter / (areas[i] + areas[sorted_indices_temp.at(j)] - inter);
-
- if(ovr <= info.nms())
+ const float xx1 = std::max(x1[sorted_indices_temp.at(j)], x1[i]);
+ const float yy1 = std::max(y1[sorted_indices_temp.at(j)], y1[i]);
+ const float xx2 = std::min(x2[sorted_indices_temp.at(j)], x2[i]);
+ const float yy2 = std::min(y2[sorted_indices_temp.at(j)], y2[i]);
+
+ const float w = std::max((xx2 - xx1 + 1.f), 0.f);
+ const float h = std::max((yy2 - yy1 + 1.f), 0.f);
+ const float inter = w * h;
+ const float ovr = inter / (areas[i] + areas[sorted_indices_temp.at(j)] - inter);
+ const float ctr_x = xx1 + (w / 2);
+ const float ctr_y = yy1 + (h / 2);
+
+ // If suppress_size is specified, filter the boxes based on their size and position
+ const bool keep_size = !info.suppress_size() || (w >= info.min_size() && h >= info.min_size() && ctr_x < info.im_width() && ctr_y < info.im_height());
+ if(ovr <= info.nms() && keep_size)
{
new_indices.push_back(j);
}
@@ -214,8 +218,9 @@ void CPPBoxWithNonMaximaSuppressionLimitKernel::run_nmslimit()
for(int b = 0; b < batch_size; ++b)
{
const int num_boxes = _batch_splits_in == nullptr ? 1 : static_cast<int>(*reinterpret_cast<T *>(_batch_splits_in->ptr_to_element(Coordinates(b))));
- // Skip first class
- for(int j = 1; j < num_classes; ++j)
+ // Skip first class if there is more than 1 except if the number of classes is 1.
+ const int j_start = (num_classes == 1 ? 0 : 1);
+ for(int j = j_start; j < num_classes; ++j)
{
std::vector<T> cur_scores(scores_count);
std::vector<int> inds;
@@ -290,7 +295,7 @@ void CPPBoxWithNonMaximaSuppressionLimitKernel::run_nmslimit()
// Write results
int cur_out_idx = 0;
- for(int j = 1; j < num_classes; ++j)
+ for(int j = j_start; j < num_classes; ++j)
{
auto &cur_keep = keeps[j];
auto cur_out_scores = reinterpret_cast<T *>(_scores_out->ptr_to_element(Coordinates(cur_start_idx + cur_out_idx)));
diff --git a/src/graph/GraphBuilder.cpp b/src/graph/GraphBuilder.cpp
index cac1a37099..a944d2c25d 100644
--- a/src/graph/GraphBuilder.cpp
+++ b/src/graph/GraphBuilder.cpp
@@ -448,6 +448,22 @@ NodeID GraphBuilder::add_fully_connected_layer(Graph &g, NodeParams params, Node
return fc_nid;
}
+NodeID GraphBuilder::add_generate_proposals_node(Graph &g, NodeParams params, NodeIdxPair scores, NodeIdxPair deltas, NodeIdxPair anchors, GenerateProposalsInfo info)
+{
+ CHECK_NODEIDX_PAIR(scores, g);
+ CHECK_NODEIDX_PAIR(deltas, g);
+ CHECK_NODEIDX_PAIR(anchors, g);
+
+ NodeID nid = g.add_node<GenerateProposalsLayerNode>(info);
+
+ g.add_connection(scores.node_id, scores.index, nid, 0);
+ g.add_connection(deltas.node_id, deltas.index, nid, 1);
+ g.add_connection(anchors.node_id, anchors.index, nid, 2);
+
+ set_node_params(g, nid, params);
+ return nid;
+}
+
NodeID GraphBuilder::add_normalization_node(Graph &g, NodeParams params, NodeIdxPair input, NormalizationLayerInfo norm_info)
{
return create_simple_single_input_output_node<NormalizationLayerNode>(g, params, input, norm_info);
diff --git a/src/graph/backends/CL/CLFunctionsFactory.cpp b/src/graph/backends/CL/CLFunctionsFactory.cpp
index 88d8e3c6c5..b9e3ddc0a3 100644
--- a/src/graph/backends/CL/CLFunctionsFactory.cpp
+++ b/src/graph/backends/CL/CLFunctionsFactory.cpp
@@ -192,6 +192,8 @@ std::unique_ptr<IFunction> CLFunctionFactory::create(INode *node, GraphContext &
return detail::create_flatten_layer<CLFlattenLayer, CLTargetInfo>(*polymorphic_downcast<FlattenLayerNode *>(node));
case NodeType::FullyConnectedLayer:
return detail::create_fully_connected_layer<CLFullyConnectedLayer, CLTargetInfo>(*polymorphic_downcast<FullyConnectedLayerNode *>(node), ctx);
+ case NodeType::GenerateProposalsLayer:
+ return detail::create_generate_proposals_layer<CLGenerateProposalsLayer, CLTargetInfo>(*polymorphic_downcast<GenerateProposalsLayerNode *>(node), ctx);
case NodeType::NormalizationLayer:
return detail::create_normalization_layer<CLNormalizationLayer, CLTargetInfo>(*polymorphic_downcast<NormalizationLayerNode *>(node), ctx);
case NodeType::NormalizePlanarYUVLayer:
diff --git a/src/graph/backends/CL/CLNodeValidator.cpp b/src/graph/backends/CL/CLNodeValidator.cpp
index ca327c9771..4b71837a49 100644
--- a/src/graph/backends/CL/CLNodeValidator.cpp
+++ b/src/graph/backends/CL/CLNodeValidator.cpp
@@ -62,6 +62,8 @@ Status CLNodeValidator::validate(INode *node)
CLDepthwiseConvolutionLayer3x3>(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
case NodeType::DetectionOutputLayer:
return detail::validate_detection_output_layer<CPPDetectionOutputLayer>(*polymorphic_downcast<DetectionOutputLayerNode *>(node));
+ case NodeType::GenerateProposalsLayer:
+ return detail::validate_generate_proposals_layer<CLGenerateProposalsLayer>(*polymorphic_downcast<GenerateProposalsLayerNode *>(node));
case NodeType::NormalizePlanarYUVLayer:
return detail::validate_normalize_planar_yuv_layer<CLNormalizePlanarYUVLayer>(*polymorphic_downcast<NormalizePlanarYUVLayerNode *>(node));
case NodeType::PadLayer:
diff --git a/src/graph/backends/GLES/GCNodeValidator.cpp b/src/graph/backends/GLES/GCNodeValidator.cpp
index aaa031dbb9..f15ede6e2c 100644
--- a/src/graph/backends/GLES/GCNodeValidator.cpp
+++ b/src/graph/backends/GLES/GCNodeValidator.cpp
@@ -115,6 +115,8 @@ Status GCNodeValidator::validate(INode *node)
return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : DetectionOutputLayer");
case NodeType::FlattenLayer:
return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : FlattenLayer");
+ case NodeType::GenerateProposalsLayer:
+ return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : GenerateProposalsLayer");
case NodeType::NormalizePlanarYUVLayer:
return detail::validate_normalize_planar_yuv_layer<GCNormalizePlanarYUVLayer>(*polymorphic_downcast<NormalizePlanarYUVLayerNode *>(node));
case NodeType::PadLayer:
diff --git a/src/graph/backends/NEON/NENodeValidator.cpp b/src/graph/backends/NEON/NENodeValidator.cpp
index 96236b66c3..b0feec563b 100644
--- a/src/graph/backends/NEON/NENodeValidator.cpp
+++ b/src/graph/backends/NEON/NENodeValidator.cpp
@@ -62,6 +62,8 @@ Status NENodeValidator::validate(INode *node)
NEDepthwiseConvolutionLayer3x3>(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
case NodeType::DetectionOutputLayer:
return detail::validate_detection_output_layer<CPPDetectionOutputLayer>(*polymorphic_downcast<DetectionOutputLayerNode *>(node));
+ case NodeType::GenerateProposalsLayer:
+ return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : GenerateProposalsLayer");
case NodeType::NormalizePlanarYUVLayer:
return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : NormalizePlanarYUVLayer");
case NodeType::PadLayer:
diff --git a/src/graph/nodes/GenerateProposalsLayerNode.cpp b/src/graph/nodes/GenerateProposalsLayerNode.cpp
new file mode 100644
index 0000000000..dabfc5aa10
--- /dev/null
+++ b/src/graph/nodes/GenerateProposalsLayerNode.cpp
@@ -0,0 +1,102 @@
+/*
+ * 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/graph/nodes/GenerateProposalsLayerNode.h"
+
+#include "arm_compute/graph/Graph.h"
+#include "arm_compute/graph/INodeVisitor.h"
+
+#include "arm_compute/core/Helpers.h"
+
+namespace arm_compute
+{
+namespace graph
+{
+GenerateProposalsLayerNode::GenerateProposalsLayerNode(GenerateProposalsInfo &info)
+ : _info(info)
+{
+ _input_edges.resize(3, EmptyEdgeID);
+ _outputs.resize(3, NullTensorID);
+}
+
+const GenerateProposalsInfo &GenerateProposalsLayerNode::info() const
+{
+ return _info;
+}
+
+bool GenerateProposalsLayerNode::forward_descriptors()
+{
+ if((input_id(0) != NullTensorID) && (input_id(1) != NullTensorID) && (input_id(2) != NullTensorID) && (output_id(0) != NullTensorID) && (output_id(1) != NullTensorID)
+ && (output_id(2) != NullTensorID))
+ {
+ for(unsigned int i = 0; i < 3; ++i)
+ {
+ Tensor *dst = output(i);
+ ARM_COMPUTE_ERROR_ON(dst == nullptr);
+ dst->desc() = configure_output(i);
+ }
+ return true;
+ }
+ return false;
+}
+
+TensorDescriptor GenerateProposalsLayerNode::configure_output(size_t idx) const
+{
+ ARM_COMPUTE_ERROR_ON(idx > 3);
+
+ const Tensor *src = input(0);
+ ARM_COMPUTE_ERROR_ON(src == nullptr);
+ TensorDescriptor output_desc = src->desc();
+
+ switch(idx)
+ {
+ case 0:
+ // Configure proposals output
+ output_desc.shape = TensorShape(5, src->desc().shape.total_size());
+ break;
+ case 1:
+ // Configure scores_out output
+ output_desc.shape = TensorShape(src->desc().shape.total_size());
+ break;
+ case 2:
+ // Configure num_valid_proposals
+ output_desc.shape = TensorShape(1);
+ output_desc.data_type = DataType::U32;
+ break;
+ default:
+ ARM_COMPUTE_ERROR("Unsupported output index");
+ }
+ return output_desc;
+}
+
+NodeType GenerateProposalsLayerNode::type() const
+{
+ return NodeType::GenerateProposalsLayer;
+}
+
+void GenerateProposalsLayerNode::accept(INodeVisitor &v)
+{
+ v.visit(*this);
+}
+} // namespace graph
+} // namespace arm_compute
diff --git a/src/runtime/CL/functions/CLComputeAllAnchors.cpp b/src/runtime/CL/functions/CLComputeAllAnchors.cpp
new file mode 100644
index 0000000000..24c152f4d6
--- /dev/null
+++ b/src/runtime/CL/functions/CLComputeAllAnchors.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/CL/functions/CLComputeAllAnchors.h"
+
+#include "support/ToolchainSupport.h"
+
+namespace arm_compute
+{
+void CLComputeAllAnchors::configure(const ICLTensor *anchors, ICLTensor *all_anchors, const ComputeAnchorsInfo &info)
+{
+ // Configure ComputeAllAnchors kernel
+ auto k = arm_compute::support::cpp14::make_unique<CLComputeAllAnchorsKernel>();
+ k->configure(anchors, all_anchors, info);
+ _kernel = std::move(k);
+}
+
+Status CLComputeAllAnchors::validate(const ITensorInfo *anchors, const ITensorInfo *all_anchors, const ComputeAnchorsInfo &info)
+{
+ return CLComputeAllAnchorsKernel::validate(anchors, all_anchors, info);
+}
+} // namespace arm_compute
diff --git a/src/runtime/CL/functions/CLGenerateProposalsLayer.cpp b/src/runtime/CL/functions/CLGenerateProposalsLayer.cpp
new file mode 100644
index 0000000000..c50132ea04
--- /dev/null
+++ b/src/runtime/CL/functions/CLGenerateProposalsLayer.cpp
@@ -0,0 +1,284 @@
+/*
+ * 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/CL/functions/CLGenerateProposalsLayer.h"
+
+#include "arm_compute/core/CL/ICLTensor.h"
+#include "arm_compute/core/Types.h"
+#include "support/ToolchainSupport.h"
+
+namespace arm_compute
+{
+CLGenerateProposalsLayer::CLGenerateProposalsLayer(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 CLGenerateProposalsLayer::configure(const ICLTensor *scores, const ICLTensor *deltas, const ICLTensor *anchors, ICLTensor *proposals, ICLTensor *scores_out, ICLTensor *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(CLGenerateProposalsLayer::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));
+
+ // Permute and reshape deltas
+ if(!_is_nhwc)
+ {
+ _memory_group.manage(&_deltas_permuted);
+ _memory_group.manage(&_deltas_flattened);
+ _permute_deltas_kernel.configure(deltas, &_deltas_permuted, PermutationVector{ 2, 0, 1 });
+ _flatten_deltas_kernel.configure(&_deltas_permuted, &_deltas_flattened);
+ _deltas_permuted.allocator()->allocate();
+ }
+ else
+ {
+ _memory_group.manage(&_deltas_flattened);
+ _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));
+
+ // Permute and reshape scores
+ if(!_is_nhwc)
+ {
+ _memory_group.manage(&_scores_permuted);
+ _memory_group.manage(&_scores_flattened);
+ _permute_scores_kernel.configure(scores, &_scores_permuted, PermutationVector{ 2, 0, 1 });
+ _flatten_scores_kernel.configure(&_scores_permuted, &_scores_flattened);
+ _scores_permuted.allocator()->allocate();
+ }
+ else
+ {
+ _memory_group.manage(&_scores_flattened);
+ _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(1), 1, DataType::U32);
+
+ // Initialize temporaries (unused) outputs
+ _classes_nms_unused.allocator()->init(TensorInfo(TensorShape(1, 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);
+ _cpp_nms_kernel.configure(&_scores_flattened, &_all_proposals, nullptr, scores_out, &_proposals_4_roi_values, &_classes_nms_unused, nullptr, &_keeps_nms_unused, num_valid_proposals,
+ BoxNMSLimitInfo(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()));
+ _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 CLGenerateProposalsLayer::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(CLComputeAllAnchorsKernel::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(CLPermuteKernel::validate(deltas, &deltas_permuted_info, PermutationVector{ 2, 0, 1 }));
+ ARM_COMPUTE_RETURN_ON_ERROR(CLPermuteKernel::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(CLReshapeLayerKernel::validate(&deltas_permuted_info, &deltas_flattened_info));
+
+ TensorInfo scores_flattened_info(deltas->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(CLReshapeLayerKernel::validate(&scores_permuted_info, &scores_flattened_info));
+ ARM_COMPUTE_RETURN_ON_ERROR(CLBoundingBoxTransformKernel::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(CLCopyKernel::validate(&proposals_4_roi_values, proposals, PaddingList{ { 0, 1 } }));
+ ARM_COMPUTE_RETURN_ON_ERROR(CLMemsetKernel::validate(proposals, PixelValue()));
+
+ 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 CLGenerateProposalsLayer::run_cpp_nms_kernel()
+{
+ // Map inputs
+ _scores_flattened.map(true);
+ _all_proposals.map(true);
+
+ // Map outputs
+ _scores_out->map(CLScheduler::get().queue(), true);
+ _proposals_4_roi_values.map(CLScheduler::get().queue(), true);
+ _num_valid_proposals->map(CLScheduler::get().queue(), true);
+ _keeps_nms_unused.map(true);
+ _classes_nms_unused.map(true);
+
+ // Run nms
+ CPPScheduler::get().schedule(&_cpp_nms_kernel, Window::DimX);
+
+ // Unmap outputs
+ _keeps_nms_unused.unmap();
+ _classes_nms_unused.unmap();
+ _scores_out->unmap(CLScheduler::get().queue());
+ _proposals_4_roi_values.unmap(CLScheduler::get().queue());
+ _num_valid_proposals->unmap(CLScheduler::get().queue());
+
+ // Unmap inputs
+ _scores_flattened.unmap();
+ _all_proposals.unmap();
+}
+
+void CLGenerateProposalsLayer::run()
+{
+ // Acquire all the temporaries
+ _memory_group.acquire();
+
+ // Compute all the anchors
+ CLScheduler::get().enqueue(_compute_anchors_kernel, false);
+
+ // Transpose and reshape the inputs
+ if(!_is_nhwc)
+ {
+ CLScheduler::get().enqueue(_permute_deltas_kernel, false);
+ CLScheduler::get().enqueue(_permute_scores_kernel, false);
+ }
+ CLScheduler::get().enqueue(_flatten_deltas_kernel, false);
+ CLScheduler::get().enqueue(_flatten_scores_kernel, false);
+
+ // Build the boxes
+ CLScheduler::get().enqueue(_bounding_box_kernel, false);
+ // Non maxima suppression
+ run_cpp_nms_kernel();
+ // Add dummy batch indexes
+ CLScheduler::get().enqueue(_memset_kernel, true);
+ CLScheduler::get().enqueue(_padded_copy_kernel, true);
+
+ // Release all the temporaries
+ _memory_group.release();
+}
+} // namespace arm_compute
diff --git a/tests/validation/CL/GenerateProposalsLayer.cpp b/tests/validation/CL/GenerateProposalsLayer.cpp
new file mode 100644
index 0000000000..4ebffd7e79
--- /dev/null
+++ b/tests/validation/CL/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/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"
+#include "tests/Globals.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(CLAccessor &&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(CL)
+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(CLGenerateProposalsLayer::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 CLComputeAllAnchorsFixture = ComputeAllAnchorsFixture<CLTensor, CLAccessor, CLComputeAllAnchors, 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
+ });
+
+ CLTensor all_anchors;
+ CLTensor anchors = create_tensor<CLTensor>(TensorShape(4, num_anchors), data_type);
+
+ // Create and configure function
+ CLComputeAllAnchors 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(CLAccessor(anchors), std::vector<float> { -26, -19, 87, 86,
+ -81, -27, 58, 63,
+ -44, -15, 55, 36
+ });
+ // Compute function
+ compute_anchors.run();
+ validate(CLAccessor(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
+ };
+
+ 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
+ CLTensor scores = create_tensor<CLTensor>(scores_shape, data_type, 1, QuantizationInfo(), data_layout);
+ CLTensor bbox_deltas = create_tensor<CLTensor>(deltas_shape, data_type, 1, QuantizationInfo(), data_layout);
+ CLTensor anchors = create_tensor<CLTensor>(TensorShape(values_per_roi, num_anchors), data_type);
+
+ // Outputs
+ CLTensor proposals;
+ CLTensor num_valid_proposals;
+ CLTensor scores_out;
+ num_valid_proposals.allocator()->init(TensorInfo(TensorShape(1), 1, DataType::U32));
+
+ CLGenerateProposalsLayer 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(CLAccessor(scores), scores_vector);
+ fill_tensor(CLAccessor(bbox_deltas), bbx_vector);
+ fill_tensor(CLAccessor(anchors), anchors_vector);
+
+ // Run operator
+ generate_proposals.run();
+ // Gather num_valid_proposals
+ num_valid_proposals.map();
+ const uint32_t N = *reinterpret_cast<uint32_t *>(num_valid_proposals.ptr_to_element(Coordinates(0, 0)));
+ num_valid_proposals.unmap();
+
+ // Select the first N entries of the proposals
+ CLTensor proposals_final;
+ CLSlice 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
+ CLTensor scores_final;
+ CLSlice 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(CLAccessor(proposals_final), proposals_expected, tolerance_f32);
+ validate(CLAccessor(scores_final), scores_expected, tolerance_f32);
+}
+
+FIXTURE_DATA_TEST_CASE(ComputeAllAnchors, CLComputeAllAnchorsFixture<float>, framework::DatasetMode::ALL,
+ combine(combine(framework::dataset::make("NumAnchors", { 2, 4, 8 }), ComputeAllInfoDataset), framework::dataset::make("DataType", { DataType::F32 })))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+TEST_SUITE_END() // FP32
+
+TEST_SUITE(FP16)
+FIXTURE_DATA_TEST_CASE(ComputeAllAnchors, CLComputeAllAnchorsFixture<half>, framework::DatasetMode::ALL,
+ combine(combine(framework::dataset::make("NumAnchors", { 2, 4, 8 }), ComputeAllInfoDataset), framework::dataset::make("DataType", { DataType::F16 })))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+TEST_SUITE_END() // FP16
+TEST_SUITE_END() // Float
+
+TEST_SUITE_END() // GenerateProposals
+TEST_SUITE_END() // CL
+
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/validation/fixtures/ComputeAllAnchorsFixture.h b/tests/validation/fixtures/ComputeAllAnchorsFixture.h
new file mode 100644
index 0000000000..bfa43ceafc
--- /dev/null
+++ b/tests/validation/fixtures/ComputeAllAnchorsFixture.h
@@ -0,0 +1,107 @@
+/*
+ * 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_TEST_COMPUTEALLANCHORS_FIXTURE
+#define ARM_COMPUTE_TEST_COMPUTEALLANCHORS_FIXTURE
+
+#include "arm_compute/core/TensorShape.h"
+#include "arm_compute/core/Types.h"
+#include "tests/AssetsLibrary.h"
+#include "tests/Globals.h"
+#include "tests/IAccessor.h"
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Fixture.h"
+#include "tests/validation/Helpers.h"
+#include "tests/validation/reference/ComputeAllAnchors.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
+class ComputeAllAnchorsFixture : public framework::Fixture
+{
+public:
+ template <typename...>
+ void setup(size_t num_anchors, const ComputeAnchorsInfo &info, DataType data_type)
+ {
+ _target = compute_target(num_anchors, data_type, info);
+ _reference = compute_reference(num_anchors, data_type, info);
+ }
+
+protected:
+ template <typename U>
+ void fill(U &&tensor)
+ {
+ library->fill_tensor_uniform(tensor, 0, T(0), T(100));
+ }
+
+ TensorType compute_target(size_t num_anchors, DataType data_type, const ComputeAnchorsInfo &info)
+ {
+ // Create tensors
+ TensorShape anchors_shape(4, num_anchors);
+ TensorType anchors = create_tensor<TensorType>(anchors_shape, data_type);
+ TensorType all_anchors;
+
+ // Create and configure function
+ FunctionType compute_all_anchors;
+ compute_all_anchors.configure(&anchors, &all_anchors, info);
+
+ ARM_COMPUTE_EXPECT(all_anchors.info()->is_resizable(), framework::LogLevel::ERRORS);
+
+ // Allocate tensors
+ all_anchors.allocator()->allocate();
+ anchors.allocator()->allocate();
+
+ ARM_COMPUTE_EXPECT(!all_anchors.info()->is_resizable(), framework::LogLevel::ERRORS);
+
+ // Fill tensors
+ fill(CLAccessor(anchors));
+
+ // Compute function
+ compute_all_anchors.run();
+
+ return all_anchors;
+ }
+
+ SimpleTensor<T> compute_reference(size_t num_anchors,
+ DataType data_type,
+ const ComputeAnchorsInfo &info)
+ {
+ // Create reference tensor
+ SimpleTensor<T> anchors(TensorShape(4, num_anchors), data_type);
+
+ // Fill reference tensor
+ fill(anchors);
+ return reference::compute_all_anchors(anchors, info);
+ }
+
+ TensorType _target{};
+ SimpleTensor<T> _reference{};
+};
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
+#endif /* ARM_COMPUTE_TEST_COMPUTEALLANCHORS_FIXTURE */
diff --git a/tests/validation/reference/ComputeAllAnchors.cpp b/tests/validation/reference/ComputeAllAnchors.cpp
new file mode 100644
index 0000000000..3f0498015a
--- /dev/null
+++ b/tests/validation/reference/ComputeAllAnchors.cpp
@@ -0,0 +1,79 @@
+/*
+ * 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 "ComputeAllAnchors.h"
+
+#include "arm_compute/core/Types.h"
+#include "arm_compute/core/utils/misc/ShapeCalculator.h"
+#include "arm_compute/core/utils/misc/Utility.h"
+#include "tests/validation/Helpers.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace reference
+{
+template <typename T>
+SimpleTensor<T> compute_all_anchors(const SimpleTensor<T> &anchors, const ComputeAnchorsInfo &info)
+{
+ const int num_anchors = anchors.shape()[1];
+ const auto width = int(info.feat_width());
+ const auto height = int(info.feat_height());
+ const float stride = 1. / info.spatial_scale();
+
+ SimpleTensor<T> all_anchors(TensorShape(4, width * height * num_anchors), anchors.data_type());
+ const T *anchors_ptr = anchors.data();
+ T *all_anchors_ptr = all_anchors.data();
+
+ // Iterate over the input grid and anchors
+ for(int y = 0; y < height; y++)
+ {
+ for(int x = 0; x < width; x++)
+ {
+ for(int a = 0; a < num_anchors; a++)
+ {
+ const T shift_x = T(x) * T(stride);
+ const T shift_y = T(y) * T(stride);
+ const size_t anchor_id = a + x * num_anchors + y * width * num_anchors;
+ // x1
+ all_anchors_ptr[anchor_id * 4] = anchors_ptr[4 * a] + shift_x;
+ // y1
+ all_anchors_ptr[anchor_id * 4 + 1] = anchors_ptr[4 * a + 1] + shift_y;
+ // x2
+ all_anchors_ptr[anchor_id * 4 + 2] = anchors_ptr[4 * a + 2] + shift_x;
+ // y2
+ all_anchors_ptr[anchor_id * 4 + 3] = anchors_ptr[4 * a + 3] + shift_y;
+ }
+ }
+ }
+ return all_anchors;
+}
+template SimpleTensor<float> compute_all_anchors(const SimpleTensor<float> &anchors, const ComputeAnchorsInfo &info);
+template SimpleTensor<half> compute_all_anchors(const SimpleTensor<half> &anchors, const ComputeAnchorsInfo &info);
+} // namespace reference
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/validation/reference/ComputeAllAnchors.h b/tests/validation/reference/ComputeAllAnchors.h
new file mode 100644
index 0000000000..8fa5eabde3
--- /dev/null
+++ b/tests/validation/reference/ComputeAllAnchors.h
@@ -0,0 +1,45 @@
+/*
+ * 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_TEST_COMPUTEALLANCHORS_H__
+#define __ARM_COMPUTE_TEST_COMPUTEALLANCHORS_H__
+
+#include "arm_compute/core/Types.h"
+#include "arm_compute/core/utils/misc/ShapeCalculator.h"
+#include "tests/validation/Helpers.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace reference
+{
+template <typename T>
+SimpleTensor<T> compute_all_anchors(const SimpleTensor<T> &anchors, const ComputeAnchorsInfo &info);
+} // namespace reference
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_TEST_COMPUTEALLANCHORS_H__ */
diff --git a/utils/TypePrinter.h b/utils/TypePrinter.h
index 3361c39ee3..f2cf606a00 100644
--- a/utils/TypePrinter.h
+++ b/utils/TypePrinter.h
@@ -261,6 +261,58 @@ inline std::string to_string(const BoundingBoxTransformInfo &bbox_info)
return str.str();
}
+/** Formatted output of the ComputeAnchorsInfo type.
+ *
+ * @param[out] os Output stream.
+ * @param[in] anchors_info Type to output.
+ *
+ * @return Modified output stream.
+ */
+inline ::std::ostream &operator<<(::std::ostream &os, const ComputeAnchorsInfo &anchors_info)
+{
+ os << "(" << anchors_info.feat_width() << "x" << anchors_info.feat_height() << ")~" << anchors_info.spatial_scale();
+ return os;
+}
+
+/** Formatted output of the ComputeAnchorsInfo type.
+ *
+ * @param[in] anchors_info Type to output.
+ *
+ * @return Formatted string.
+ */
+inline std::string to_string(const ComputeAnchorsInfo &anchors_info)
+{
+ std::stringstream str;
+ str << anchors_info;
+ return str.str();
+}
+
+/** Formatted output of the GenerateProposalsInfo type.
+ *
+ * @param[out] os Output stream.
+ * @param[in] proposals_info Type to output.
+ *
+ * @return Modified output stream.
+ */
+inline ::std::ostream &operator<<(::std::ostream &os, const GenerateProposalsInfo &proposals_info)
+{
+ os << "(" << proposals_info.im_width() << "x" << proposals_info.im_height() << ")~" << proposals_info.im_scale();
+ return os;
+}
+
+/** Formatted output of the GenerateProposalsInfo type.
+ *
+ * @param[in] proposals_info Type to output.
+ *
+ * @return Formatted string.
+ */
+inline std::string to_string(const GenerateProposalsInfo &proposals_info)
+{
+ std::stringstream str;
+ str << proposals_info;
+ return str.str();
+}
+
/** Formatted output of the QuantizationInfo type.
*
* @param[out] os Output stream.