40 inline void configure_crop(
const ICLTensor *
input,
41 ICLTensor *crop_boxes,
44 uint32_t crop_box_ind,
47 uint32_t &batch_index)
49 batch_index = *(
reinterpret_cast<int32_t *
>(box_ind->ptr_to_element(Coordinates(crop_box_ind))));
53 const float x0 = *
reinterpret_cast<const float *
>(crop_boxes->ptr_to_element(Coordinates(1, crop_box_ind)));
54 const float y0 = *
reinterpret_cast<const float *
>(crop_boxes->ptr_to_element(Coordinates(0, crop_box_ind)));
55 const float x1 = *
reinterpret_cast<const float *
>(crop_boxes->ptr_to_element(Coordinates(3, crop_box_ind)));
56 const float y1 = *
reinterpret_cast<const float *
>(crop_boxes->ptr_to_element(Coordinates(2, crop_box_ind)));
58 start = Coordinates(std::floor(x0 * (
input->info()->tensor_shape()[1] - 1) + 0.5f),
59 std::floor(y0 * (
input->info()->tensor_shape()[2] - 1) + 0.5f));
60 end = Coordinates(std::floor(x1 * (
input->info()->tensor_shape()[1] - 1) + 0.5f),
61 std::floor(y1 * (
input->info()->tensor_shape()[2] - 1) + 0.5f));
62 const TensorShape out_shape(
input->info()->tensor_shape()[0],
static_cast<uint32_t
>(abs(
end[0] - start[0])) + 1,
63 static_cast<uint32_t
>(abs(
end[1] - start[1])) + 1);
64 output->info()->set_tensor_shape(out_shape);
75 _extrapolation_value(0),
92 float extrapolation_value)
100 input->dimension(3) - 1, extrapolation_value));
117 float extrapolation_value)
120 extrapolation_value);
130 float extrapolation_value)
134 crop_size, method, extrapolation_value));
164 for (
unsigned int num_box = 0; num_box <
_num_boxes; ++num_box)
166 auto crop_tensor = std::make_unique<CLTensor>();
169 crop_tensor->allocator()->init(crop_result_info);
172 auto scale_tensor = std::make_unique<CLTensor>();
175 scale_tensor->allocator()->init(scaled_result_info);
179 uint32_t batch_index;
184 auto scale_kernel = std::make_unique<CLScale>();
185 scale_kernel->configure(
188 _scale.emplace_back(std::move(scale_kernel));
193 auto copy_kernel = std::make_unique<CLCopy>();
195 _copy.emplace_back(std::move(copy_kernel));
200 bool is_width_flipped =
end[0] < start[0];
201 bool is_height_flipped =
end[1] < start[1];
203 std::array<int32_t, 2> rows_out_of_bounds{0};
205 std::array<int32_t, 2> cols_out_of_bounds{0};
206 if (is_height_flipped)
212 rows_out_of_bounds[1] =
218 rows_out_of_bounds[0] =
220 ? std::min(-start[1],
static_cast<int32_t
>(
_crop_results[num_box].get()->
info()->dimension(2)))
227 if (is_width_flipped)
233 cols_out_of_bounds[1] =
239 cols_out_of_bounds[0] =
241 ? std::min(-start[0],
static_cast<int32_t
>(
_crop_results[num_box].get()->
info()->dimension(1)))
269 if (rows_out_of_bounds[0] > 0)
271 Window slice_fill_rows_before(full_window);
273 auto kernel = std::make_unique<CLFill>();
274 kernel->configure(compile_context,
_crop_results[num_box].get(), extrapolation_value,
275 &slice_fill_rows_before);
280 Window slice_in(full_window);
288 int rows_in_bounds =
static_cast<int32_t
>(
_crop_results[num_box].get()->info()->dimension(2)) -
289 rows_out_of_bounds[0] - rows_out_of_bounds[1];
290 if (rows_in_bounds > 0)
293 if (cols_out_of_bounds[0] > 0)
295 Window slice_fill_cols_before(slice_in);
297 auto kernel = std::make_unique<CLFill>();
298 kernel->configure(compile_context,
_crop_results[num_box].get(), extrapolation_value,
299 &slice_fill_cols_before);
304 if (cols_out_of_bounds[1] > 0)
306 Window slice_fill_cols_after(slice_in);
307 slice_fill_cols_after.
set(
310 auto kernel = std::make_unique<CLFill>();
311 kernel->configure(compile_context,
_crop_results[num_box].get(), extrapolation_value,
312 &slice_fill_cols_after);
318 int cols_in_bounds =
static_cast<int32_t
>(
_crop_results[num_box].get()->info()->dimension(1)) -
319 cols_out_of_bounds[0] - cols_out_of_bounds[1];
320 if (cols_in_bounds > 0)
323 is_width_flipped ? start[0] - cols_out_of_bounds[0] : start[0] + cols_out_of_bounds[0],
324 is_height_flipped ? start[1] - rows_out_of_bounds[0] : start[1] + rows_out_of_bounds[0]};
326 is_width_flipped ? start_in.
x - cols_in_bounds + 1 : start_in.x + cols_in_bounds - 1,
327 is_height_flipped ? start_in.y - rows_in_bounds + 1 : start_in.y + rows_in_bounds - 1};
328 auto kernel = std::make_unique<CLCrop>();
330 kernel->configure(compile_context,
_input,
_crop_results[num_box].get(), start_in, end_in, batch_index,
331 extrapolation_value, &slice_in);
338 if (rows_out_of_bounds[1] > 0)
340 Window slice_fill_rows_after(full_window);
341 slice_fill_rows_after.
set(
344 auto kernel = std::make_unique<CLFill>();
345 kernel->configure(compile_context,
_crop_results[num_box].get(), extrapolation_value,
346 &slice_fill_rows_after);
366 for (
auto &kernel :
_scale)
371 for (
auto &kernel :
_copy)