40 inline void configure_crop(
const ICLTensor *
input, ICLTensor *crop_boxes, ICLTensor *box_ind, ICLTensor *output, uint32_t crop_box_ind, Coordinates &start, Coordinates &
end, uint32_t &batch_index)
42 batch_index = *(
reinterpret_cast<int32_t *
>(box_ind->ptr_to_element(Coordinates(crop_box_ind))));
46 const float x0 = *
reinterpret_cast<const float *
>(crop_boxes->ptr_to_element(Coordinates(1, crop_box_ind)));
47 const float y0 = *
reinterpret_cast<const float *
>(crop_boxes->ptr_to_element(Coordinates(0, crop_box_ind)));
48 const float x1 = *
reinterpret_cast<const float *
>(crop_boxes->ptr_to_element(Coordinates(3, crop_box_ind)));
49 const float y1 = *
reinterpret_cast<const float *
>(crop_boxes->ptr_to_element(Coordinates(2, crop_box_ind)));
51 start = Coordinates(std::floor(x0 * (
input->info()->tensor_shape()[1] - 1) + 0.5f),
52 std::floor(y0 * (
input->info()->tensor_shape()[2] - 1) + 0.5f));
53 end = Coordinates(std::floor(x1 * (
input->info()->tensor_shape()[1] - 1) + 0.5f),
54 std::floor(y1 * (
input->info()->tensor_shape()[2] - 1) + 0.5f));
55 const TensorShape out_shape(
input->info()->tensor_shape()[0],
static_cast<uint32_t
>(abs(
end[0] - start[0])) + 1,
static_cast<uint32_t
>(abs(
end[1] - start[1])) + 1);
56 output->info()->set_tensor_shape(out_shape);
61 : _input(nullptr), _boxes(nullptr), _box_ind(nullptr), _output(nullptr), _num_boxes(0), _method(), _extrapolation_value(0), _scale(), _copy(), _crop_results(), _scaled_results(), _internal_functions()
125 for(
unsigned int num_box = 0; num_box <
_num_boxes; ++num_box)
127 auto crop_tensor = std::make_unique<CLTensor>();
130 crop_tensor->allocator()->init(crop_result_info);
133 auto scale_tensor = std::make_unique<CLTensor>();
136 scale_tensor->allocator()->init(scaled_result_info);
140 uint32_t batch_index;
145 auto scale_kernel = std::make_unique<CLScale>();
147 _scale.emplace_back(std::move(scale_kernel));
152 auto copy_kernel = std::make_unique<CLCopy>();
154 _copy.emplace_back(std::move(copy_kernel));
159 bool is_width_flipped =
end[0] < start[0];
160 bool is_height_flipped =
end[1] < start[1];
162 std::array<int32_t, 2> rows_out_of_bounds{ 0 };
164 std::array<int32_t, 2> cols_out_of_bounds{ 0 };
165 if(is_height_flipped)
168 rows_out_of_bounds[1] =
end[1] < 0 ? std::min(-
end[1],
static_cast<int32_t
>(
_crop_results[num_box].get()->
info()->dimension(2))) : 0;
172 rows_out_of_bounds[0] = start[1] < 0 ? std::min(-start[1],
static_cast<int32_t
>(
_crop_results[num_box].get()->
info()->dimension(2))) : 0;
178 cols_out_of_bounds[1] =
end[0] < 0 ? std::min(-
end[0],
static_cast<int32_t
>(
_crop_results[num_box].get()->
info()->dimension(1))) : 0;
182 cols_out_of_bounds[0] = start[0] < 0 ? std::min(-start[0],
static_cast<int32_t
>(
_crop_results[num_box].get()->
info()->dimension(1))) : 0;
206 if(rows_out_of_bounds[0] > 0)
208 Window slice_fill_rows_before(full_window);
210 auto kernel = std::make_unique<CLFill>();
211 kernel->configure(compile_context,
_crop_results[num_box].get(), extrapolation_value, &slice_fill_rows_before);
216 Window slice_in(full_window);
220 int rows_in_bounds =
static_cast<int32_t
>(
_crop_results[num_box].get()->info()->dimension(2)) - rows_out_of_bounds[0] - rows_out_of_bounds[1];
221 if(rows_in_bounds > 0)
224 if(cols_out_of_bounds[0] > 0)
226 Window slice_fill_cols_before(slice_in);
228 auto kernel = std::make_unique<CLFill>();
229 kernel->configure(compile_context,
_crop_results[num_box].get(), extrapolation_value, &slice_fill_cols_before);
234 if(cols_out_of_bounds[1] > 0)
236 Window slice_fill_cols_after(slice_in);
238 auto kernel = std::make_unique<CLFill>();
239 kernel->configure(compile_context,
_crop_results[num_box].get(), extrapolation_value, &slice_fill_cols_after);
245 int cols_in_bounds =
static_cast<int32_t
>(
_crop_results[num_box].get()->info()->dimension(1)) - cols_out_of_bounds[0] - cols_out_of_bounds[1];
246 if(cols_in_bounds > 0)
248 Coordinates2D start_in{ is_width_flipped ? start[0] - cols_out_of_bounds[0] : start[0] + cols_out_of_bounds[0],
249 is_height_flipped ? start[1] - rows_out_of_bounds[0] : start[1] + rows_out_of_bounds[0] };
250 Coordinates2D end_in{ is_width_flipped ? start_in.
x - cols_in_bounds + 1 : start_in.x + cols_in_bounds - 1,
251 is_height_flipped ? start_in.y - rows_in_bounds + 1 : start_in.y + rows_in_bounds - 1 };
252 auto kernel = std::make_unique<CLCrop>();
254 kernel->configure(compile_context,
_input,
_crop_results[num_box].get(), start_in, end_in, batch_index, extrapolation_value, &slice_in);
261 if(rows_out_of_bounds[1] > 0)
263 Window slice_fill_rows_after(full_window);
265 auto kernel = std::make_unique<CLFill>();
266 kernel->configure(compile_context,
_crop_results[num_box].get(), extrapolation_value, &slice_fill_rows_after);
286 for(
auto &kernel :
_scale)
291 for(
auto &kernel :
_copy)