George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2020 Arm Limited. |
George Wort | 05398a9 | 2019-01-25 15:38:33 +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_NEON_CROP_RESIZE_H |
| 25 | #define ARM_COMPUTE_NEON_CROP_RESIZE_H |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 26 | |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 27 | #include "arm_compute/runtime/NEON/functions/NEScale.h" |
| 28 | |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 29 | #include <memory> |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | // Forward Declarations |
| 34 | class ITensor; |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 35 | class NECropKernel; |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 36 | |
| 37 | /** Function to perform cropping and resizing */ |
| 38 | class NECropResize : public IFunction |
| 39 | { |
| 40 | public: |
| 41 | /** Default constructor */ |
| 42 | NECropResize(); |
| 43 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 44 | NECropResize(const NECropResize &) = delete; |
| 45 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 46 | NECropResize &operator=(const NECropResize &) = delete; |
| 47 | /** Allow instances of this class to be moved */ |
| 48 | NECropResize(NECropResize &&) = default; |
| 49 | /** Allow instances of this class to be moved */ |
| 50 | NECropResize &operator=(NECropResize &&) = default; |
| 51 | /** Default destructor */ |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 52 | ~NECropResize(); |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 53 | |
| 54 | /** Configure kernel |
| 55 | * |
| 56 | * @note Supported tensor rank: up to 4 |
| 57 | * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used. |
| 58 | * @note Start and end indices of boxes are inclusive. |
| 59 | * |
Michele Di Giorgio | 1710133 | 2020-06-01 12:07:50 +0100 | [diff] [blame] | 60 | * @param[in] input Source tensor containing N batches of 3D images to be cropped. Data type supported: U8/U16/S16/U32/S32/F16/F32 |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 61 | * @param[in] boxes Tensor containing the boxes used to crop the images. Data type supported: F32 |
| 62 | * @param[in] box_ind One dimensional tensor containing the batch index of the 3D image in @p input that the corresponding |
| 63 | * box in @p boxes will be applied to. Data type supported: F32 |
| 64 | * @param[out] output Destination tensor containing a cropped and resized image for each box in @p boxes. Data type supported: F32 |
| 65 | * @param[in] crop_size The dimensions that each cropped image will be resized to. |
| 66 | * @param[in] method The policy to be used when resizing image. Default is bilinear. |
| 67 | * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0. |
| 68 | */ |
| 69 | void configure(const ITensor *input, const ITensor *boxes, const ITensor *box_ind, ITensor *output, Coordinates2D crop_size, |
| 70 | InterpolationPolicy method = InterpolationPolicy::BILINEAR, float extrapolation_value = 0); |
| 71 | |
| 72 | /** Static function to check if given info will lead to a valid configuration of @ref NESlice |
| 73 | * |
| 74 | * @note Supported tensor rank: up to 4 |
| 75 | * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used. |
| 76 | * @note Start and end indices of boxes are inclusive. |
| 77 | * |
Michele Di Giorgio | 1710133 | 2020-06-01 12:07:50 +0100 | [diff] [blame] | 78 | * @param[in] input Source tensor containing N batches of 3D images to be cropped. Data type supported: U8/U16/S16/U32/S32/F16/F32 |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 79 | * @param[in] boxes Tensor info for the tensor containing the boxes used to crop the images. Data type supported: F32 |
| 80 | * @param[in] box_ind Tensor info for the one dimensional tensor containing the batch index of the 3D image in @p input |
| 81 | * that the corresponding box in @p boxes will be applied to. Data type supported: F32 |
| 82 | * @param[in] output Tensor info for the destination tensor containing a cropped and resized image for each box in @p boxes. |
| 83 | * Data type supported: F32 |
| 84 | * @param[in] crop_size The dimensions that each cropped image will be resized to. |
| 85 | * @param[in] method The policy to be used when resizing image. Default is bilinear. |
| 86 | * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0. |
| 87 | * |
| 88 | * @return A status |
| 89 | */ |
| 90 | static Status validate(const ITensorInfo *input, const ITensorInfo *boxes, const ITensorInfo *box_ind, const ITensorInfo *output, |
| 91 | Coordinates2D crop_size, InterpolationPolicy method, float extrapolation_value); |
| 92 | |
| 93 | void run() override; |
| 94 | |
| 95 | ITensor *_output; |
| 96 | size_t _num_boxes; |
| 97 | InterpolationPolicy _method; |
| 98 | float _extrapolation_value; |
| 99 | |
Michalis Spyrou | 299fdd3 | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 100 | std::vector<std::unique_ptr<NECropKernel>> _crop; |
| 101 | std::vector<std::unique_ptr<NEScale>> _scale; |
| 102 | std::vector<std::unique_ptr<Tensor>> _crop_results; |
| 103 | std::vector<std::unique_ptr<Tensor>> _scaled_results; |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 104 | }; |
| 105 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 106 | #endif /* ARM_COMPUTE_NEON_CROP_RESIZE_H */ |