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