blob: 0dc3c48b329362eb0350d49bb02c19e1f5559721 [file] [log] [blame]
George Wort894066d2019-02-15 15:12:52 +00001/*
Sheri Zhang7e20e292021-02-02 11:49:34 +00002 * Copyright (c) 2019-2021 Arm Limited.
George Wort894066d2019-02-15 15:12:52 +00003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CL_CROP_RESIZE_H
25#define ARM_COMPUTE_CL_CROP_RESIZE_H
George Wort894066d2019-02-15 15:12:52 +000026
27#include "arm_compute/core/CL/ICLTensor.h"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010028
George Wort894066d2019-02-15 15:12:52 +000029#include "arm_compute/runtime/CL/CLTensor.h"
Sheri Zhang7e20e292021-02-02 11:49:34 +000030#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 Wort894066d2019-02-15 15:12:52 +000033#include "arm_compute/runtime/CL/functions/CLScale.h"
34
35#include <cstdint>
36#include <memory>
37
38namespace arm_compute
39{
40// Forward Declarations
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010041class CLCompileContext;
George Wort894066d2019-02-15 15:12:52 +000042class ITensor;
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010043class ITensorInfo;
George Wort894066d2019-02-15 15:12:52 +000044
45/** Function to perform cropping and resizing */
46class CLCropResize : public IFunction
47{
48public:
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 Parkbef7fa22020-10-21 15:58:54 +010060 ~CLCropResize();
George Wort894066d2019-02-15 15:12:52 +000061
62 /** Configure kernel
63 *
64 * @note Supported tensor rank: up to 4
65 * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
66 * @note Start and end indices of boxes are inclusive.
67 *
Michele Di Giorgio7d6b5772020-06-01 13:39:52 +010068 * @param[in] input Source tensor containing N batches of 3D images to be cropped. Data type supported: All
Manuel Bottini2b84be52020-04-08 10:15:51 +010069 * @param[in] boxes Tensor containing the boxes used to crop the images. It has to be known before configuration. Data type supported: F32
George Wort894066d2019-02-15 15:12:52 +000070 * @param[in] box_ind One dimensional tensor containing the batch index of the 3D image in @p input that the corresponding
Manuel Bottini2b84be52020-04-08 10:15:51 +010071 * box in @p boxes will be applied to. It has to be known before configuration. Data type supported: F32
George Wort894066d2019-02-15 15:12:52 +000072 * @param[out] output Destination tensor containing a cropped and resized image for each box in @p boxes. Data type supported: F32
73 * @param[in] crop_size The dimensions that each cropped image will be resized to.
74 * @param[in] method The policy to be used when resizing image. Default is bilinear.
75 * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
76 */
77 void configure(const ICLTensor *input, ICLTensor *boxes, ICLTensor *box_ind, ICLTensor *output, Coordinates2D crop_size,
78 InterpolationPolicy method = InterpolationPolicy::BILINEAR, float extrapolation_value = 0);
Manuel Bottini2b84be52020-04-08 10:15:51 +010079 /** Configure kernel
80 *
81 * @note Supported tensor rank: up to 4
82 * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
83 * @note Start and end indices of boxes are inclusive.
84 *
85 * @param[in] compile_context The compile context to be used.
Michele Di Giorgio7d6b5772020-06-01 13:39:52 +010086 * @param[in] input Source tensor containing N batches of 3D images to be cropped. Data type supported: All
Manuel Bottini2b84be52020-04-08 10:15:51 +010087 * @param[in] boxes Tensor containing the boxes used to crop the images. It has to be known before configuration. Data type supported: F32
88 * @param[in] box_ind One dimensional tensor containing the batch index of the 3D image in @p input that the corresponding
89 * box in @p boxes will be applied to. It has to be known before configuration. Data type supported: F32
90 * @param[out] output Destination tensor containing a cropped and resized image for each box in @p boxes. Data type supported: F32
91 * @param[in] crop_size The dimensions that each cropped image will be resized to.
92 * @param[in] method The policy to be used when resizing image. Default is bilinear.
93 * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
94 */
95 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *boxes, ICLTensor *box_ind, ICLTensor *output, Coordinates2D crop_size,
96 InterpolationPolicy method = InterpolationPolicy::BILINEAR, float extrapolation_value = 0);
George Wort894066d2019-02-15 15:12:52 +000097
98 /** Static function to check if given info will lead to a valid configuration of @ref NESlice
99 *
100 * @note Supported tensor rank: up to 4
101 * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
102 * @note Start and end indices of boxes are inclusive.
103 *
Michele Di Giorgio7d6b5772020-06-01 13:39:52 +0100104 * @param[in] input Source tensor info containing N batches of 3D images to be cropped. Data type supported: All
George Wort894066d2019-02-15 15:12:52 +0000105 * @param[in] boxes Tensor info for the tensor containing the boxes used to crop the images. Data type supported: F32
106 * @param[in] box_ind Tensor info for the one dimensional tensor containing the batch index of the 3D image in @p input
107 * that the corresponding box in @p boxes will be applied to. Data type supported: F32
108 * @param[in] output Tensor info for the destination tensor containing a cropped and resized image for each box in @p boxes.
109 * Data type supported: F32
110 * @param[in] crop_size The dimensions that each cropped image will be resized to.
111 * @param[in] method The policy to be used when resizing image. Default is bilinear.
112 * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
113 *
114 * @return A status
115 */
116 static Status validate(const ITensorInfo *input, ITensorInfo *boxes, ITensorInfo *box_ind, const ITensorInfo *output,
117 Coordinates2D crop_size, InterpolationPolicy method, float extrapolation_value);
118
119 void run() override;
120
121 const ICLTensor *_input;
122 ICLTensor *_boxes;
123 ICLTensor *_box_ind;
124 ICLTensor *_output;
125 size_t _num_boxes;
126 InterpolationPolicy _method;
127 float _extrapolation_value;
128
Sheri Zhang7e20e292021-02-02 11:49:34 +0000129 std::vector<std::unique_ptr<CLScale>> _scale;
130 std::vector<std::unique_ptr<CLCopy>> _copy;
131 std::vector<std::unique_ptr<CLTensor>> _crop_results;
132 std::vector<std::unique_ptr<CLTensor>> _scaled_results;
Manuel Bottini2b84be52020-04-08 10:15:51 +0100133
Sheri Zhang7e20e292021-02-02 11:49:34 +0000134 std::vector<std::unique_ptr<IFunction>> _internal_functions;
George Wort894066d2019-02-15 15:12:52 +0000135};
136} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000137#endif /* ARM_COMPUTE_CL_CROP_RESIZE_H */