| 75 | } |
| 76 | |
| 77 | void NECropResize::configure(const ITensor *input, |
| 78 | const ITensor *boxes, |
| 79 | const ITensor *box_ind, |
| 80 | ITensor *output, |
| 81 | Coordinates2D crop_size, |
| 82 | InterpolationPolicy method, |
| 83 | float extrapolation_value) |
| 84 | { |
| 85 | ARM_COMPUTE_TRACE_EVENT(ARM_COMPUTE_PROF_CAT_CPU, ARM_COMPUTE_PROF_LVL_CPU, "NECropResize::configure"); |
| 86 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
| 87 | ARM_COMPUTE_ERROR_THROW_ON(NECropResize::validate(input->info(), boxes->info(), box_ind->info(), output->info(), |
| 88 | crop_size, method, extrapolation_value)); |
| 89 | ARM_COMPUTE_LOG_PARAMS(input, boxes, box_ind, output, crop_size, method, extrapolation_value); |
| 90 | |
| 91 | _num_boxes = boxes->info()->tensor_shape()[1]; |
| 92 | TensorShape out_shape(input->info()->tensor_shape()[0], crop_size.x, crop_size.y); |
| 93 | |
| 94 | _output = output; |
| 95 | _method = method; |
| 96 | _extrapolation_value = extrapolation_value; |
| 97 | |
| 98 | // For each crop box: |
| 99 | // - A crop kernel is used to extract the initial cropped image as specified by boxes[i] from the 3D image input[box_ind[i]]. |
| 100 | // - A tensor is required to hold this initial cropped image. |
| 101 | // - A scale function is used to resize the cropped image to the size specified by crop_size. |
| 102 | // - A tensor is required to hold the final scaled image before it is copied into the 4D output |
| 103 | // that will hold all final cropped and scaled 3D images. |
| 104 | _crop.reserve(_num_boxes); |
| 105 | _crop_results.reserve(_num_boxes); |
| 106 | _scaled_results.reserve(_num_boxes); |
| 107 | _scale.reserve(_num_boxes); |
| 108 | |
| 109 | for (unsigned int i = 0; i < _num_boxes; ++i) |
| 110 | { |
| 111 | auto crop_tensor = std::make_unique<Tensor>(); |
| 112 | TensorInfo crop_result_info(1, DataType::F32); |
| 113 | crop_result_info.set_data_layout(DataLayout::NHWC); |
| 114 | crop_tensor->allocator()->init(crop_result_info); |
| 115 | |
| 116 | auto scale_tensor = std::make_unique<Tensor>(); |
| 117 | TensorInfo scaled_result_info(out_shape, 1, DataType::F32); |
| 118 | scaled_result_info.set_data_layout(DataLayout::NHWC); |
| 119 | scale_tensor->allocator()->init(scaled_result_info); |
| 120 | |
| 121 | auto crop_kernel = std::make_unique<NECropKernel>(); |
| 122 | auto scale_kernel = std::make_unique<NEScale>(); |
| 123 | crop_kernel->configure(input, boxes, box_ind, crop_tensor.get(), i, _extrapolation_value); |
| 124 | |
| 125 | _crop.emplace_back(std::move(crop_kernel)); |
| 126 | _scaled_results.emplace_back(std::move(scale_tensor)); |
| 127 | _crop_results.emplace_back(std::move(crop_tensor)); |
| 128 | _scale.emplace_back(std::move(scale_kernel)); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | void NECropResize::run() |
| 133 | { |