blob: 13210a06cd691b421fa2035521b283e629d3fb64 [file] [log] [blame]
Pablo Telloc9564cb2019-09-13 10:20:25 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
Pablo Telloc9564cb2019-09-13 10:20: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 */
24#include "arm_compute/runtime/NEON/functions/NEGenerateProposalsLayer.h"
25
26#include "arm_compute/core/Types.h"
27#include "arm_compute/runtime/NEON/NEScheduler.h"
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010028#include "src/core/helpers/AutoConfiguration.h"
Pablo Telloc9564cb2019-09-13 10:20:25 +010029
30namespace arm_compute
31{
32NEGenerateProposalsLayer::NEGenerateProposalsLayer(std::shared_ptr<IMemoryManager> memory_manager)
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +010033 : _memory_group(memory_manager),
Pablo Telloc9564cb2019-09-13 10:20:25 +010034 _permute_deltas_kernel(),
Michalis Spyroubcd23522020-05-21 15:02:36 +010035 _flatten_deltas(),
Pablo Telloc9564cb2019-09-13 10:20:25 +010036 _permute_scores_kernel(),
Michalis Spyroubcd23522020-05-21 15:02:36 +010037 _flatten_scores(),
Pablo Telloc9564cb2019-09-13 10:20:25 +010038 _compute_anchors_kernel(),
39 _bounding_box_kernel(),
Michele Di Giorgio4c268b92019-09-20 14:01:48 +010040 _pad_kernel(),
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +010041 _dequantize_anchors(),
42 _dequantize_deltas(),
43 _quantize_all_proposals(),
44 _cpp_nms(memory_manager),
Pablo Telloc9564cb2019-09-13 10:20:25 +010045 _is_nhwc(false),
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +010046 _is_qasymm8(false),
Pablo Telloc9564cb2019-09-13 10:20:25 +010047 _deltas_permuted(),
48 _deltas_flattened(),
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +010049 _deltas_flattened_f32(),
Pablo Telloc9564cb2019-09-13 10:20:25 +010050 _scores_permuted(),
51 _scores_flattened(),
52 _all_anchors(),
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +010053 _all_anchors_f32(),
Pablo Telloc9564cb2019-09-13 10:20:25 +010054 _all_proposals(),
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +010055 _all_proposals_quantized(),
Pablo Telloc9564cb2019-09-13 10:20:25 +010056 _keeps_nms_unused(),
57 _classes_nms_unused(),
58 _proposals_4_roi_values(),
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +010059 _all_proposals_to_use(nullptr),
Pablo Telloc9564cb2019-09-13 10:20:25 +010060 _num_valid_proposals(nullptr),
61 _scores_out(nullptr)
62{
63}
64
65void NEGenerateProposalsLayer::configure(const ITensor *scores, const ITensor *deltas, const ITensor *anchors, ITensor *proposals, ITensor *scores_out, ITensor *num_valid_proposals,
66 const GenerateProposalsInfo &info)
67{
68 ARM_COMPUTE_ERROR_ON_NULLPTR(scores, deltas, anchors, proposals, scores_out, num_valid_proposals);
69 ARM_COMPUTE_ERROR_THROW_ON(NEGenerateProposalsLayer::validate(scores->info(), deltas->info(), anchors->info(), proposals->info(), scores_out->info(), num_valid_proposals->info(), info));
70
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +010071 _is_nhwc = scores->info()->data_layout() == DataLayout::NHWC;
72 const DataType scores_data_type = scores->info()->data_type();
73 _is_qasymm8 = scores_data_type == DataType::QASYMM8;
74 const int num_anchors = scores->info()->dimension(get_data_layout_dimension_index(scores->info()->data_layout(), DataLayoutDimension::CHANNEL));
75 const int feat_width = scores->info()->dimension(get_data_layout_dimension_index(scores->info()->data_layout(), DataLayoutDimension::WIDTH));
76 const int feat_height = scores->info()->dimension(get_data_layout_dimension_index(scores->info()->data_layout(), DataLayoutDimension::HEIGHT));
77 const int total_num_anchors = num_anchors * feat_width * feat_height;
78 const int pre_nms_topN = info.pre_nms_topN();
79 const int post_nms_topN = info.post_nms_topN();
80 const size_t values_per_roi = info.values_per_roi();
81
82 const QuantizationInfo scores_qinfo = scores->info()->quantization_info();
83 const DataType rois_data_type = (_is_qasymm8) ? DataType::QASYMM16 : scores_data_type;
84 const QuantizationInfo rois_qinfo = (_is_qasymm8) ? QuantizationInfo(0.125f, 0) : scores->info()->quantization_info();
Pablo Telloc9564cb2019-09-13 10:20:25 +010085
86 // Compute all the anchors
87 _memory_group.manage(&_all_anchors);
88 _compute_anchors_kernel.configure(anchors, &_all_anchors, ComputeAnchorsInfo(feat_width, feat_height, info.spatial_scale()));
89
90 const TensorShape flatten_shape_deltas(values_per_roi, total_num_anchors);
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +010091 _deltas_flattened.allocator()->init(TensorInfo(flatten_shape_deltas, 1, scores_data_type, deltas->info()->quantization_info()));
Pablo Telloc9564cb2019-09-13 10:20:25 +010092
93 // Permute and reshape deltas
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +010094 _memory_group.manage(&_deltas_flattened);
Pablo Telloc9564cb2019-09-13 10:20:25 +010095 if(!_is_nhwc)
96 {
97 _memory_group.manage(&_deltas_permuted);
98 _permute_deltas_kernel.configure(deltas, &_deltas_permuted, PermutationVector{ 2, 0, 1 });
Michalis Spyroubcd23522020-05-21 15:02:36 +010099 _flatten_deltas.configure(&_deltas_permuted, &_deltas_flattened);
Pablo Telloc9564cb2019-09-13 10:20:25 +0100100 _deltas_permuted.allocator()->allocate();
101 }
102 else
103 {
Michalis Spyroubcd23522020-05-21 15:02:36 +0100104 _flatten_deltas.configure(deltas, &_deltas_flattened);
Pablo Telloc9564cb2019-09-13 10:20:25 +0100105 }
106
107 const TensorShape flatten_shape_scores(1, total_num_anchors);
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100108 _scores_flattened.allocator()->init(TensorInfo(flatten_shape_scores, 1, scores_data_type, scores_qinfo));
109
Pablo Telloc9564cb2019-09-13 10:20:25 +0100110 // Permute and reshape scores
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100111 _memory_group.manage(&_scores_flattened);
Pablo Telloc9564cb2019-09-13 10:20:25 +0100112 if(!_is_nhwc)
113 {
114 _memory_group.manage(&_scores_permuted);
115 _permute_scores_kernel.configure(scores, &_scores_permuted, PermutationVector{ 2, 0, 1 });
Michalis Spyroubcd23522020-05-21 15:02:36 +0100116 _flatten_scores.configure(&_scores_permuted, &_scores_flattened);
Pablo Telloc9564cb2019-09-13 10:20:25 +0100117 _scores_permuted.allocator()->allocate();
118 }
119 else
120 {
Michalis Spyroubcd23522020-05-21 15:02:36 +0100121 _flatten_scores.configure(scores, &_scores_flattened);
Pablo Telloc9564cb2019-09-13 10:20:25 +0100122 }
123
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100124 Tensor *anchors_to_use = &_all_anchors;
125 Tensor *deltas_to_use = &_deltas_flattened;
126 if(_is_qasymm8)
127 {
128 _all_anchors_f32.allocator()->init(TensorInfo(_all_anchors.info()->tensor_shape(), 1, DataType::F32));
129 _deltas_flattened_f32.allocator()->init(TensorInfo(_deltas_flattened.info()->tensor_shape(), 1, DataType::F32));
130 _memory_group.manage(&_all_anchors_f32);
131 _memory_group.manage(&_deltas_flattened_f32);
132 // Dequantize anchors to float
133 _dequantize_anchors.configure(&_all_anchors, &_all_anchors_f32);
134 _all_anchors.allocator()->allocate();
135 anchors_to_use = &_all_anchors_f32;
136 // Dequantize deltas to float
137 _dequantize_deltas.configure(&_deltas_flattened, &_deltas_flattened_f32);
138 _deltas_flattened.allocator()->allocate();
139 deltas_to_use = &_deltas_flattened_f32;
140 }
Pablo Telloc9564cb2019-09-13 10:20:25 +0100141 // Bounding box transform
142 _memory_group.manage(&_all_proposals);
143 BoundingBoxTransformInfo bbox_info(info.im_width(), info.im_height(), 1.f);
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100144 _bounding_box_kernel.configure(anchors_to_use, &_all_proposals, deltas_to_use, bbox_info);
145 deltas_to_use->allocator()->allocate();
146 anchors_to_use->allocator()->allocate();
Pablo Telloc9564cb2019-09-13 10:20:25 +0100147
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100148 _all_proposals_to_use = &_all_proposals;
149 if(_is_qasymm8)
150 {
151 _memory_group.manage(&_all_proposals_quantized);
152 // Requantize all_proposals to QASYMM16 with 0.125 scale and 0 offset
153 _all_proposals_quantized.allocator()->init(TensorInfo(_all_proposals.info()->tensor_shape(), 1, DataType::QASYMM16, QuantizationInfo(0.125f, 0)));
154 _quantize_all_proposals.configure(&_all_proposals, &_all_proposals_quantized);
155 _all_proposals.allocator()->allocate();
156 _all_proposals_to_use = &_all_proposals_quantized;
157 }
Pablo Telloc9564cb2019-09-13 10:20:25 +0100158 // The original layer implementation first selects the best pre_nms_topN anchors (thus having a lightweight sort)
159 // that are then transformed by bbox_transform. The boxes generated are then fed into a non-sorting NMS operation.
160 // Since we are reusing the NMS layer and we don't implement any CL/sort, we let NMS do the sorting (of all the input)
161 // and the filtering
162 const int scores_nms_size = std::min<int>(std::min<int>(post_nms_topN, pre_nms_topN), total_num_anchors);
163 const float min_size_scaled = info.min_size() * info.im_scale();
164 _memory_group.manage(&_classes_nms_unused);
165 _memory_group.manage(&_keeps_nms_unused);
166
167 // Note that NMS needs outputs preinitialized.
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100168 auto_init_if_empty(*scores_out->info(), TensorShape(scores_nms_size), 1, scores_data_type, scores_qinfo);
169 auto_init_if_empty(*_proposals_4_roi_values.info(), TensorShape(values_per_roi, scores_nms_size), 1, rois_data_type, rois_qinfo);
170 auto_init_if_empty(*num_valid_proposals->info(), TensorShape(1), 1, DataType::U32);
Pablo Telloc9564cb2019-09-13 10:20:25 +0100171
172 // Initialize temporaries (unused) outputs
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100173 _classes_nms_unused.allocator()->init(TensorInfo(TensorShape(scores_nms_size), 1, scores_data_type, scores_qinfo));
Pablo Telloc9564cb2019-09-13 10:20:25 +0100174 _keeps_nms_unused.allocator()->init(*scores_out->info());
175
176 // Save the output (to map and unmap them at run)
177 _scores_out = scores_out;
178 _num_valid_proposals = num_valid_proposals;
179
180 _memory_group.manage(&_proposals_4_roi_values);
181
182 const BoxNMSLimitInfo box_nms_info(0.0f, info.nms_thres(), scores_nms_size, false, NMSType::LINEAR, 0.5f, 0.001f, true, min_size_scaled, info.im_width(), info.im_height());
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100183 _cpp_nms.configure(&_scores_flattened /*scores_in*/,
184 _all_proposals_to_use /*boxes_in,*/,
185 nullptr /* batch_splits_in*/,
186 scores_out /* scores_out*/,
187 &_proposals_4_roi_values /*boxes_out*/,
188 &_classes_nms_unused /*classes*/,
189 nullptr /*batch_splits_out*/,
190 &_keeps_nms_unused /*keeps*/,
191 num_valid_proposals /* keeps_size*/,
192 box_nms_info);
Pablo Telloc9564cb2019-09-13 10:20:25 +0100193
194 _keeps_nms_unused.allocator()->allocate();
195 _classes_nms_unused.allocator()->allocate();
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100196 _all_proposals_to_use->allocator()->allocate();
Pablo Telloc9564cb2019-09-13 10:20:25 +0100197 _scores_flattened.allocator()->allocate();
198
199 // Add the first column that represents the batch id. This will be all zeros, as we don't support multiple images
Michele Di Giorgio4c268b92019-09-20 14:01:48 +0100200 _pad_kernel.configure(&_proposals_4_roi_values, proposals, PaddingList{ { 1, 0 } });
Pablo Telloc9564cb2019-09-13 10:20:25 +0100201 _proposals_4_roi_values.allocator()->allocate();
Pablo Telloc9564cb2019-09-13 10:20:25 +0100202}
203
204Status NEGenerateProposalsLayer::validate(const ITensorInfo *scores, const ITensorInfo *deltas, const ITensorInfo *anchors, const ITensorInfo *proposals, const ITensorInfo *scores_out,
205 const ITensorInfo *num_valid_proposals, const GenerateProposalsInfo &info)
206{
207 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(scores, deltas, anchors, proposals, scores_out, num_valid_proposals);
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100208 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(scores, 1, DataType::QASYMM8, DataType::F16, DataType::F32);
Pablo Telloc9564cb2019-09-13 10:20:25 +0100209 ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(scores, DataLayout::NCHW, DataLayout::NHWC);
210 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(scores, deltas);
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100211 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(scores, deltas);
Pablo Telloc9564cb2019-09-13 10:20:25 +0100212
213 const int num_anchors = scores->dimension(get_data_layout_dimension_index(scores->data_layout(), DataLayoutDimension::CHANNEL));
214 const int feat_width = scores->dimension(get_data_layout_dimension_index(scores->data_layout(), DataLayoutDimension::WIDTH));
215 const int feat_height = scores->dimension(get_data_layout_dimension_index(scores->data_layout(), DataLayoutDimension::HEIGHT));
216 const int num_images = scores->dimension(3);
217 const int total_num_anchors = num_anchors * feat_width * feat_height;
218 const int values_per_roi = info.values_per_roi();
219
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100220 const bool is_qasymm8 = scores->data_type() == DataType::QASYMM8;
221
Pablo Telloc9564cb2019-09-13 10:20:25 +0100222 ARM_COMPUTE_RETURN_ERROR_ON(num_images > 1);
223
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100224 if(is_qasymm8)
225 {
226 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(anchors, 1, DataType::QSYMM16);
227 const UniformQuantizationInfo anchors_qinfo = anchors->quantization_info().uniform();
228 ARM_COMPUTE_RETURN_ERROR_ON(anchors_qinfo.scale != 0.125f);
229 }
230
Pablo Telloc9564cb2019-09-13 10:20:25 +0100231 TensorInfo all_anchors_info(anchors->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true));
232 ARM_COMPUTE_RETURN_ON_ERROR(NEComputeAllAnchorsKernel::validate(anchors, &all_anchors_info, ComputeAnchorsInfo(feat_width, feat_height, info.spatial_scale())));
233
234 TensorInfo deltas_permuted_info = deltas->clone()->set_tensor_shape(TensorShape(values_per_roi * num_anchors, feat_width, feat_height)).set_is_resizable(true);
235 TensorInfo scores_permuted_info = scores->clone()->set_tensor_shape(TensorShape(num_anchors, feat_width, feat_height)).set_is_resizable(true);
236 if(scores->data_layout() == DataLayout::NHWC)
237 {
238 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(deltas, &deltas_permuted_info);
239 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(scores, &scores_permuted_info);
240 }
241 else
242 {
243 ARM_COMPUTE_RETURN_ON_ERROR(NEPermuteKernel::validate(deltas, &deltas_permuted_info, PermutationVector{ 2, 0, 1 }));
244 ARM_COMPUTE_RETURN_ON_ERROR(NEPermuteKernel::validate(scores, &scores_permuted_info, PermutationVector{ 2, 0, 1 }));
245 }
246
247 TensorInfo deltas_flattened_info(deltas->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true));
Michalis Spyroubcd23522020-05-21 15:02:36 +0100248 ARM_COMPUTE_RETURN_ON_ERROR(NEReshapeLayer::validate(&deltas_permuted_info, &deltas_flattened_info));
Pablo Telloc9564cb2019-09-13 10:20:25 +0100249
250 TensorInfo scores_flattened_info(scores->clone()->set_tensor_shape(TensorShape(1, total_num_anchors)).set_is_resizable(true));
251 TensorInfo proposals_4_roi_values(deltas->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true));
252
Michalis Spyroubcd23522020-05-21 15:02:36 +0100253 ARM_COMPUTE_RETURN_ON_ERROR(NEReshapeLayer::validate(&scores_permuted_info, &scores_flattened_info));
Pablo Telloc9564cb2019-09-13 10:20:25 +0100254
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100255 TensorInfo *proposals_4_roi_values_to_use = &proposals_4_roi_values;
256 TensorInfo proposals_4_roi_values_quantized(deltas->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true));
257 proposals_4_roi_values_quantized.set_data_type(DataType::QASYMM16).set_quantization_info(QuantizationInfo(0.125f, 0));
258 if(is_qasymm8)
259 {
260 TensorInfo all_anchors_f32_info(anchors->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true).set_data_type(DataType::F32));
261 ARM_COMPUTE_RETURN_ON_ERROR(NEDequantizationLayerKernel::validate(&all_anchors_info, &all_anchors_f32_info));
262
263 TensorInfo deltas_flattened_f32_info(deltas->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true).set_data_type(DataType::F32));
264 ARM_COMPUTE_RETURN_ON_ERROR(NEDequantizationLayerKernel::validate(&deltas_flattened_info, &deltas_flattened_f32_info));
265
266 TensorInfo proposals_4_roi_values_f32(deltas->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true).set_data_type(DataType::F32));
267 ARM_COMPUTE_RETURN_ON_ERROR(NEBoundingBoxTransformKernel::validate(&all_anchors_f32_info, &proposals_4_roi_values_f32, &deltas_flattened_f32_info,
268 BoundingBoxTransformInfo(info.im_width(), info.im_height(), 1.f)));
269
270 ARM_COMPUTE_RETURN_ON_ERROR(NEQuantizationLayerKernel::validate(&proposals_4_roi_values_f32, &proposals_4_roi_values_quantized));
271 proposals_4_roi_values_to_use = &proposals_4_roi_values_quantized;
272 }
273 else
274 {
275 ARM_COMPUTE_RETURN_ON_ERROR(NEBoundingBoxTransformKernel::validate(&all_anchors_info, &proposals_4_roi_values, &deltas_flattened_info,
276 BoundingBoxTransformInfo(info.im_width(), info.im_height(), 1.f)));
277 }
278
279 ARM_COMPUTE_RETURN_ON_ERROR(NEPadLayerKernel::validate(proposals_4_roi_values_to_use, proposals, PaddingList{ { 1, 0 } }));
Pablo Telloc9564cb2019-09-13 10:20:25 +0100280
281 if(num_valid_proposals->total_size() > 0)
282 {
283 ARM_COMPUTE_RETURN_ERROR_ON(num_valid_proposals->num_dimensions() > 1);
284 ARM_COMPUTE_RETURN_ERROR_ON(num_valid_proposals->dimension(0) > 1);
285 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(num_valid_proposals, 1, DataType::U32);
286 }
287
288 if(proposals->total_size() > 0)
289 {
290 ARM_COMPUTE_RETURN_ERROR_ON(proposals->num_dimensions() > 2);
291 ARM_COMPUTE_RETURN_ERROR_ON(proposals->dimension(0) != size_t(values_per_roi) + 1);
292 ARM_COMPUTE_RETURN_ERROR_ON(proposals->dimension(1) != size_t(total_num_anchors));
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100293 if(is_qasymm8)
294 {
295 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(proposals, 1, DataType::QASYMM16);
296 const UniformQuantizationInfo proposals_qinfo = proposals->quantization_info().uniform();
297 ARM_COMPUTE_RETURN_ERROR_ON(proposals_qinfo.scale != 0.125f);
298 ARM_COMPUTE_RETURN_ERROR_ON(proposals_qinfo.offset != 0);
299 }
300 else
301 {
302 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(proposals, scores);
303 }
Pablo Telloc9564cb2019-09-13 10:20:25 +0100304 }
305
306 if(scores_out->total_size() > 0)
307 {
308 ARM_COMPUTE_RETURN_ERROR_ON(scores_out->num_dimensions() > 1);
309 ARM_COMPUTE_RETURN_ERROR_ON(scores_out->dimension(0) != size_t(total_num_anchors));
310 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(scores_out, scores);
311 }
312
313 return Status{};
314}
315
316void NEGenerateProposalsLayer::run()
317{
318 // Acquire all the temporaries
319 MemoryGroupResourceScope scope_mg(_memory_group);
320
321 // Compute all the anchors
322 NEScheduler::get().schedule(&_compute_anchors_kernel, Window::DimY);
323
324 // Transpose and reshape the inputs
325 if(!_is_nhwc)
326 {
327 NEScheduler::get().schedule(&_permute_deltas_kernel, Window::DimY);
328 NEScheduler::get().schedule(&_permute_scores_kernel, Window::DimY);
329 }
330
Michalis Spyroubcd23522020-05-21 15:02:36 +0100331 _flatten_deltas.run();
332 _flatten_scores.run();
Pablo Telloc9564cb2019-09-13 10:20:25 +0100333
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100334 if(_is_qasymm8)
335 {
336 NEScheduler::get().schedule(&_dequantize_anchors, Window::DimY);
337 NEScheduler::get().schedule(&_dequantize_deltas, Window::DimY);
338 }
339
Pablo Telloc9564cb2019-09-13 10:20:25 +0100340 // Build the boxes
341 NEScheduler::get().schedule(&_bounding_box_kernel, Window::DimY);
342
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100343 if(_is_qasymm8)
344 {
345 NEScheduler::get().schedule(&_quantize_all_proposals, Window::DimY);
346 }
347
Pablo Telloc9564cb2019-09-13 10:20:25 +0100348 // Non maxima suppression
Michele Di Giorgio58c71ef2019-09-30 15:03:21 +0100349 _cpp_nms.run();
Pablo Telloc9564cb2019-09-13 10:20:25 +0100350
351 // Add dummy batch indexes
Michele Di Giorgio4c268b92019-09-20 14:01:48 +0100352 NEScheduler::get().schedule(&_pad_kernel, Window::DimY);
Pablo Telloc9564cb2019-09-13 10:20:25 +0100353}
354} // namespace arm_compute