Isabella Gottardi | 05e5644 | 2018-11-16 11:26:52 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 Arm Limited. |
Isabella Gottardi | 05e5644 | 2018-11-16 11:26:52 +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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CPP_DETECTION_OUTPUT_LAYER_H |
| 25 | #define ARM_COMPUTE_CPP_DETECTION_OUTPUT_LAYER_H |
Isabella Gottardi | 05e5644 | 2018-11-16 11:26:52 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/runtime/CPP/ICPPSimpleFunction.h" |
| 28 | |
| 29 | #include "arm_compute/core/Types.h" |
| 30 | |
Isabella Gottardi | 05e5644 | 2018-11-16 11:26:52 +0000 | [diff] [blame] | 31 | namespace arm_compute |
| 32 | { |
| 33 | class ITensor; |
| 34 | |
Isabella Gottardi | 05e5644 | 2018-11-16 11:26:52 +0000 | [diff] [blame] | 35 | /** CPP Function to generate the detection output based on location and confidence |
| 36 | * predictions by doing non maximum suppression. |
| 37 | * |
| 38 | * @note Intended for use with MultiBox detection method. |
| 39 | */ |
| 40 | class CPPDetectionOutputLayer : public IFunction |
| 41 | { |
| 42 | public: |
| 43 | /** Default constructor */ |
| 44 | CPPDetectionOutputLayer(); |
| 45 | /** Configure the detection output layer CPP kernel |
| 46 | * |
| 47 | * @param[in] input_loc The mbox location input tensor of size [C1, N]. Data types supported: F32. |
| 48 | * @param[in] input_conf The mbox confidence input tensor of size [C2, N]. Data types supported: F32. |
| 49 | * @param[in] input_priorbox The mbox prior box input tensor of size [C3, 2, N]. Data types supported: F32. |
| 50 | * @param[out] output The output tensor of size [7, M]. Data types supported: Same as @p input |
| 51 | * @param[in] info (Optional) DetectionOutputLayerInfo information. |
| 52 | * |
| 53 | * @note Output contains all the detections. Of those, only the ones selected by the valid region are valid. |
| 54 | */ |
| 55 | void configure(const ITensor *input_loc, const ITensor *input_conf, const ITensor *input_priorbox, ITensor *output, DetectionOutputLayerInfo info = DetectionOutputLayerInfo()); |
| 56 | /** Static function to check if given info will lead to a valid configuration of @ref CPPDetectionOutputLayer |
| 57 | * |
| 58 | * @param[in] input_loc The mbox location input tensor info. Data types supported: F32. |
| 59 | * @param[in] input_conf The mbox confidence input tensor info. Data types supported: F32. |
| 60 | * @param[in] input_priorbox The mbox prior box input tensor info. Data types supported: F32. |
| 61 | * @param[in] output The output tensor info. Data types supported: Same as @p input |
| 62 | * @param[in] info (Optional) DetectionOutputLayerInfo information. |
| 63 | * |
| 64 | * @return a status |
| 65 | */ |
| 66 | static Status validate(const ITensorInfo *input_loc, const ITensorInfo *input_conf, const ITensorInfo *input_priorbox, const ITensorInfo *output, |
| 67 | DetectionOutputLayerInfo info = DetectionOutputLayerInfo()); |
| 68 | // Inherited methods overridden: |
| 69 | void run() override; |
| 70 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 71 | CPPDetectionOutputLayer(const CPPDetectionOutputLayer &) = delete; |
| 72 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 73 | CPPDetectionOutputLayer &operator=(const CPPDetectionOutputLayer &) = delete; |
| 74 | |
| 75 | private: |
| 76 | const ITensor *_input_loc; |
| 77 | const ITensor *_input_conf; |
| 78 | const ITensor *_input_priorbox; |
| 79 | ITensor *_output; |
| 80 | DetectionOutputLayerInfo _info; |
| 81 | |
| 82 | int _num_priors; |
| 83 | int _num; |
| 84 | |
| 85 | std::vector<LabelBBox> _all_location_predictions; |
| 86 | std::vector<std::map<int, std::vector<float>>> _all_confidence_scores; |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 87 | std::vector<BBox> _all_prior_bboxes; |
Isabella Gottardi | 05e5644 | 2018-11-16 11:26:52 +0000 | [diff] [blame] | 88 | std::vector<std::array<float, 4>> _all_prior_variances; |
| 89 | std::vector<LabelBBox> _all_decode_bboxes; |
| 90 | std::vector<std::map<int, std::vector<int>>> _all_indices; |
| 91 | }; |
| 92 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 93 | #endif /* ARM_COMPUTE_CPP_DETECTION_OUTPUT_LAYER_H */ |