blob: 6bf6574568b1b6d2f75eebe39b69a735d43cffbf [file] [log] [blame]
Michalis Spyrou721c4cb2018-09-04 15:27:25 +01001/*
Michalis Spyrouf4643372019-11-29 16:17:13 +00002 * Copyright (c) 2018-2019 ARM Limited.
Michalis Spyrou721c4cb2018-09-04 15:27:25 +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_NEPRIORBOXLAYERKERNEL_H
25#define ARM_COMPUTE_NEPRIORBOXLAYERKERNEL_H
Michalis Spyrou721c4cb2018-09-04 15:27:25 +010026
27#include "arm_compute/core/NEON/INEKernel.h"
28
29namespace arm_compute
30{
31class ITensor;
32
33/** Interface for the kernel to calculate prior boxes */
34class NEPriorBoxLayerKernel : public INEKernel
35{
36public:
37 const char *name() const override
38 {
39 return "NEPriorBoxLayerKernel";
40 }
41 /** Default constructor */
42 NEPriorBoxLayerKernel();
43 /** Prevent instances of this class from being copied (As this class contains pointers) */
44 NEPriorBoxLayerKernel(const NEPriorBoxLayerKernel &) = delete;
45 /** Prevent instances of this class from being copied (As this class contains pointers) */
46 NEPriorBoxLayerKernel &operator=(const NEPriorBoxLayerKernel &) = delete;
47 /** Allow instances of this class to be moved */
48 NEPriorBoxLayerKernel(NEPriorBoxLayerKernel &&) = default;
49 /** Allow instances of this class to be moved */
50 NEPriorBoxLayerKernel &operator=(NEPriorBoxLayerKernel &&) = default;
51 /** Set the input and output tensors.
52 *
53 * @param[in] input1 First source tensor. Data types supported: F32. Data layouts supported: NCHW/NHWC.
54 * @param[in] input2 Second source tensor. Data types and layouts supported: same as @p input1
55 * @param[out] output Destination tensor. Output dimensions are [W * H * num_priors * 4, 2]. Data type supported: same as @p input
56 * @param[in] info Prior box layer info.
57 */
58 void configure(const ITensor *input1, const ITensor *input2, ITensor *output, const PriorBoxLayerInfo &info);
59 /** Static function to check if given info will lead to a valid configuration of @ref NEPriorBoxLayerKernel
60 *
61 * @param[in] input1 First source tensor info. Data types supported: F32. Data layouts supported: NCHW/NHWC.
62 * @param[in] input2 Second source tensor info. Data types and layouts supported: same as @p input1
63 * @param[in] output Destination tensor info. Output dimensions are [W * H * num_priors * 4, 2]. Data type supported: same as @p input
64 * @param[in] info Prior box layer info.
65 *
66 * @return a status
67 */
68 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const PriorBoxLayerInfo &info);
69
70 // Inherited methods overridden:
71 void run(const Window &window, const ThreadInfo &info) override;
72
73private:
74 /** Stores the coordinates of the calculated prior boxes.
75 *
76 * @param[out] out Output pointer.
77 * @param[in] offset Output offset to write to.
78 * @param[in] center_x Center pixel value on x-axis.
79 * @param[in] center_y Center pixel value on y-axis.
80 * @param[in] box_width Prior box width.
81 * @param[in] box_height Prior box height.
82 * @param[in] width Input width.
83 * @param[in] height Input height.
84 */
Michalis Spyrou721c4cb2018-09-04 15:27:25 +010085 void store_coordinates(float *out, const int offset, const float center_x, const float center_y, const float box_width, const float box_height, const int width, const int height);
86 /** Function to calculate prior boxes.
87 *
88 * @param[in] window Input region on which to execute the kernel.
89 */
Michalis Spyrou721c4cb2018-09-04 15:27:25 +010090 void calculate_prior_boxes(const Window &window);
Michalis Spyrou3112e332018-11-21 15:44:55 +000091
Michalis Spyrou721c4cb2018-09-04 15:27:25 +010092 const ITensor *_input1;
93 const ITensor *_input2;
94 ITensor *_output;
95 PriorBoxLayerInfo _info;
96};
97} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000098#endif /* ARM_COMPUTE_NEPRIORBOXLAYERKERNEL_H */