blob: 58b4bf25cc3f4d7be70775c896ea002a1e98c6cd [file] [log] [blame]
Michalis Spyrou2709d612018-09-19 09:46:47 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Michalis Spyrou2709d612018-09-19 09:46:47 +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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CPPBOXWITHNONMAXIMASUPPRESSIONLIMIT_H
25#define ARM_COMPUTE_CPPBOXWITHNONMAXIMASUPPRESSIONLIMIT_H
Michalis Spyrou2709d612018-09-19 09:46:47 +010026
Michele Di Giorgio70ad6192019-09-06 17:51:37 +010027#include "arm_compute/core/CPP/kernels/CPPBoxWithNonMaximaSuppressionLimitKernel.h"
Michalis Spyrou2709d612018-09-19 09:46:47 +010028#include "arm_compute/core/Types.h"
Michele Di Giorgio70ad6192019-09-06 17:51:37 +010029#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 Spyrou2709d612018-09-19 09:46:47 +010033
34namespace arm_compute
35{
36class ITensor;
37
38/** Basic function to run @ref CPPBoxWithNonMaximaSuppressionLimitKernel */
Michele Di Giorgio70ad6192019-09-06 17:51:37 +010039class CPPBoxWithNonMaximaSuppressionLimit : public IFunction
Michalis Spyrou2709d612018-09-19 09:46:47 +010040{
41public:
Michele Di Giorgio70ad6192019-09-06 17:51:37 +010042 /** 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 Spyrou2709d612018-09-19 09:46:47 +010048 /** Configure the BoxWithNonMaximaSuppressionLimit CPP kernel
49 *
Sheri Zhangd9a623a2020-03-16 21:25:52 +000050 * @param[in] scores_in The scores input tensor of size [count, num_classes]. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32
Michele Di Giorgio70ad6192019-09-06 17:51:37 +010051 * @param[in] boxes_in The boxes input tensor of size [count, num_classes * 4].
Sheri Zhangd9a623a2020-03-16 21:25:52 +000052 * 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 Spyrou2709d612018-09-19 09:46:47 +010053 * @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 Giorgio70ad6192019-09-06 17:51:37 +010056 * @param[out] boxes_out The boxes output tensor of size [N, 4].
Sheri Zhangd9a623a2020-03-16 21:25:52 +000057 * 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 Spyrou2709d612018-09-19 09:46:47 +010058 * @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
Michele Di Giorgiof22f6722020-07-03 16:29:24 +010061 * @param[in] keeps_size (Optional) Number of filtered indices per class tensor of size [num_classes]. Data types supported: U32.
Michalis Spyrou2709d612018-09-19 09:46:47 +010062 * @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 Giorgio70ad6192019-09-06 17:51:37 +010066 /** Static function to check if given info will lead to a valid configuration of @ref CPPDetectionOutputLayer
67 *
Sheri Zhangd9a623a2020-03-16 21:25:52 +000068 * @param[in] scores_in The scores input tensor of size [count, num_classes]. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32
Michele Di Giorgio70ad6192019-09-06 17:51:37 +010069 * @param[in] boxes_in The boxes input tensor of size [count, num_classes * 4].
Sheri Zhangd9a623a2020-03-16 21:25:52 +000070 * 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 Giorgio70ad6192019-09-06 17:51:37 +010071 * @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 Zhangd9a623a2020-03-16 21:25:52 +000075 * 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 Giorgio70ad6192019-09-06 17:51:37 +010076 * @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
Michele Di Giorgiof22f6722020-07-03 16:29:24 +010079 * @param[in] keeps_size (Optional) Number of filtered indices per class tensor of size [num_classes]. Data types supported: U32.
Michele Di Giorgio70ad6192019-09-06 17:51:37 +010080 * @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
90private:
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 Giorgio70ad6192019-09-06 17:51:37 +0100103
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 Giorgio70ad6192019-09-06 17:51:37 +0100112
113 bool _is_qasymm8;
Michalis Spyrou2709d612018-09-19 09:46:47 +0100114};
115} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000116#endif /* ARM_COMPUTE_CPPBOXWITHNONMAXIMASUPPRESSIONLIMIT_H */