Manuel Bottini | 3f9d4d7 | 2018-10-19 14:04:42 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018 Arm Limited. |
Manuel Bottini | 3f9d4d7 | 2018-10-19 14:04:42 +0100 | [diff] [blame] | 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 | |
| 25 | #include "arm_compute/graph/nodes/ROIAlignLayerNode.h" |
| 26 | |
| 27 | #include "arm_compute/graph/Graph.h" |
| 28 | #include "arm_compute/graph/INodeVisitor.h" |
| 29 | |
| 30 | #include "arm_compute/core/Helpers.h" |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace graph |
| 35 | { |
| 36 | ROIAlignLayerNode::ROIAlignLayerNode(ROIPoolingLayerInfo &pool_info) |
| 37 | : _pool_info(pool_info) |
| 38 | { |
| 39 | _input_edges.resize(2, EmptyEdgeID); |
| 40 | _outputs.resize(1, NullTensorID); |
| 41 | } |
| 42 | |
| 43 | const ROIPoolingLayerInfo &ROIAlignLayerNode::pooling_info() const |
| 44 | { |
| 45 | return _pool_info; |
| 46 | } |
| 47 | |
| 48 | bool ROIAlignLayerNode::forward_descriptors() |
| 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 | |
| 60 | TensorDescriptor ROIAlignLayerNode::configure_output(size_t idx) const |
| 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 | |
| 85 | NodeType ROIAlignLayerNode::type() const |
| 86 | { |
| 87 | return NodeType::ROIAlignLayer; |
| 88 | } |
| 89 | |
| 90 | void ROIAlignLayerNode::accept(INodeVisitor &v) |
| 91 | { |
| 92 | v.visit(*this); |
| 93 | } |
| 94 | } // namespace graph |
| 95 | } // namespace arm_compute |