blob: c9eb8abc2986c60bbf9e44aad589c6596b0866c6 [file] [log] [blame]
Jenkinsb9abeae2018-11-22 11:58:08 +00001/*
Jenkins514be652019-02-28 12:25:18 +00002 * Copyright (c) 2019 ARM Limited.
Jenkinsb9abeae2018-11-22 11:58:08 +00003 *
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/CL/functions/CLGenerateProposalsLayer.h"
25
26#include "arm_compute/core/CL/ICLTensor.h"
27#include "arm_compute/core/Types.h"
28#include "support/ToolchainSupport.h"
29
30namespace arm_compute
31{
32CLGenerateProposalsLayer::CLGenerateProposalsLayer(std::shared_ptr<IMemoryManager> memory_manager)
Jenkins0e205f72019-11-28 16:53:35 +000033 : _memory_group(memory_manager),
Jenkinsb9abeae2018-11-22 11:58:08 +000034 _permute_deltas_kernel(),
35 _flatten_deltas_kernel(),
36 _permute_scores_kernel(),
37 _flatten_scores_kernel(),
38 _compute_anchors_kernel(),
39 _bounding_box_kernel(),
Jenkins0e205f72019-11-28 16:53:35 +000040 _pad_kernel(),
41 _dequantize_anchors(),
42 _dequantize_deltas(),
43 _quantize_all_proposals(),
44 _cpp_nms(memory_manager),
Jenkins514be652019-02-28 12:25:18 +000045 _is_nhwc(false),
Jenkins0e205f72019-11-28 16:53:35 +000046 _is_qasymm8(false),
Jenkinsb9abeae2018-11-22 11:58:08 +000047 _deltas_permuted(),
48 _deltas_flattened(),
Jenkins0e205f72019-11-28 16:53:35 +000049 _deltas_flattened_f32(),
Jenkinsb9abeae2018-11-22 11:58:08 +000050 _scores_permuted(),
51 _scores_flattened(),
52 _all_anchors(),
Jenkins0e205f72019-11-28 16:53:35 +000053 _all_anchors_f32(),
Jenkinsb9abeae2018-11-22 11:58:08 +000054 _all_proposals(),
Jenkins0e205f72019-11-28 16:53:35 +000055 _all_proposals_quantized(),
Jenkinsb9abeae2018-11-22 11:58:08 +000056 _keeps_nms_unused(),
57 _classes_nms_unused(),
58 _proposals_4_roi_values(),
Jenkins0e205f72019-11-28 16:53:35 +000059 _all_proposals_to_use(nullptr),
Jenkinsb9abeae2018-11-22 11:58:08 +000060 _num_valid_proposals(nullptr),
61 _scores_out(nullptr)
62{
63}
64
65void CLGenerateProposalsLayer::configure(const ICLTensor *scores, const ICLTensor *deltas, const ICLTensor *anchors, ICLTensor *proposals, ICLTensor *scores_out, ICLTensor *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(CLGenerateProposalsLayer::validate(scores->info(), deltas->info(), anchors->info(), proposals->info(), scores_out->info(), num_valid_proposals->info(), info));
70
Jenkins0e205f72019-11-28 16:53:35 +000071 _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();
Jenkinsb9abeae2018-11-22 11:58:08 +000085
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);
Jenkins0e205f72019-11-28 16:53:35 +000091 _deltas_flattened.allocator()->init(TensorInfo(flatten_shape_deltas, 1, scores_data_type, deltas->info()->quantization_info()));
Jenkinsb9abeae2018-11-22 11:58:08 +000092
93 // Permute and reshape deltas
Jenkins0e205f72019-11-28 16:53:35 +000094 _memory_group.manage(&_deltas_flattened);
Jenkins514be652019-02-28 12:25:18 +000095 if(!_is_nhwc)
96 {
97 _memory_group.manage(&_deltas_permuted);
Jenkins514be652019-02-28 12:25:18 +000098 _permute_deltas_kernel.configure(deltas, &_deltas_permuted, PermutationVector{ 2, 0, 1 });
99 _flatten_deltas_kernel.configure(&_deltas_permuted, &_deltas_flattened);
100 _deltas_permuted.allocator()->allocate();
101 }
102 else
103 {
Jenkins514be652019-02-28 12:25:18 +0000104 _flatten_deltas_kernel.configure(deltas, &_deltas_flattened);
105 }
Jenkinsb9abeae2018-11-22 11:58:08 +0000106
107 const TensorShape flatten_shape_scores(1, total_num_anchors);
Jenkins0e205f72019-11-28 16:53:35 +0000108 _scores_flattened.allocator()->init(TensorInfo(flatten_shape_scores, 1, scores_data_type, scores_qinfo));
Jenkinsb9abeae2018-11-22 11:58:08 +0000109
110 // Permute and reshape scores
Jenkins0e205f72019-11-28 16:53:35 +0000111 _memory_group.manage(&_scores_flattened);
Jenkins514be652019-02-28 12:25:18 +0000112 if(!_is_nhwc)
113 {
114 _memory_group.manage(&_scores_permuted);
Jenkins514be652019-02-28 12:25:18 +0000115 _permute_scores_kernel.configure(scores, &_scores_permuted, PermutationVector{ 2, 0, 1 });
116 _flatten_scores_kernel.configure(&_scores_permuted, &_scores_flattened);
117 _scores_permuted.allocator()->allocate();
118 }
119 else
120 {
Jenkins514be652019-02-28 12:25:18 +0000121 _flatten_scores_kernel.configure(scores, &_scores_flattened);
122 }
Jenkinsb9abeae2018-11-22 11:58:08 +0000123
Jenkins0e205f72019-11-28 16:53:35 +0000124 CLTensor *anchors_to_use = &_all_anchors;
125 CLTensor *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 }
Jenkinsb9abeae2018-11-22 11:58:08 +0000141 // Bounding box transform
142 _memory_group.manage(&_all_proposals);
143 BoundingBoxTransformInfo bbox_info(info.im_width(), info.im_height(), 1.f);
Jenkins0e205f72019-11-28 16:53:35 +0000144 _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();
Jenkinsb9abeae2018-11-22 11:58:08 +0000147
Jenkins0e205f72019-11-28 16:53:35 +0000148 _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 }
Jenkinsb9abeae2018-11-22 11:58:08 +0000158 // 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.
Jenkins0e205f72019-11-28 16:53:35 +0000168 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);
Jenkinsb9abeae2018-11-22 11:58:08 +0000170 auto_init_if_empty(*num_valid_proposals->info(), TensorShape(1), 1, DataType::U32);
171
172 // Initialize temporaries (unused) outputs
Jenkins0e205f72019-11-28 16:53:35 +0000173 _classes_nms_unused.allocator()->init(TensorInfo(TensorShape(scores_nms_size), 1, scores_data_type, scores_qinfo));
Jenkinsb9abeae2018-11-22 11:58:08 +0000174 _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);
Jenkins0e205f72019-11-28 16:53:35 +0000181 _cpp_nms.configure(&_scores_flattened, _all_proposals_to_use, nullptr, scores_out, &_proposals_4_roi_values, &_classes_nms_unused, nullptr, &_keeps_nms_unused, num_valid_proposals,
182 BoxNMSLimitInfo(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()));
Jenkinsb9abeae2018-11-22 11:58:08 +0000183 _keeps_nms_unused.allocator()->allocate();
184 _classes_nms_unused.allocator()->allocate();
Jenkins0e205f72019-11-28 16:53:35 +0000185 _all_proposals_to_use->allocator()->allocate();
Jenkinsb9abeae2018-11-22 11:58:08 +0000186 _scores_flattened.allocator()->allocate();
187
188 // Add the first column that represents the batch id. This will be all zeros, as we don't support multiple images
Jenkins0e205f72019-11-28 16:53:35 +0000189 _pad_kernel.configure(&_proposals_4_roi_values, proposals, PaddingList{ { 1, 0 } });
Jenkinsb9abeae2018-11-22 11:58:08 +0000190 _proposals_4_roi_values.allocator()->allocate();
Jenkinsb9abeae2018-11-22 11:58:08 +0000191}
192
193Status CLGenerateProposalsLayer::validate(const ITensorInfo *scores, const ITensorInfo *deltas, const ITensorInfo *anchors, const ITensorInfo *proposals, const ITensorInfo *scores_out,
194 const ITensorInfo *num_valid_proposals, const GenerateProposalsInfo &info)
195{
196 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(scores, deltas, anchors, proposals, scores_out, num_valid_proposals);
Jenkins0e205f72019-11-28 16:53:35 +0000197 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(scores, 1, DataType::QASYMM8, DataType::F16, DataType::F32);
Jenkins514be652019-02-28 12:25:18 +0000198 ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(scores, DataLayout::NCHW, DataLayout::NHWC);
199 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(scores, deltas);
Jenkins0e205f72019-11-28 16:53:35 +0000200 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(scores, deltas);
Jenkinsb9abeae2018-11-22 11:58:08 +0000201
Jenkins514be652019-02-28 12:25:18 +0000202 const int num_anchors = scores->dimension(get_data_layout_dimension_index(scores->data_layout(), DataLayoutDimension::CHANNEL));
203 const int feat_width = scores->dimension(get_data_layout_dimension_index(scores->data_layout(), DataLayoutDimension::WIDTH));
204 const int feat_height = scores->dimension(get_data_layout_dimension_index(scores->data_layout(), DataLayoutDimension::HEIGHT));
Jenkinsb9abeae2018-11-22 11:58:08 +0000205 const int num_images = scores->dimension(3);
206 const int total_num_anchors = num_anchors * feat_width * feat_height;
207 const int values_per_roi = info.values_per_roi();
208
Jenkins0e205f72019-11-28 16:53:35 +0000209 const bool is_qasymm8 = scores->data_type() == DataType::QASYMM8;
210
Jenkinsb9abeae2018-11-22 11:58:08 +0000211 ARM_COMPUTE_RETURN_ERROR_ON(num_images > 1);
212
Jenkins0e205f72019-11-28 16:53:35 +0000213 if(is_qasymm8)
214 {
215 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(anchors, 1, DataType::QSYMM16);
216 const UniformQuantizationInfo anchors_qinfo = anchors->quantization_info().uniform();
217 ARM_COMPUTE_RETURN_ERROR_ON(anchors_qinfo.scale != 0.125f);
218 }
219
Jenkinsb9abeae2018-11-22 11:58:08 +0000220 TensorInfo all_anchors_info(anchors->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true));
221 ARM_COMPUTE_RETURN_ON_ERROR(CLComputeAllAnchorsKernel::validate(anchors, &all_anchors_info, ComputeAnchorsInfo(feat_width, feat_height, info.spatial_scale())));
222
223 TensorInfo deltas_permuted_info = deltas->clone()->set_tensor_shape(TensorShape(values_per_roi * num_anchors, feat_width, feat_height)).set_is_resizable(true);
Jenkins514be652019-02-28 12:25:18 +0000224 TensorInfo scores_permuted_info = scores->clone()->set_tensor_shape(TensorShape(num_anchors, feat_width, feat_height)).set_is_resizable(true);
225 if(scores->data_layout() == DataLayout::NHWC)
226 {
227 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(deltas, &deltas_permuted_info);
228 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(scores, &scores_permuted_info);
229 }
230 else
231 {
232 ARM_COMPUTE_RETURN_ON_ERROR(CLPermuteKernel::validate(deltas, &deltas_permuted_info, PermutationVector{ 2, 0, 1 }));
233 ARM_COMPUTE_RETURN_ON_ERROR(CLPermuteKernel::validate(scores, &scores_permuted_info, PermutationVector{ 2, 0, 1 }));
234 }
Jenkinsb9abeae2018-11-22 11:58:08 +0000235
236 TensorInfo deltas_flattened_info(deltas->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true));
237 ARM_COMPUTE_RETURN_ON_ERROR(CLReshapeLayerKernel::validate(&deltas_permuted_info, &deltas_flattened_info));
238
Jenkins0e205f72019-11-28 16:53:35 +0000239 TensorInfo scores_flattened_info(scores->clone()->set_tensor_shape(TensorShape(1, total_num_anchors)).set_is_resizable(true));
Jenkinsb9abeae2018-11-22 11:58:08 +0000240 TensorInfo proposals_4_roi_values(deltas->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true));
241
242 ARM_COMPUTE_RETURN_ON_ERROR(CLReshapeLayerKernel::validate(&scores_permuted_info, &scores_flattened_info));
Jenkinsb9abeae2018-11-22 11:58:08 +0000243
Jenkins0e205f72019-11-28 16:53:35 +0000244 TensorInfo *proposals_4_roi_values_to_use = &proposals_4_roi_values;
245 TensorInfo proposals_4_roi_values_quantized(deltas->clone()->set_tensor_shape(TensorShape(values_per_roi, total_num_anchors)).set_is_resizable(true));
246 proposals_4_roi_values_quantized.set_data_type(DataType::QASYMM16).set_quantization_info(QuantizationInfo(0.125f, 0));
247 if(is_qasymm8)
248 {
249 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));
250 ARM_COMPUTE_RETURN_ON_ERROR(CLDequantizationLayerKernel::validate(&all_anchors_info, &all_anchors_f32_info));
251
252 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));
253 ARM_COMPUTE_RETURN_ON_ERROR(CLDequantizationLayerKernel::validate(&deltas_flattened_info, &deltas_flattened_f32_info));
254
255 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));
256 ARM_COMPUTE_RETURN_ON_ERROR(CLBoundingBoxTransformKernel::validate(&all_anchors_f32_info, &proposals_4_roi_values_f32, &deltas_flattened_f32_info,
257 BoundingBoxTransformInfo(info.im_width(), info.im_height(), 1.f)));
258
259 ARM_COMPUTE_RETURN_ON_ERROR(CLQuantizationLayerKernel::validate(&proposals_4_roi_values_f32, &proposals_4_roi_values_quantized));
260 proposals_4_roi_values_to_use = &proposals_4_roi_values_quantized;
261 }
262 else
263 {
264 ARM_COMPUTE_RETURN_ON_ERROR(CLBoundingBoxTransformKernel::validate(&all_anchors_info, &proposals_4_roi_values, &deltas_flattened_info,
265 BoundingBoxTransformInfo(info.im_width(), info.im_height(), 1.f)));
266 }
267
268 ARM_COMPUTE_RETURN_ON_ERROR(CLPadLayerKernel::validate(proposals_4_roi_values_to_use, proposals, PaddingList{ { 1, 0 } }));
Jenkinsb9abeae2018-11-22 11:58:08 +0000269
270 if(num_valid_proposals->total_size() > 0)
271 {
272 ARM_COMPUTE_RETURN_ERROR_ON(num_valid_proposals->num_dimensions() > 1);
273 ARM_COMPUTE_RETURN_ERROR_ON(num_valid_proposals->dimension(0) > 1);
274 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(num_valid_proposals, 1, DataType::U32);
275 }
276
277 if(proposals->total_size() > 0)
278 {
279 ARM_COMPUTE_RETURN_ERROR_ON(proposals->num_dimensions() > 2);
280 ARM_COMPUTE_RETURN_ERROR_ON(proposals->dimension(0) != size_t(values_per_roi) + 1);
281 ARM_COMPUTE_RETURN_ERROR_ON(proposals->dimension(1) != size_t(total_num_anchors));
Jenkins0e205f72019-11-28 16:53:35 +0000282 if(is_qasymm8)
283 {
284 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(proposals, 1, DataType::QASYMM16);
285 const UniformQuantizationInfo proposals_qinfo = proposals->quantization_info().uniform();
286 ARM_COMPUTE_RETURN_ERROR_ON(proposals_qinfo.scale != 0.125f);
287 ARM_COMPUTE_RETURN_ERROR_ON(proposals_qinfo.offset != 0);
288 }
289 else
290 {
291 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(proposals, scores);
292 }
Jenkinsb9abeae2018-11-22 11:58:08 +0000293 }
294
295 if(scores_out->total_size() > 0)
296 {
297 ARM_COMPUTE_RETURN_ERROR_ON(scores_out->num_dimensions() > 1);
298 ARM_COMPUTE_RETURN_ERROR_ON(scores_out->dimension(0) != size_t(total_num_anchors));
299 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(scores_out, scores);
300 }
301
302 return Status{};
303}
304
305void CLGenerateProposalsLayer::run_cpp_nms_kernel()
306{
307 // Map inputs
308 _scores_flattened.map(true);
Jenkins0e205f72019-11-28 16:53:35 +0000309 _all_proposals_to_use->map(true);
Jenkinsb9abeae2018-11-22 11:58:08 +0000310
311 // Map outputs
312 _scores_out->map(CLScheduler::get().queue(), true);
313 _proposals_4_roi_values.map(CLScheduler::get().queue(), true);
314 _num_valid_proposals->map(CLScheduler::get().queue(), true);
315 _keeps_nms_unused.map(true);
316 _classes_nms_unused.map(true);
317
318 // Run nms
Jenkins0e205f72019-11-28 16:53:35 +0000319 _cpp_nms.run();
Jenkinsb9abeae2018-11-22 11:58:08 +0000320
321 // Unmap outputs
322 _keeps_nms_unused.unmap();
323 _classes_nms_unused.unmap();
324 _scores_out->unmap(CLScheduler::get().queue());
325 _proposals_4_roi_values.unmap(CLScheduler::get().queue());
326 _num_valid_proposals->unmap(CLScheduler::get().queue());
327
328 // Unmap inputs
329 _scores_flattened.unmap();
Jenkins0e205f72019-11-28 16:53:35 +0000330 _all_proposals_to_use->unmap();
Jenkinsb9abeae2018-11-22 11:58:08 +0000331}
332
333void CLGenerateProposalsLayer::run()
334{
335 // Acquire all the temporaries
Jenkins4ba87db2019-05-23 17:11:51 +0100336 MemoryGroupResourceScope scope_mg(_memory_group);
Jenkinsb9abeae2018-11-22 11:58:08 +0000337
338 // Compute all the anchors
339 CLScheduler::get().enqueue(_compute_anchors_kernel, false);
340
341 // Transpose and reshape the inputs
Jenkins514be652019-02-28 12:25:18 +0000342 if(!_is_nhwc)
343 {
344 CLScheduler::get().enqueue(_permute_deltas_kernel, false);
345 CLScheduler::get().enqueue(_permute_scores_kernel, false);
346 }
Jenkinsb9abeae2018-11-22 11:58:08 +0000347 CLScheduler::get().enqueue(_flatten_deltas_kernel, false);
Jenkinsb9abeae2018-11-22 11:58:08 +0000348 CLScheduler::get().enqueue(_flatten_scores_kernel, false);
349
Jenkins0e205f72019-11-28 16:53:35 +0000350 if(_is_qasymm8)
351 {
352 CLScheduler::get().enqueue(_dequantize_anchors, false);
353 CLScheduler::get().enqueue(_dequantize_deltas, false);
354 }
355
Jenkinsb9abeae2018-11-22 11:58:08 +0000356 // Build the boxes
357 CLScheduler::get().enqueue(_bounding_box_kernel, false);
Jenkins0e205f72019-11-28 16:53:35 +0000358
359 if(_is_qasymm8)
360 {
361 CLScheduler::get().enqueue(_quantize_all_proposals, false);
362 }
363
Jenkinsb9abeae2018-11-22 11:58:08 +0000364 // Non maxima suppression
365 run_cpp_nms_kernel();
366 // Add dummy batch indexes
Jenkins0e205f72019-11-28 16:53:35 +0000367 CLScheduler::get().enqueue(_pad_kernel, true);
Jenkinsb9abeae2018-11-22 11:58:08 +0000368}
369} // namespace arm_compute