Compute Library
 22.08
CPPDetectionPostProcessLayer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020 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  */
24 #ifndef ARM_COMPUTE_CPP_DETECTION_POSTPROCESS_H
25 #define ARM_COMPUTE_CPP_DETECTION_POSTPROCESS_H
26 
28 
29 #include "arm_compute/core/Types.h"
34 
35 #include <map>
36 
37 namespace arm_compute
38 {
39 class ITensor;
40 
41 /** CPP Function to generate the detection output based on center size encoded boxes, class prediction and anchors
42  * by doing non maximum suppression.
43  *
44  * @note Intended for use with MultiBox detection method.
45  */
47 {
48 public:
49  /** Constructor */
50  CPPDetectionPostProcessLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
51  /** Prevent instances of this class from being copied (As this class contains pointers) */
53  /** Prevent instances of this class from being copied (As this class contains pointers) */
55  /** Configure the detection output layer CPP function
56  *
57  * @param[in] input_box_encoding The bounding box input tensor. Data types supported: F32/QASYMM8/QASYMM8_SIGNED.
58  * @param[in] input_score The class prediction input tensor. Data types supported: Same as @p input_box_encoding.
59  * @param[in] input_anchors The anchors input tensor. Data types supported: Same as @p input_box_encoding.
60  * @param[out] output_boxes The boxes output tensor. Data types supported: F32.
61  * @param[out] output_classes The classes output tensor. Data types supported: Same as @p output_boxes.
62  * @param[out] output_scores The scores output tensor. Data types supported: Same as @p output_boxes.
63  * @param[out] num_detection The number of output detection. Data types supported: Same as @p output_boxes.
64  * @param[in] info (Optional) DetectionPostProcessLayerInfo information.
65  *
66  * @note Output contains all the detections. Of those, only the ones selected by the valid region are valid.
67  */
68  void configure(const ITensor *input_box_encoding, const ITensor *input_score, const ITensor *input_anchors,
69  ITensor *output_boxes, ITensor *output_classes, ITensor *output_scores, ITensor *num_detection, DetectionPostProcessLayerInfo info = DetectionPostProcessLayerInfo());
70  /** Static function to check if given info will lead to a valid configuration of @ref CPPDetectionPostProcessLayer
71  *
72  * @param[in] input_box_encoding The bounding box input tensor info. Data types supported: F32/QASYMM8/QASYMM8_SIGNED.
73  * @param[in] input_class_score The class prediction input tensor info. Data types supported: Same as @p input_box_encoding.
74  * @param[in] input_anchors The anchors input tensor. Data types supported: F32, QASYMM8.
75  * @param[out] output_boxes The output tensor. Data types supported: F32.
76  * @param[out] output_classes The output tensor. Data types supported: Same as @p output_boxes.
77  * @param[out] output_scores The output tensor. Data types supported: Same as @p output_boxes.
78  * @param[out] num_detection The number of output detection. Data types supported: Same as @p output_boxes.
79  * @param[in] info (Optional) DetectionPostProcessLayerInfo information.
80  *
81  * @return a status
82  */
83  static Status validate(const ITensorInfo *input_box_encoding, const ITensorInfo *input_class_score, const ITensorInfo *input_anchors,
84  ITensorInfo *output_boxes, ITensorInfo *output_classes, ITensorInfo *output_scores, ITensorInfo *num_detection,
86  // Inherited methods overridden:
87  void run() override;
88 
89 private:
90  MemoryGroup _memory_group;
92  const ITensor *_input_box_encoding;
93  const ITensor *_input_scores;
94  const ITensor *_input_anchors;
95  ITensor *_output_boxes;
96  ITensor *_output_classes;
97  ITensor *_output_scores;
98  ITensor *_num_detection;
100 
101  const unsigned int _kBatchSize = 1;
102  const unsigned int _kNumCoordBox = 4;
103  unsigned int _num_boxes;
104  unsigned int _num_classes_with_background;
105  unsigned int _num_max_detected_boxes;
106  bool _dequantize_scores;
107 
108  Tensor _decoded_boxes;
109  Tensor _decoded_scores;
110  Tensor _selected_indices;
111  Tensor _class_scores;
112  const ITensor *_input_scores_to_use;
113 };
114 } // namespace arm_compute
115 #endif /* ARM_COMPUTE_CPP_DETECTION_POSTPROCESS_H */
Base class for all functions.
Definition: IFunction.h:30
static Status validate(const ITensorInfo *input_box_encoding, const ITensorInfo *input_class_score, const ITensorInfo *input_anchors, ITensorInfo *output_boxes, ITensorInfo *output_classes, ITensorInfo *output_scores, ITensorInfo *num_detection, DetectionPostProcessLayerInfo info=DetectionPostProcessLayerInfo())
Static function to check if given info will lead to a valid configuration of CPPDetectionPostProcessL...
CPPDetectionPostProcessLayer(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Constructor.
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
Interface for CPU tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2022 Arm Limited.
CPP Function to generate the detection output based on center size encoded boxes, class prediction an...
void run() override
Run the kernels contained in the function.
Basic implementation of the tensor interface.
Definition: Tensor.h:37
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
void configure(const ITensor *input_box_encoding, const ITensor *input_score, const ITensor *input_anchors, ITensor *output_boxes, ITensor *output_classes, ITensor *output_scores, ITensor *num_detection, DetectionPostProcessLayerInfo info=DetectionPostProcessLayerInfo())
Configure the detection output layer CPP function.
Detection Output layer info.
Definition: Types.h:1067
CPPDetectionPostProcessLayer & operator=(const CPPDetectionPostProcessLayer &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
CPP Function to perform non maximum suppression on the bounding boxes and scores. ...