blob: 59093358267db1f0c5099d3d3a7e146f74766e7a [file] [log] [blame]
Manuel Bottini3f9d4d72018-10-19 14:04:42 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018 Arm Limited.
Manuel Bottini3f9d4d72018-10-19 14:04:42 +01003 *
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
25#include "arm_compute/graph/nodes/ROIAlignLayerNode.h"
26
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010027#include "arm_compute/core/Helpers.h"
Manuel Bottini3f9d4d72018-10-19 14:04:42 +010028#include "arm_compute/graph/Graph.h"
29#include "arm_compute/graph/INodeVisitor.h"
30
Manuel Bottini3f9d4d72018-10-19 14:04:42 +010031namespace arm_compute
32{
33namespace graph
34{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010035ROIAlignLayerNode::ROIAlignLayerNode(ROIPoolingLayerInfo &pool_info) : _pool_info(pool_info)
Manuel Bottini3f9d4d72018-10-19 14:04:42 +010036{
37 _input_edges.resize(2, EmptyEdgeID);
38 _outputs.resize(1, NullTensorID);
39}
40
41const ROIPoolingLayerInfo &ROIAlignLayerNode::pooling_info() const
42{
43 return _pool_info;
44}
45
46bool ROIAlignLayerNode::forward_descriptors()
47{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010048 if ((input_id(0) != NullTensorID) && (input_id(1) != NullTensorID) && (output_id(0) != NullTensorID))
Manuel Bottini3f9d4d72018-10-19 14:04:42 +010049 {
50 Tensor *dst = output(0);
51 ARM_COMPUTE_ERROR_ON(dst == nullptr);
52 dst->desc() = configure_output(0);
53 return true;
54 }
55 return false;
56}
57
58TensorDescriptor ROIAlignLayerNode::configure_output(size_t idx) const
59{
60 ARM_COMPUTE_UNUSED(idx);
61 ARM_COMPUTE_ERROR_ON(idx >= _outputs.size());
62
63 const Tensor *src = input(0);
64 const Tensor *rois = input(1);
65 ARM_COMPUTE_ERROR_ON(src == nullptr);
66 ARM_COMPUTE_ERROR_ON(rois == nullptr);
67
68 TensorDescriptor output_desc = src->desc();
69
70 const size_t idx_n = get_data_layout_dimension_index(output_desc.layout, DataLayoutDimension::BATCHES);
71 const size_t idx_c = get_data_layout_dimension_index(output_desc.layout, DataLayoutDimension::CHANNEL);
72 const size_t idx_h = get_data_layout_dimension_index(output_desc.layout, DataLayoutDimension::HEIGHT);
73 const size_t idx_w = get_data_layout_dimension_index(output_desc.layout, DataLayoutDimension::WIDTH);
74
75 output_desc.shape.set(idx_n, rois->desc().shape[1]);
76 output_desc.shape.set(idx_c, src->desc().shape[idx_c]);
77 output_desc.shape.set(idx_h, _pool_info.pooled_height());
78 output_desc.shape.set(idx_w, _pool_info.pooled_width());
79
80 return output_desc;
81}
82
83NodeType ROIAlignLayerNode::type() const
84{
85 return NodeType::ROIAlignLayer;
86}
87
88void ROIAlignLayerNode::accept(INodeVisitor &v)
89{
90 v.visit(*this);
91}
92} // namespace graph
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010093} // namespace arm_compute