Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019 Arm Limited. |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [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 | #include "arm_compute/graph/nodes/DetectionPostProcessLayerNode.h" |
| 25 | |
| 26 | #include "arm_compute/core/Utils.h" |
| 27 | #include "arm_compute/graph/Graph.h" |
| 28 | #include "arm_compute/graph/INodeVisitor.h" |
| 29 | #include "arm_compute/graph/Utils.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace graph |
| 34 | { |
| 35 | DetectionPostProcessLayerNode::DetectionPostProcessLayerNode(DetectionPostProcessLayerInfo detection_info) |
| 36 | : _info(detection_info) |
| 37 | { |
| 38 | _input_edges.resize(3, EmptyEdgeID); |
| 39 | _outputs.resize(4, NullTensorID); |
| 40 | } |
| 41 | |
| 42 | DetectionPostProcessLayerInfo DetectionPostProcessLayerNode::detection_post_process_info() const |
| 43 | { |
| 44 | return _info; |
| 45 | } |
| 46 | |
| 47 | bool DetectionPostProcessLayerNode::forward_descriptors() |
| 48 | { |
| 49 | if((input_id(0) != NullTensorID) && (input_id(1) != NullTensorID) && (input_id(2) != NullTensorID) && (output_id(0) != NullTensorID) && (output_id(1) != NullTensorID) |
| 50 | && (output_id(2) != NullTensorID) && (output_id(3) != NullTensorID)) |
| 51 | { |
| 52 | for(unsigned int i = 0; i < 4; ++i) |
| 53 | { |
| 54 | Tensor *dst = output(i); |
| 55 | ARM_COMPUTE_ERROR_ON(dst == nullptr); |
| 56 | dst->desc() = configure_output(i); |
| 57 | } |
| 58 | return true; |
| 59 | } |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | TensorDescriptor DetectionPostProcessLayerNode::configure_output(size_t idx) const |
| 64 | { |
| 65 | ARM_COMPUTE_UNUSED(idx); |
| 66 | ARM_COMPUTE_ERROR_ON(idx >= _outputs.size()); |
| 67 | |
| 68 | TensorDescriptor output_desc; |
| 69 | const unsigned int num_detected_box = _info.max_detections() * _info.max_classes_per_detection(); |
| 70 | |
| 71 | switch(idx) |
| 72 | { |
| 73 | case 0: |
| 74 | // Configure boxes output |
| 75 | output_desc.shape = TensorShape(kNumCoordBox, num_detected_box, kBatchSize); |
| 76 | break; |
| 77 | case 1: |
| 78 | case 2: |
| 79 | // Configure classes or scores output |
| 80 | output_desc.shape = TensorShape(num_detected_box, kBatchSize); |
| 81 | break; |
| 82 | case 3: |
| 83 | // Configure num_detection |
| 84 | output_desc.shape = TensorShape(1); |
| 85 | break; |
| 86 | default: |
| 87 | ARM_COMPUTE_ERROR("Unsupported output index"); |
| 88 | } |
| 89 | output_desc.data_type = DataType::F32; |
| 90 | |
| 91 | return output_desc; |
| 92 | } |
| 93 | |
| 94 | NodeType DetectionPostProcessLayerNode::type() const |
| 95 | { |
| 96 | return NodeType::DetectionPostProcessLayer; |
| 97 | } |
| 98 | |
| 99 | void DetectionPostProcessLayerNode::accept(INodeVisitor &v) |
| 100 | { |
| 101 | v.visit(*this); |
| 102 | } |
| 103 | } // namespace graph |
| 104 | } // namespace arm_compute |