Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 1 | /* |
Sheri Zhang | d9a623a | 2020-03-16 21:25:52 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2018-2020 ARM Limited. |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CPPBOXWITHNONMAXIMASUPPRESSIONLIMIT_H |
| 25 | #define ARM_COMPUTE_CPPBOXWITHNONMAXIMASUPPRESSIONLIMIT_H |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 26 | |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.h" |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/Types.h" |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/IFunction.h" |
| 30 | #include "arm_compute/runtime/IMemoryManager.h" |
| 31 | #include "arm_compute/runtime/MemoryGroup.h" |
| 32 | #include "arm_compute/runtime/Tensor.h" |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | class ITensor; |
| 37 | |
| 38 | /** Basic function to run @ref CPPBoxWithNonMaximaSuppressionLimitKernel */ |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 39 | class CPPBoxWithNonMaximaSuppressionLimit : public IFunction |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 40 | { |
| 41 | public: |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 42 | /** Constructor */ |
| 43 | CPPBoxWithNonMaximaSuppressionLimit(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
| 44 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 45 | CPPBoxWithNonMaximaSuppressionLimit(const CPPBoxWithNonMaximaSuppressionLimit &) = delete; |
| 46 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 47 | CPPBoxWithNonMaximaSuppressionLimit &operator=(const CPPBoxWithNonMaximaSuppressionLimit &) = delete; |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 48 | /** Configure the BoxWithNonMaximaSuppressionLimit CPP kernel |
| 49 | * |
Sheri Zhang | d9a623a | 2020-03-16 21:25:52 +0000 | [diff] [blame^] | 50 | * @param[in] scores_in The scores input tensor of size [count, num_classes]. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32 |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 51 | * @param[in] boxes_in The boxes input tensor of size [count, num_classes * 4]. |
Sheri Zhang | d9a623a | 2020-03-16 21:25:52 +0000 | [diff] [blame^] | 52 | * Data types supported: QASYMM16 with 0.125 scale and 0 offset if @p scores_in is QASYMM8/QASYMM8_SIGNED, otherwise same as @p scores_in |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 53 | * @param[in] batch_splits_in The batch splits input tensor of size [batch_size]. Data types supported: Same as @p scores_in |
| 54 | * @note Can be a nullptr. If not a nullptr, @p scores_in and @p boxes_in have items from multiple images. |
| 55 | * @param[out] scores_out The scores output tensor of size [N]. Data types supported: Same as @p scores_in |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 56 | * @param[out] boxes_out The boxes output tensor of size [N, 4]. |
Sheri Zhang | d9a623a | 2020-03-16 21:25:52 +0000 | [diff] [blame^] | 57 | * Data types supported: QASYMM16 with 0.125 scale and 0 offset if @p scores_in is QASYMM8/QASYMM8_SIGNED, otherwise same as @p scores_in |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 58 | * @param[out] classes The classes output tensor of size [N]. Data types supported: Same as @p scores_in |
| 59 | * @param[out] batch_splits_out (Optional) The batch splits output tensor. Data types supported: Same as @p scores_in |
| 60 | * @param[out] keeps (Optional) The keeps output tensor of size [N]. Data types supported: Same as @p scores_in |
| 61 | * @param[in] keeps_size (Optional) Number of filtered indices per class tensor of size [num_classes]. Data types supported: Same as @p scores_in |
| 62 | * @param[in] info (Optional) BoxNMSLimitInfo information. |
| 63 | */ |
| 64 | void configure(const ITensor *scores_in, const ITensor *boxes_in, const ITensor *batch_splits_in, ITensor *scores_out, ITensor *boxes_out, ITensor *classes, |
| 65 | ITensor *batch_splits_out = nullptr, ITensor *keeps = nullptr, ITensor *keeps_size = nullptr, const BoxNMSLimitInfo info = BoxNMSLimitInfo()); |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 66 | /** Static function to check if given info will lead to a valid configuration of @ref CPPDetectionOutputLayer |
| 67 | * |
Sheri Zhang | d9a623a | 2020-03-16 21:25:52 +0000 | [diff] [blame^] | 68 | * @param[in] scores_in The scores input tensor of size [count, num_classes]. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32 |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 69 | * @param[in] boxes_in The boxes input tensor of size [count, num_classes * 4]. |
Sheri Zhang | d9a623a | 2020-03-16 21:25:52 +0000 | [diff] [blame^] | 70 | * Data types supported: QASYMM16 with 0.125 scale and 0 offset if @p scores_in is QASYMM8/QASYMM8_SIGNED, otherwise same as @p scores_in |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 71 | * @param[in] batch_splits_in The batch splits input tensor of size [batch_size]. Data types supported: Same as @p scores_in |
| 72 | * @note Can be a nullptr. If not a nullptr, @p scores_in and @p boxes_in have items from multiple images. |
| 73 | * @param[in] scores_out The scores output tensor of size [N]. Data types supported: Same as @p scores_in |
| 74 | * @param[in] boxes_out The boxes output tensor of size [N, 4]. |
Sheri Zhang | d9a623a | 2020-03-16 21:25:52 +0000 | [diff] [blame^] | 75 | * Data types supported: QASYMM16 with 0.125 scale and 0 offset if @p scores_in is QASYMM8/QASYMM8_SIGNED, otherwise same as @p scores_in |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 76 | * @param[in] classes The classes output tensor of size [N]. Data types supported: Same as @p scores_in |
| 77 | * @param[in] batch_splits_out (Optional) The batch splits output tensor. Data types supported: Same as @p scores_in |
| 78 | * @param[in] keeps (Optional) The keeps output tensor of size [N]. Data types supported: Same as @p scores_in |
| 79 | * @param[in] keeps_size (Optional) Number of filtered indices per class tensor of size [num_classes]. Data types supported: Same as @p scores_in |
| 80 | * @param[in] info (Optional) BoxNMSLimitInfo information. |
| 81 | * |
| 82 | * @return a status |
| 83 | */ |
| 84 | static Status validate(const ITensorInfo *scores_in, const ITensorInfo *boxes_in, const ITensorInfo *batch_splits_in, const ITensorInfo *scores_out, const ITensorInfo *boxes_out, |
| 85 | const ITensorInfo *classes, |
| 86 | const ITensorInfo *batch_splits_out = nullptr, const ITensorInfo *keeps = nullptr, const ITensorInfo *keeps_size = nullptr, const BoxNMSLimitInfo info = BoxNMSLimitInfo()); |
| 87 | // Inherited methods overridden: |
| 88 | void run() override; |
| 89 | |
| 90 | private: |
| 91 | MemoryGroup _memory_group; |
| 92 | |
| 93 | CPPBoxWithNonMaximaSuppressionLimitKernel _box_with_nms_limit_kernel; |
| 94 | |
| 95 | const ITensor *_scores_in; |
| 96 | const ITensor *_boxes_in; |
| 97 | const ITensor *_batch_splits_in; |
| 98 | ITensor *_scores_out; |
| 99 | ITensor *_boxes_out; |
| 100 | ITensor *_classes; |
| 101 | ITensor *_batch_splits_out; |
| 102 | ITensor *_keeps; |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 103 | |
| 104 | Tensor _scores_in_f32; |
| 105 | Tensor _boxes_in_f32; |
| 106 | Tensor _batch_splits_in_f32; |
| 107 | Tensor _scores_out_f32; |
| 108 | Tensor _boxes_out_f32; |
| 109 | Tensor _classes_f32; |
| 110 | Tensor _batch_splits_out_f32; |
| 111 | Tensor _keeps_f32; |
Michele Di Giorgio | 70ad619 | 2019-09-06 17:51:37 +0100 | [diff] [blame] | 112 | |
| 113 | bool _is_qasymm8; |
Michalis Spyrou | 2709d61 | 2018-09-19 09:46:47 +0100 | [diff] [blame] | 114 | }; |
| 115 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 116 | #endif /* ARM_COMPUTE_CPPBOXWITHNONMAXIMASUPPRESSIONLIMIT_H */ |