Compute Library
 20.05
ROIAlignLayerNode.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 ARM Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
26 
29 
31 
32 namespace arm_compute
33 {
34 namespace graph
35 {
37  : _pool_info(pool_info)
38 {
39  _input_edges.resize(2, EmptyEdgeID);
40  _outputs.resize(1, NullTensorID);
41 }
42 
44 {
45  return _pool_info;
46 }
47 
49 {
50  if((input_id(0) != NullTensorID) && (input_id(1) != NullTensorID) && (output_id(0) != NullTensorID))
51  {
52  Tensor *dst = output(0);
53  ARM_COMPUTE_ERROR_ON(dst == nullptr);
54  dst->desc() = configure_output(0);
55  return true;
56  }
57  return false;
58 }
59 
61 {
62  ARM_COMPUTE_UNUSED(idx);
63  ARM_COMPUTE_ERROR_ON(idx >= _outputs.size());
64 
65  const Tensor *src = input(0);
66  const Tensor *rois = input(1);
67  ARM_COMPUTE_ERROR_ON(src == nullptr);
68  ARM_COMPUTE_ERROR_ON(rois == nullptr);
69 
70  TensorDescriptor output_desc = src->desc();
71 
72  const size_t idx_n = get_data_layout_dimension_index(output_desc.layout, DataLayoutDimension::BATCHES);
73  const size_t idx_c = get_data_layout_dimension_index(output_desc.layout, DataLayoutDimension::CHANNEL);
74  const size_t idx_h = get_data_layout_dimension_index(output_desc.layout, DataLayoutDimension::HEIGHT);
75  const size_t idx_w = get_data_layout_dimension_index(output_desc.layout, DataLayoutDimension::WIDTH);
76 
77  output_desc.shape.set(idx_n, rois->desc().shape[1]);
78  output_desc.shape.set(idx_c, src->desc().shape[idx_c]);
79  output_desc.shape.set(idx_h, _pool_info.pooled_height());
80  output_desc.shape.set(idx_w, _pool_info.pooled_width());
81 
82  return output_desc;
83 }
84 
86 {
88 }
89 
91 {
92  v.visit(*this);
93 }
94 } // namespace graph
95 } // namespace arm_compute
bool forward_descriptors() override
Forwards descriptor information to outputs if possible.
const ROIPoolingLayerInfo & pooling_info() const
ROIPoolingLayerInfo accessor.
ROIAlignLayerNode(ROIPoolingLayerInfo &pool_info)
Constructor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
unsigned int pooled_width() const
Get the pooled width of the layer.
Definition: Types.h:1291
Copyright (c) 2017-2020 ARM Limited.
TensorDescriptor & desc()
TensorInfo metadata accessor.
Definition: Tensor.cpp:40
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
virtual void visit(INode &n)=0
Visit INode.
Tensor * output(size_t idx) const
Returns the tensor of a given output of the node.
Definition: INode.cpp:158
TensorID input_id(size_t idx) const
Returns the tensor ID of a given input of the node.
Definition: INode.cpp:137
NodeType
Supported nodes.
Definition: Types.h:134
NodeType type() const override
Returns node's type.
constexpr EdgeID EmptyEdgeID
Definition: Types.h:75
unsigned int pooled_height() const
Get the pooled height of the layer.
Definition: Types.h:1296
ROI Pooling Layer Information class.
Definition: Types.h:1276
TensorID output_id(size_t idx) const
Returns the tensor ID of a given output of the node.
Definition: INode.cpp:144
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true)
Accessor to set the value of one of the dimensions.
Definition: TensorShape.h:78
TensorDescriptor configure_output(size_t idx) const override
Calculates output configuration.
void accept(INodeVisitor &v) override
Accepts a node visitor.
constexpr TensorID NullTensorID
Constant NodeID specifying an equivalent of null node.
Definition: Types.h:71
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:327
Node visitor interface.
Definition: INodeVisitor.h:34
Tensor * input(size_t idx) const
Returns the tensor of a given input of the node.
Definition: INode.cpp:150
cast configure & src
Definition: Cast.cpp:169
Tensor object.
Definition: Tensor.h:41