George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 1 | /* |
Sheri Zhang | 7e20e29 | 2021-02-02 11:49:34 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2021 Arm Limited. |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 3 | * |
| 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CL_CROP_RESIZE_H |
| 25 | #define ARM_COMPUTE_CL_CROP_RESIZE_H |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/CL/ICLTensor.h" |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 28 | |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 29 | #include "arm_compute/runtime/CL/CLTensor.h" |
Sheri Zhang | 7e20e29 | 2021-02-02 11:49:34 +0000 | [diff] [blame] | 30 | #include "arm_compute/runtime/CL/functions/CLCopy.h" |
| 31 | #include "arm_compute/runtime/CL/functions/CLCrop.h" |
| 32 | #include "arm_compute/runtime/CL/functions/CLFill.h" |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 33 | #include "arm_compute/runtime/CL/functions/CLScale.h" |
| 34 | |
| 35 | #include <cstdint> |
| 36 | #include <memory> |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | // Forward Declarations |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 41 | class CLCompileContext; |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 42 | class ITensor; |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 43 | class ITensorInfo; |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 44 | |
| 45 | /** Function to perform cropping and resizing */ |
| 46 | class CLCropResize : public IFunction |
| 47 | { |
| 48 | public: |
| 49 | /** Default constructor */ |
| 50 | CLCropResize(); |
| 51 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 52 | CLCropResize(const CLCropResize &) = delete; |
| 53 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 54 | CLCropResize &operator=(const CLCropResize &) = delete; |
| 55 | /** Allow instances of this class to be moved */ |
| 56 | CLCropResize(CLCropResize &&) = default; |
| 57 | /** Allow instances of this class to be moved */ |
| 58 | CLCropResize &operator=(CLCropResize &&) = default; |
| 59 | /** Default destructor */ |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 60 | ~CLCropResize(); |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 61 | |
| 62 | /** Configure kernel |
| 63 | * |
Teresa Charlin | 6268742 | 2021-04-28 10:58:49 +0100 | [diff] [blame] | 64 | * Valid data layouts: |
| 65 | * - NHWC |
| 66 | * |
| 67 | * Valid data type configurations: |
| 68 | * |src0 |src1 |src2 |dst | |
| 69 | * |:--------|:--------|:------|:--------| |
| 70 | * |All |F32 |F32 |F32 | |
| 71 | * |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 72 | * @note Supported tensor rank: up to 4 |
| 73 | * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used. |
| 74 | * @note Start and end indices of boxes are inclusive. |
| 75 | * |
Michele Di Giorgio | 7d6b577 | 2020-06-01 13:39:52 +0100 | [diff] [blame] | 76 | * @param[in] input Source tensor containing N batches of 3D images to be cropped. Data type supported: All |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 77 | * @param[in] boxes Tensor containing the boxes used to crop the images. It has to be known before configuration. Data type supported: F32 |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 78 | * @param[in] box_ind One dimensional tensor containing the batch index of the 3D image in @p input that the corresponding |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 79 | * box in @p boxes will be applied to. It has to be known before configuration. Data type supported: F32 |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 80 | * @param[out] output Destination tensor containing a cropped and resized image for each box in @p boxes. Data type supported: F32 |
| 81 | * @param[in] crop_size The dimensions that each cropped image will be resized to. |
| 82 | * @param[in] method The policy to be used when resizing image. Default is bilinear. |
| 83 | * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0. |
| 84 | */ |
| 85 | void configure(const ICLTensor *input, ICLTensor *boxes, ICLTensor *box_ind, ICLTensor *output, Coordinates2D crop_size, |
| 86 | InterpolationPolicy method = InterpolationPolicy::BILINEAR, float extrapolation_value = 0); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 87 | /** Configure kernel |
| 88 | * |
| 89 | * @note Supported tensor rank: up to 4 |
| 90 | * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used. |
| 91 | * @note Start and end indices of boxes are inclusive. |
| 92 | * |
| 93 | * @param[in] compile_context The compile context to be used. |
Michele Di Giorgio | 7d6b577 | 2020-06-01 13:39:52 +0100 | [diff] [blame] | 94 | * @param[in] input Source tensor containing N batches of 3D images to be cropped. Data type supported: All |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 95 | * @param[in] boxes Tensor containing the boxes used to crop the images. It has to be known before configuration. Data type supported: F32 |
| 96 | * @param[in] box_ind One dimensional tensor containing the batch index of the 3D image in @p input that the corresponding |
| 97 | * box in @p boxes will be applied to. It has to be known before configuration. Data type supported: F32 |
| 98 | * @param[out] output Destination tensor containing a cropped and resized image for each box in @p boxes. Data type supported: F32 |
| 99 | * @param[in] crop_size The dimensions that each cropped image will be resized to. |
| 100 | * @param[in] method The policy to be used when resizing image. Default is bilinear. |
| 101 | * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0. |
| 102 | */ |
| 103 | void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *boxes, ICLTensor *box_ind, ICLTensor *output, Coordinates2D crop_size, |
| 104 | InterpolationPolicy method = InterpolationPolicy::BILINEAR, float extrapolation_value = 0); |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 105 | |
| 106 | /** Static function to check if given info will lead to a valid configuration of @ref NESlice |
| 107 | * |
| 108 | * @note Supported tensor rank: up to 4 |
| 109 | * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used. |
| 110 | * @note Start and end indices of boxes are inclusive. |
| 111 | * |
Michele Di Giorgio | 7d6b577 | 2020-06-01 13:39:52 +0100 | [diff] [blame] | 112 | * @param[in] input Source tensor info containing N batches of 3D images to be cropped. Data type supported: All |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 113 | * @param[in] boxes Tensor info for the tensor containing the boxes used to crop the images. Data type supported: F32 |
| 114 | * @param[in] box_ind Tensor info for the one dimensional tensor containing the batch index of the 3D image in @p input |
| 115 | * that the corresponding box in @p boxes will be applied to. Data type supported: F32 |
| 116 | * @param[in] output Tensor info for the destination tensor containing a cropped and resized image for each box in @p boxes. |
| 117 | * Data type supported: F32 |
| 118 | * @param[in] crop_size The dimensions that each cropped image will be resized to. |
| 119 | * @param[in] method The policy to be used when resizing image. Default is bilinear. |
| 120 | * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0. |
| 121 | * |
| 122 | * @return A status |
| 123 | */ |
| 124 | static Status validate(const ITensorInfo *input, ITensorInfo *boxes, ITensorInfo *box_ind, const ITensorInfo *output, |
| 125 | Coordinates2D crop_size, InterpolationPolicy method, float extrapolation_value); |
| 126 | |
| 127 | void run() override; |
| 128 | |
| 129 | const ICLTensor *_input; |
| 130 | ICLTensor *_boxes; |
| 131 | ICLTensor *_box_ind; |
| 132 | ICLTensor *_output; |
| 133 | size_t _num_boxes; |
| 134 | InterpolationPolicy _method; |
| 135 | float _extrapolation_value; |
| 136 | |
Sheri Zhang | 7e20e29 | 2021-02-02 11:49:34 +0000 | [diff] [blame] | 137 | std::vector<std::unique_ptr<CLScale>> _scale; |
| 138 | std::vector<std::unique_ptr<CLCopy>> _copy; |
| 139 | std::vector<std::unique_ptr<CLTensor>> _crop_results; |
| 140 | std::vector<std::unique_ptr<CLTensor>> _scaled_results; |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 141 | |
Sheri Zhang | 7e20e29 | 2021-02-02 11:49:34 +0000 | [diff] [blame] | 142 | std::vector<std::unique_ptr<IFunction>> _internal_functions; |
George Wort | 894066d | 2019-02-15 15:12:52 +0000 | [diff] [blame] | 143 | }; |
| 144 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 145 | #endif /* ARM_COMPUTE_CL_CROP_RESIZE_H */ |