diff options
author | Georgios Pinitas <georgios.pinitas@arm.com> | 2020-02-13 17:59:09 +0000 |
---|---|---|
committer | Michele Di Giorgio <michele.digiorgio@arm.com> | 2020-02-19 21:01:13 +0000 |
commit | 102b0ce919bf5415993cdd6b0e4385b35734d38d (patch) | |
tree | f711c876711e178a04c3684bb15e202ebf4d14ac | |
parent | 51545e4acbb6a613da5ee19110ca8c8d7fd39776 (diff) | |
download | ComputeLibrary-102b0ce919bf5415993cdd6b0e4385b35734d38d.tar.gz |
COMPMID-3105: Update pad layer to PadV2
Adds the ability to set the padding value in the pad layer node.
Change-Id: I2f323146cbdfdfd6cfd617ee4bcafb5ffafedbbb
Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/2727
Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r-- | arm_compute/graph/GraphBuilder.h | 13 | ||||
-rw-r--r-- | arm_compute/graph/Types.h | 2 | ||||
-rw-r--r-- | arm_compute/graph/backends/FunctionHelpers.h | 9 | ||||
-rw-r--r-- | arm_compute/graph/frontend/Layers.h | 12 | ||||
-rw-r--r-- | arm_compute/graph/nodes/PadLayerNode.h | 13 | ||||
-rw-r--r-- | src/graph/GraphBuilder.cpp | 4 | ||||
-rw-r--r-- | src/graph/nodes/PadLayerNode.cpp | 9 |
7 files changed, 40 insertions, 22 deletions
diff --git a/arm_compute/graph/GraphBuilder.h b/arm_compute/graph/GraphBuilder.h index 23541c4a0f..612703cae5 100644 --- a/arm_compute/graph/GraphBuilder.h +++ b/arm_compute/graph/GraphBuilder.h @@ -335,15 +335,16 @@ public: ITensorAccessorUPtr mean_accessor = nullptr, ITensorAccessorUPtr std_accessor = nullptr); /** Adds a pad layer node to the graph * - * @param[in] g Graph to add the node to - * @param[in] params Common node parameters - * @param[in] input Input to the reshape layer node as a NodeID-Index pair - * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] - * specifies the front and the end padding in the i-th dimension. + * @param[in] g Graph to add the node to + * @param[in] params Common node parameters + * @param[in] input Input to the reshape layer node as a NodeID-Index pair + * @param[in] paddings The padding for each spatial dimension of the input tensor. The pair padding[i] + * specifies the front and the end padding in the i-th dimension. + * @param[in] pad_value Padding value to be used. Defaults to 0 * * @return Node ID of the created node, EmptyNodeID in case of error */ - static NodeID add_pad_node(Graph &g, NodeParams params, NodeIdxPair input, PaddingList padding); + static NodeID add_pad_node(Graph &g, NodeParams params, NodeIdxPair input, const PaddingList &paddings, PixelValue pad_value = PixelValue()); /** Adds a permute layer node to the graph * * @param[in] g Graph to add the node to diff --git a/arm_compute/graph/Types.h b/arm_compute/graph/Types.h index 7c81641cbe..296f757c9b 100644 --- a/arm_compute/graph/Types.h +++ b/arm_compute/graph/Types.h @@ -25,6 +25,7 @@ #define ARM_COMPUTE_GRAPH_TYPES_H #include "arm_compute/core/Error.h" +#include "arm_compute/core/PixelValue.h" #include "arm_compute/core/Types.h" #include "arm_compute/runtime/CL/CLTunerTypes.h" @@ -45,6 +46,7 @@ using arm_compute::DataLayoutDimension; using arm_compute::TensorShape; using arm_compute::Size2D; using arm_compute::PermutationVector; +using arm_compute::PixelValue; using arm_compute::ActivationLayerInfo; using arm_compute::DetectionOutputLayerInfo; diff --git a/arm_compute/graph/backends/FunctionHelpers.h b/arm_compute/graph/backends/FunctionHelpers.h index 9f352edb9a..20c69bfffa 100644 --- a/arm_compute/graph/backends/FunctionHelpers.h +++ b/arm_compute/graph/backends/FunctionHelpers.h @@ -1048,15 +1048,16 @@ std::unique_ptr<IFunction> create_pad_layer(PadLayerNode &node) validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); // Extract IO and info - typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); - typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); - const PaddingList &padding = node.padding(); + typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); + typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); + const PaddingList &padding = node.padding(); + const PixelValue pad_value = node.pad_value(); ARM_COMPUTE_ERROR_ON(input == nullptr); ARM_COMPUTE_ERROR_ON(output == nullptr); // Create and configure function auto func = support::cpp14::make_unique<PadLayerFunction>(); - func->configure(input, output, padding); + func->configure(input, output, padding, pad_value); // Log info ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " diff --git a/arm_compute/graph/frontend/Layers.h b/arm_compute/graph/frontend/Layers.h index 420f715674..61a6fd47ee 100644 --- a/arm_compute/graph/frontend/Layers.h +++ b/arm_compute/graph/frontend/Layers.h @@ -832,11 +832,12 @@ class PadLayer final : public ILayer public: /** Construct a pad layer. * - * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] - * specifies the front and the end padding in the i-th dimension. + * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] + * specifies the front and the end padding in the i-th dimension. + * @param[in] pad_value Padding value to use. Defaults to 0. */ - PadLayer(PaddingList padding) - : _padding(padding) + PadLayer(PaddingList padding, PixelValue pad_value = PixelValue()) + : _padding(padding), _pad_value(pad_value) { } @@ -844,11 +845,12 @@ public: { NodeParams common_params = { name(), s.hints().target_hint }; NodeIdxPair input = { s.tail_node(), 0 }; - return GraphBuilder::add_pad_node(s.graph(), common_params, input, _padding); + return GraphBuilder::add_pad_node(s.graph(), common_params, input, _padding, _pad_value); } private: PaddingList _padding; + PixelValue _pad_value; }; /** Permute Layer */ diff --git a/arm_compute/graph/nodes/PadLayerNode.h b/arm_compute/graph/nodes/PadLayerNode.h index 0b1bddac9b..852427a593 100644 --- a/arm_compute/graph/nodes/PadLayerNode.h +++ b/arm_compute/graph/nodes/PadLayerNode.h @@ -36,15 +36,21 @@ class PadLayerNode final : public INode public: /** Constructor * - * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] - * specifies the front and the end padding in the i-th dimension. + * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] + * specifies the front and the end padding in the i-th dimension. + * @param[in] pad_value Padding value to be used. Defaults to 0 */ - PadLayerNode(const PaddingList &padding); + PadLayerNode(const PaddingList &padding, PixelValue pad_value = PixelValue()); /** Padding list accessor * * @return Padding list */ const PaddingList &padding() const; + /** Padding value accessor + * + * @return Padding value + */ + PixelValue pad_value() const; // Inherited overridden methods: NodeType type() const override; @@ -54,6 +60,7 @@ public: private: PaddingList _padding; + PixelValue _pad_value; }; } // namespace graph } // namespace arm_compute diff --git a/src/graph/GraphBuilder.cpp b/src/graph/GraphBuilder.cpp index 6592b2b21e..97ade9362d 100644 --- a/src/graph/GraphBuilder.cpp +++ b/src/graph/GraphBuilder.cpp @@ -571,9 +571,9 @@ NodeID GraphBuilder::add_normalize_planar_yuv_node(Graph &g, NodeParams params, return norm_planar_yuv_nid; } -NodeID GraphBuilder::add_pad_node(Graph &g, NodeParams params, NodeIdxPair input, PaddingList padding) +NodeID GraphBuilder::add_pad_node(Graph &g, NodeParams params, NodeIdxPair input, const PaddingList &paddings, PixelValue pad_value) { - return create_simple_single_input_output_node<PadLayerNode>(g, params, input, padding); + return create_simple_single_input_output_node<PadLayerNode>(g, params, input, paddings, pad_value); } NodeID GraphBuilder::add_permute_node(Graph &g, NodeParams params, NodeIdxPair input, PermutationVector perm, DataLayout layout) diff --git a/src/graph/nodes/PadLayerNode.cpp b/src/graph/nodes/PadLayerNode.cpp index 1bd0776b35..cbee134caf 100644 --- a/src/graph/nodes/PadLayerNode.cpp +++ b/src/graph/nodes/PadLayerNode.cpp @@ -32,8 +32,8 @@ namespace arm_compute { namespace graph { -PadLayerNode::PadLayerNode(const PaddingList &padding) - : _padding(padding) +PadLayerNode::PadLayerNode(const PaddingList &padding, PixelValue pad_value) + : _padding(padding), _pad_value(pad_value) { _input_edges.resize(1, EmptyEdgeID); _outputs.resize(1, NullTensorID); @@ -44,6 +44,11 @@ const PaddingList &PadLayerNode::padding() const return _padding; } +PixelValue PadLayerNode::pad_value() const +{ + return _pad_value; +} + bool PadLayerNode::forward_descriptors() { if((input_id(0) != NullTensorID) && (output_id(0) != NullTensorID)) |