blob: e781cfe61f10a3be2f42853269f7d9b52a773447 [file] [log] [blame]
George Wort894066d2019-02-15 15:12:52 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 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"
30#include "arm_compute/runtime/CL/functions/CLScale.h"
31
32#include <cstdint>
33#include <memory>
34
35namespace arm_compute
36{
37// Forward Declarations
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010038class CLCompileContext;
39class CLCopyKernel;
40class CLCropKernel;
George Wort894066d2019-02-15 15:12:52 +000041class ITensor;
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010042class ITensorInfo;
George Wort894066d2019-02-15 15:12:52 +000043
44/** Function to perform cropping and resizing */
45class CLCropResize : public IFunction
46{
47public:
48 /** Default constructor */
49 CLCropResize();
50 /** Prevent instances of this class from being copied (As this class contains pointers) */
51 CLCropResize(const CLCropResize &) = delete;
52 /** Prevent instances of this class from being copied (As this class contains pointers) */
53 CLCropResize &operator=(const CLCropResize &) = delete;
54 /** Allow instances of this class to be moved */
55 CLCropResize(CLCropResize &&) = default;
56 /** Allow instances of this class to be moved */
57 CLCropResize &operator=(CLCropResize &&) = default;
58 /** Default destructor */
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010059 ~CLCropResize();
George Wort894066d2019-02-15 15:12:52 +000060
61 /** Configure kernel
62 *
63 * @note Supported tensor rank: up to 4
64 * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
65 * @note Start and end indices of boxes are inclusive.
66 *
Michele Di Giorgio7d6b5772020-06-01 13:39:52 +010067 * @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 +010068 * @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 +000069 * @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 +010070 * 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 +000071 * @param[out] output Destination tensor containing a cropped and resized image for each box in @p boxes. Data type supported: F32
72 * @param[in] crop_size The dimensions that each cropped image will be resized to.
73 * @param[in] method The policy to be used when resizing image. Default is bilinear.
74 * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
75 */
76 void configure(const ICLTensor *input, ICLTensor *boxes, ICLTensor *box_ind, ICLTensor *output, Coordinates2D crop_size,
77 InterpolationPolicy method = InterpolationPolicy::BILINEAR, float extrapolation_value = 0);
Manuel Bottini2b84be52020-04-08 10:15:51 +010078 /** Configure kernel
79 *
80 * @note Supported tensor rank: up to 4
81 * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
82 * @note Start and end indices of boxes are inclusive.
83 *
84 * @param[in] compile_context The compile context to be used.
Michele Di Giorgio7d6b5772020-06-01 13:39:52 +010085 * @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 +010086 * @param[in] boxes Tensor containing the boxes used to crop the images. It has to be known before configuration. Data type supported: F32
87 * @param[in] box_ind One dimensional tensor containing the batch index of the 3D image in @p input that the corresponding
88 * box in @p boxes will be applied to. It has to be known before configuration. Data type supported: F32
89 * @param[out] output Destination tensor containing a cropped and resized image for each box in @p boxes. Data type supported: F32
90 * @param[in] crop_size The dimensions that each cropped image will be resized to.
91 * @param[in] method The policy to be used when resizing image. Default is bilinear.
92 * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
93 */
94 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *boxes, ICLTensor *box_ind, ICLTensor *output, Coordinates2D crop_size,
95 InterpolationPolicy method = InterpolationPolicy::BILINEAR, float extrapolation_value = 0);
George Wort894066d2019-02-15 15:12:52 +000096
97 /** Static function to check if given info will lead to a valid configuration of @ref NESlice
98 *
99 * @note Supported tensor rank: up to 4
100 * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
101 * @note Start and end indices of boxes are inclusive.
102 *
Michele Di Giorgio7d6b5772020-06-01 13:39:52 +0100103 * @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 +0000104 * @param[in] boxes Tensor info for the tensor containing the boxes used to crop the images. Data type supported: F32
105 * @param[in] box_ind Tensor info for the one dimensional tensor containing the batch index of the 3D image in @p input
106 * that the corresponding box in @p boxes will be applied to. Data type supported: F32
107 * @param[in] output Tensor info for the destination tensor containing a cropped and resized image for each box in @p boxes.
108 * Data type supported: F32
109 * @param[in] crop_size The dimensions that each cropped image will be resized to.
110 * @param[in] method The policy to be used when resizing image. Default is bilinear.
111 * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
112 *
113 * @return A status
114 */
115 static Status validate(const ITensorInfo *input, ITensorInfo *boxes, ITensorInfo *box_ind, const ITensorInfo *output,
116 Coordinates2D crop_size, InterpolationPolicy method, float extrapolation_value);
117
118 void run() override;
119
120 const ICLTensor *_input;
121 ICLTensor *_boxes;
122 ICLTensor *_box_ind;
123 ICLTensor *_output;
124 size_t _num_boxes;
125 InterpolationPolicy _method;
126 float _extrapolation_value;
127
Michalis Spyroua4f378d2019-04-26 14:54:54 +0100128 std::vector<std::unique_ptr<CLScale>> _scale;
129 std::vector<std::unique_ptr<CLCopyKernel>> _copy;
130 std::vector<std::unique_ptr<CLTensor>> _crop_results;
131 std::vector<std::unique_ptr<CLTensor>> _scaled_results;
Manuel Bottini2b84be52020-04-08 10:15:51 +0100132
133 std::vector<std::unique_ptr<ICLKernel>> _internal_kernels;
George Wort894066d2019-02-15 15:12:52 +0000134};
135} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000136#endif /* ARM_COMPUTE_CL_CROP_RESIZE_H */