| 1 |
/* |
| 2 |
* Copyright (c) 2019-2021, 2024 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 ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEDETECTIONPOSTPROCESSLAYER_H |
| 25 |
#define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEDETECTIONPOSTPROCESSLAYER_H |
| 26 |
|
| 27 |
#include "arm_compute/core/Types.h" |
| 28 |
#include "arm_compute/runtime/CPP/functions/CPPDetectionPostProcessLayer.h" |
| 29 |
#include "arm_compute/runtime/IMemoryManager.h" |
| 30 |
#include "arm_compute/runtime/MemoryGroup.h" |
| 31 |
#include "arm_compute/runtime/MemoryManagerOnDemand.h" |
| 32 |
#include "arm_compute/runtime/NEON/functions/NEDequantizationLayer.h" |
| 33 |
#include "arm_compute/runtime/NEON/INESimpleFunction.h" |
| 34 |
#include "arm_compute/runtime/Tensor.h" |
| 35 |
|
| 36 |
#include <map> |
| 37 |
|
| 38 |
namespace arm_compute |
| 39 |
{ |
| 40 |
class ITensor; |
| 41 |
|
| 42 |
/** NE Function to generate the detection output based on center size encoded boxes, class prediction and anchors |
| 43 |
* by doing non maximum suppression. |
| 44 |
* |
| 45 |
* @note Intended for use with MultiBox detection method. |
| 46 |
*/ |
| 47 |
class NEDetectionPostProcessLayer : public IFunction |
| 48 |
{ |
| 49 |
public: |
| 50 |
/** Constructor */ |
| 51 |
NEDetectionPostProcessLayer(std::shared_ptr<IMemoryManager> memory_manager); |
| 52 |
NEDetectionPostProcessLayer() : NEDetectionPostProcessLayer(MemoryManagerOnDemand::make_default()) |
| 53 |
{ |
| 54 |
} |
| 55 |
/** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 56 |
NEDetectionPostProcessLayer(const NEDetectionPostProcessLayer &) = delete; |
| 57 |
/** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 58 |
NEDetectionPostProcessLayer &operator=(const NEDetectionPostProcessLayer &) = delete; |
| 59 |
/** Default destructor */ |
| 60 |
~NEDetectionPostProcessLayer() = default; |
| 61 |
/** Configure the detection output layer NE function |
| 62 |
* |
| 63 |
* Valid data layouts: |
| 64 |
* - All |
| 65 |
* |
| 66 |
* Valid data type configurations: |
| 67 |
* |src0 - src2 |dst0 - dst3 | |
| 68 |
* |:--------------|:--------------| |
| 69 |
* |QASYMM8 |F32 | |
| 70 |
* |QASYMM8_SIGNED |F32 | |
| 71 |
* |F32 |F32 | |
| 72 |
* |
| 73 |
* @param[in] input_box_encoding The bounding box input tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F32. |
| 74 |
* @param[in] input_score The class prediction input tensor. Data types supported: same as @p input_box_encoding. |
| 75 |
* @param[in] input_anchors The anchors input tensor. Data types supported: same as @p input_box_encoding. |
| 76 |
* @param[out] output_boxes The boxes output tensor. Data types supported: F32. |
| 77 |
* @param[out] output_classes The classes output tensor. Data types supported: Same as @p output_boxes. |
| 78 |
* @param[out] output_scores The scores output tensor. Data types supported: Same as @p output_boxes. |
| 79 |
* @param[out] num_detection The number of output detection. Data types supported: Same as @p output_boxes. |
| 80 |
* @param[in] info (Optional) DetectionPostProcessLayerInfo information. |
| 81 |
* |
| 82 |
* @note Output contains all the detections. Of those, only the ones selected by the valid region are valid. |
| 83 |
*/ |
| 84 |
void configure(const ITensor *input_box_encoding, |
| 85 |
const ITensor *input_score, |
| 86 |
const ITensor *input_anchors, |
| 87 |
ITensor *output_boxes, |
| 88 |
ITensor *output_classes, |
| 89 |
ITensor *output_scores, |
| 90 |
ITensor *num_detection, |
| 91 |
DetectionPostProcessLayerInfo info = DetectionPostProcessLayerInfo()); |
| 92 |
/** Static function to check if given info will lead to a valid configuration of @ref NEDetectionPostProcessLayer |
| 93 |
* |
| 94 |
* @param[in] input_box_encoding The bounding box input tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F32. |
| 95 |
* @param[in] input_class_score The class prediction input tensor info. Data types supported: same as @p input_box_encoding. |
| 96 |
* @param[in] input_anchors The anchors input tensor info. Data types supported: same as @p input_box_encoding. |
| 97 |
* @param[in] output_boxes The output tensor info. Data types supported: F32. |
| 98 |
* @param[in] output_classes The output tensor info. Data types supported: Same as @p output_boxes. |
| 99 |
* @param[in] output_scores The output tensor info. Data types supported: Same as @p output_boxes. |
| 100 |
* @param[in] num_detection The number of output detection tensor info. Data types supported: Same as @p output_boxes. |
| 101 |
* @param[in] info (Optional) DetectionPostProcessLayerInfo information. |
| 102 |
* |
| 103 |
* @return a status |
| 104 |
*/ |
| 105 |
static Status validate(const ITensorInfo *input_box_encoding, |
| 106 |
const ITensorInfo *input_class_score, |
| 107 |
const ITensorInfo *input_anchors, |
| 108 |
ITensorInfo *output_boxes, |
| 109 |
ITensorInfo *output_classes, |
| 110 |
ITensorInfo *output_scores, |
| 111 |
ITensorInfo *num_detection, |
| 112 |
DetectionPostProcessLayerInfo info = DetectionPostProcessLayerInfo()); |
| 113 |
// Inherited methods overridden: |
| 114 |
void run() override; |
| 115 |
|
| 116 |
private: |
| 117 |
MemoryGroup _memory_group; |
| 118 |
|
| 119 |
NEDequantizationLayer _dequantize; |
| 120 |
CPPDetectionPostProcessLayer _detection_post_process; |
| 121 |
|
| 122 |
Tensor _decoded_scores; |
| 123 |
bool _run_dequantize; |
| 124 |
}; |
| 125 |
} // namespace arm_compute |
| 126 |
#endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEDETECTIONPOSTPROCESSLAYER_H |