blob: 7f80948c818d913ff8f31dbdd772beb9e82f5cc4 [file] [log] [blame]
Isabella Gottardi05e56442018-11-16 11:26:52 +00001/*
2 * Copyright (c) 2018 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_OUTPUT_LAYER_H__
25#define __ARM_COMPUTE_CPP_DETECTION_OUTPUT_LAYER_H__
26
27#include "arm_compute/runtime/CPP/ICPPSimpleFunction.h"
28
29#include "arm_compute/core/Types.h"
30
31#include <map>
32
33namespace arm_compute
34{
35class ITensor;
36
37// Normalized Bounding Box [xmin, ymin, xmax, ymax]
38using NormalizedBBox = std::array<float, 4>;
39// LabelBBox used for map label and bounding box
40using LabelBBox = std::map<int, std::vector<NormalizedBBox>>;
41
42/** CPP Function to generate the detection output based on location and confidence
43 * predictions by doing non maximum suppression.
44 *
45 * @note Intended for use with MultiBox detection method.
46 */
47class CPPDetectionOutputLayer : public IFunction
48{
49public:
50 /** Default constructor */
51 CPPDetectionOutputLayer();
52 /** Configure the detection output layer CPP kernel
53 *
54 * @param[in] input_loc The mbox location input tensor of size [C1, N]. Data types supported: F32.
55 * @param[in] input_conf The mbox confidence input tensor of size [C2, N]. Data types supported: F32.
56 * @param[in] input_priorbox The mbox prior box input tensor of size [C3, 2, N]. Data types supported: F32.
57 * @param[out] output The output tensor of size [7, M]. Data types supported: Same as @p input
58 * @param[in] info (Optional) DetectionOutputLayerInfo information.
59 *
60 * @note Output contains all the detections. Of those, only the ones selected by the valid region are valid.
61 */
62 void configure(const ITensor *input_loc, const ITensor *input_conf, const ITensor *input_priorbox, ITensor *output, DetectionOutputLayerInfo info = DetectionOutputLayerInfo());
63 /** Static function to check if given info will lead to a valid configuration of @ref CPPDetectionOutputLayer
64 *
65 * @param[in] input_loc The mbox location input tensor info. Data types supported: F32.
66 * @param[in] input_conf The mbox confidence input tensor info. Data types supported: F32.
67 * @param[in] input_priorbox The mbox prior box input tensor info. Data types supported: F32.
68 * @param[in] output The output tensor info. Data types supported: Same as @p input
69 * @param[in] info (Optional) DetectionOutputLayerInfo information.
70 *
71 * @return a status
72 */
73 static Status validate(const ITensorInfo *input_loc, const ITensorInfo *input_conf, const ITensorInfo *input_priorbox, const ITensorInfo *output,
74 DetectionOutputLayerInfo info = DetectionOutputLayerInfo());
75 // Inherited methods overridden:
76 void run() override;
77 /** Prevent instances of this class from being copied (As this class contains pointers) */
78 CPPDetectionOutputLayer(const CPPDetectionOutputLayer &) = delete;
79 /** Prevent instances of this class from being copied (As this class contains pointers) */
80 CPPDetectionOutputLayer &operator=(const CPPDetectionOutputLayer &) = delete;
81
82private:
83 const ITensor *_input_loc;
84 const ITensor *_input_conf;
85 const ITensor *_input_priorbox;
86 ITensor *_output;
87 DetectionOutputLayerInfo _info;
88
89 int _num_priors;
90 int _num;
91
92 std::vector<LabelBBox> _all_location_predictions;
93 std::vector<std::map<int, std::vector<float>>> _all_confidence_scores;
94 std::vector<NormalizedBBox> _all_prior_bboxes;
95 std::vector<std::array<float, 4>> _all_prior_variances;
96 std::vector<LabelBBox> _all_decode_bboxes;
97 std::vector<std::map<int, std::vector<int>>> _all_indices;
98};
99} // namespace arm_compute
100#endif /* __ARM_COMPUTE_CPP_DETECTION_OUTPUT_LAYER_H__ */