blob: 0eae9eb788f70508f62f69faa2d765a824f27fed [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 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_NEHOGDESCRIPTORKERNEL_H__
25#define __ARM_COMPUTE_NEHOGDESCRIPTORKERNEL_H__
26
27#include "arm_compute/core/IHOG.h"
28#include "arm_compute/core/NEON/INEKernel.h"
29#include "arm_compute/core/Size2D.h"
30
31namespace arm_compute
32{
33class ITensor;
34
35/** NEON kernel to perform HOG Orientation Binning */
36class NEHOGOrientationBinningKernel : public INEKernel
37{
38public:
39 /** Default constructor */
40 NEHOGOrientationBinningKernel();
41 /** Prevent instances of this class from being copied (As this class contains pointers) */
42 NEHOGOrientationBinningKernel(const NEHOGOrientationBinningKernel &) = delete;
43 /** Prevent instances of this class from being copied (As this class contains pointers) */
44 NEHOGOrientationBinningKernel &operator=(const NEHOGOrientationBinningKernel &) = delete;
45 /** Allow instances of this class to be moved */
46 NEHOGOrientationBinningKernel(NEHOGOrientationBinningKernel &&) = default;
47 /** Allow instances of this class to be moved */
48 NEHOGOrientationBinningKernel &operator=(NEHOGOrientationBinningKernel &&) = default;
49 /** Default destructor */
50 ~NEHOGOrientationBinningKernel() = default;
51
52 /** Initialise the kernel's inputs, output and HOG's metadata
53 *
54 * @param[in] input_magnitude Input tensor which stores the magnitude of the gradient for each pixel. Data type supported: S16.
55 * @param[in] input_phase Input tensor which stores the phase of the gradient for each pixel. Data type supported: U8
56 * @param[out] output Output tensor which stores the local HOG for each cell. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per cell
57 * @param[in] hog_info HOG's metadata
58 */
59 void configure(const ITensor *input_magnitude, const ITensor *input_phase, ITensor *output, const HOGInfo *hog_info);
60
61 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010062 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063
64private:
65 /** Common signature for all the specialised block normalization functions
66 *
67 * @param[in] mag_row_ptr Pointer to the first row of the cell in the magnitude tensor
68 * @param[in] phase_row_ptr Pointer to the first row of the cell in the phase tensor
69 * @param[out] output_ptr Pointer to the output cell of hog space tensor
70 * @param[in] mag_stride Stride of the magnitude tensor
71 * @param[in] phase_stride Stride of the phase tensor
72 * @param[in] cell_width Width of the cell
73 * @param[in] cell_height Height of the cell
74 * @param[in] num_bins Number of bins for each cell
75 * @param[in] phase_scale Scale factor to apply to the phase in order to calculate the histogram index
76 */
77 using OrientBinFunc = void(const int16_t *__restrict mag_row_ptr, const uint8_t *__restrict phase_row_ptr, float *__restrict output_ptr, size_t mag_stride, size_t phase_stride, size_t cell_width,
78 size_t cell_height, size_t num_bins, float phase_scale);
79 /** Orientation binning function to use for the particular cell width passed to configure() */
80 OrientBinFunc *_func;
81 const ITensor *_input_magnitude;
82 const ITensor *_input_phase;
83 ITensor *_output;
84 size_t _cell_width;
85 size_t _cell_height;
86 size_t _num_bins;
87 float _phase_scale;
88};
89
90/** NEON kernel to perform HOG block normalization */
91class NEHOGBlockNormalizationKernel : public INEKernel
92{
93public:
94 /** Default constructor */
95 NEHOGBlockNormalizationKernel();
96 /** Prevent instances of this class from being copied (As this class contains pointers) */
97 NEHOGBlockNormalizationKernel(const NEHOGBlockNormalizationKernel &) = delete;
98 /** Prevent instances of this class from being copied (As this class contains pointers) */
99 NEHOGBlockNormalizationKernel &operator=(const NEHOGBlockNormalizationKernel &) = delete;
100 /** Allow instances of this class to be moved */
101 NEHOGBlockNormalizationKernel(NEHOGBlockNormalizationKernel &&) = default;
102 /** Allow instances of this class to be moved */
103 NEHOGBlockNormalizationKernel &operator=(NEHOGBlockNormalizationKernel &&) = default;
104 /** Default destructor */
105 ~NEHOGBlockNormalizationKernel() = default;
106
107 /** Initialise the kernel's input, output and HOG's metadata
108 *
109 * @param[in] input Input tensor which stores the local HOG for each cell. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per cell
110 * @param[out] output Output tensor which stores the normalised blocks. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per block
111 * @param[in] hog_info HOG's metadata
112 */
113 void configure(const ITensor *input, ITensor *output, const HOGInfo *hog_info);
114
115 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100116 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100117
118private:
119 /** Common signature for all the specialised block normalization functions
120 *
121 * @param[in] input_row_ptr Pointer to the first row of the block in the input hog space tensor
122 * @param[out] output_ptr Pointer to the output block of the hog normalized space
123 * @param[in] input_stride Stride of the input hog space tensor
124 * @param[in] num_cells_per_block_height Number of cells per block along the Y direction
125 * @param[in] num_bins_block_x Number of bins per block along the X direction
126 * @param[in] num_bins_block Number of total bins per block
127 * @param[in] l2_hyst_threshold Threshold to use for l2 hysteresis normalization
128 */
129 using BlockNormFunc = void(const float *input_row_ptr, float *output_ptr, size_t input_stride, size_t num_cells_per_block_height, size_t num_bins_block_x, size_t num_bins_block,
130 float l2_hyst_threshold);
131 /** Block normalization function to use for the particular normalization type passed to configure() */
132 BlockNormFunc *_func;
133 const ITensor *_input;
134 ITensor *_output;
135 Size2D _num_cells_per_block;
136 Size2D _num_cells_per_block_stride;
137 size_t _num_bins;
138 float _l2_hyst_threshold;
139};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100140} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100141#endif /* __ARM_COMPUTE_NEHOGDESCRIPTORKERNEL_H__ */