blob: cb416af070e07b7a54590a9879d3492877dd6f1e [file] [log] [blame]
Isabella Gottardi883bad72019-07-15 17:33:07 +01001/*
2 * Copyright (c) 2019 ARM Limited.
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CPP_NONMAXIMUMSUPPRESSIONKERNEL_LAYER_H
25#define ARM_COMPUTE_CPP_NONMAXIMUMSUPPRESSIONKERNEL_LAYER_H
Isabella Gottardi883bad72019-07-15 17:33:07 +010026
27#include "arm_compute/runtime/CPP/ICPPSimpleFunction.h"
28
29#include "arm_compute/core/Types.h"
30
31namespace arm_compute
32{
33class ITensor;
34
35/** CPP Function to perform non maximum suppression on the bounding boxes and scores
36 *
37 */
38class CPPNonMaximumSuppressionKernel : public ICPPKernel
39{
40public:
41 const char *name() const override
42 {
43 return "CPPNonMaximumSuppressionKernel";
44 }
45 /** Default constructor */
46 CPPNonMaximumSuppressionKernel();
47 /** Prevent instances of this class from being copied (As this class contains pointers) */
48 CPPNonMaximumSuppressionKernel(const CPPNonMaximumSuppressionKernel &) = delete;
49 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 CPPNonMaximumSuppressionKernel &operator=(const CPPNonMaximumSuppressionKernel &) = delete;
51 /** Allow instances of this class to be moved */
52 CPPNonMaximumSuppressionKernel(CPPNonMaximumSuppressionKernel &&) = default;
53 /** Allow instances of this class to be moved */
54 CPPNonMaximumSuppressionKernel &operator=(CPPNonMaximumSuppressionKernel &&) = default;
55 /** Default destructor */
56 ~CPPNonMaximumSuppressionKernel() = default;
57
58 /** Configure the kernel to perform non maximal suppression
59 *
60 * @param[in] input_bboxes The input bounding boxes. Data types supported: F32.
61 * @param[in] input_scores The corresponding input confidence. Same as @p input_bboxes.
62 * @param[out] output_indices The kept indices of bboxes after nms. Data types supported: S32.
63 * @param[in] max_output_size An integer tensor representing the maximum number of boxes to be selected by non max suppression.
64 * @param[in] score_threshold The threshold used to filter detection results.
65 * @param[in] iou_threshold The threshold used in non maximum suppression.
66 *
67 */
68 void configure(const ITensor *input_bboxes, const ITensor *input_scores, ITensor *output_indices, unsigned int max_output_size, const float score_threshold, const float iou_threshold);
69
70 /** Static function to check if given arguments will lead to a valid configuration of @ref CPPNonMaximumSuppressionKernel
71 *
72 * @param[in] input_bboxes The input bounding boxes tensor info. Data types supported: F32.
73 * @param[in] input_scores The corresponding input confidence tensor info. Same as @p input_bboxes.
74 * @param[out] output_indices The kept indices of bboxes after nms tensor info. Data types supported: S32.
75 * @param[in] max_output_size An integer tensor representing the maximum number of boxes to be selected by non max suppression.
76 * @param[in] score_threshold The threshold used to filter detection results.
77 * @param[in] iou_threshold The threshold used in non maximum suppression.
78 *
79 */
80 static Status validate(const ITensorInfo *input_bboxes, const ITensorInfo *input_scores, const ITensorInfo *output_indices, unsigned int max_output_size,
81 const float score_threshold, const float iou_threshold);
82
83 // Inherited methods overridden:
84 void run(const Window &window, const ThreadInfo &info) override;
85
86private:
87 const ITensor *_input_bboxes;
88 const ITensor *_input_scores;
89 ITensor *_output_indices;
90 unsigned int _max_output_size;
91 float _score_threshold;
92 float _iou_threshold;
93
94 unsigned int _num_boxes;
Isabella Gottardi883bad72019-07-15 17:33:07 +010095};
96} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000097#endif /* ARM_COMPUTE_CPP_NONMAXIMUMSUPPRESSIONKERNEL_LAYER_H */