Compute Library
 20.08
CLCropResize.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020 Arm Limited.
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  */
24 #ifndef ARM_COMPUTE_CL_CROP_RESIZE_H
25 #define ARM_COMPUTE_CL_CROP_RESIZE_H
26 
33 
34 #include <cstdint>
35 #include <memory>
36 
37 namespace arm_compute
38 {
39 // Forward Declarations
40 class ITensor;
41 
42 /** Function to perform cropping and resizing */
43 class CLCropResize : public IFunction
44 {
45 public:
46  /** Default constructor */
47  CLCropResize();
48  /** Prevent instances of this class from being copied (As this class contains pointers) */
49  CLCropResize(const CLCropResize &) = delete;
50  /** Prevent instances of this class from being copied (As this class contains pointers) */
51  CLCropResize &operator=(const CLCropResize &) = delete;
52  /** Allow instances of this class to be moved */
53  CLCropResize(CLCropResize &&) = default;
54  /** Allow instances of this class to be moved */
55  CLCropResize &operator=(CLCropResize &&) = default;
56  /** Default destructor */
57  virtual ~CLCropResize() = default;
58 
59  /** Configure kernel
60  *
61  * @note Supported tensor rank: up to 4
62  * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
63  * @note Start and end indices of boxes are inclusive.
64  *
65  * @param[in] input Source tensor containing N batches of 3D images to be cropped. Data type supported: All
66  * @param[in] boxes Tensor containing the boxes used to crop the images. It has to be known before configuration. Data type supported: F32
67  * @param[in] box_ind One dimensional tensor containing the batch index of the 3D image in @p input that the corresponding
68  * box in @p boxes will be applied to. It has to be known before configuration. Data type supported: F32
69  * @param[out] output Destination tensor containing a cropped and resized image for each box in @p boxes. Data type supported: F32
70  * @param[in] crop_size The dimensions that each cropped image will be resized to.
71  * @param[in] method The policy to be used when resizing image. Default is bilinear.
72  * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
73  */
74  void configure(const ICLTensor *input, ICLTensor *boxes, ICLTensor *box_ind, ICLTensor *output, Coordinates2D crop_size,
75  InterpolationPolicy method = InterpolationPolicy::BILINEAR, float extrapolation_value = 0);
76  /** Configure kernel
77  *
78  * @note Supported tensor rank: up to 4
79  * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
80  * @note Start and end indices of boxes are inclusive.
81  *
82  * @param[in] compile_context The compile context to be used.
83  * @param[in] input Source tensor containing N batches of 3D images to be cropped. Data type supported: All
84  * @param[in] boxes Tensor containing the boxes used to crop the images. It has to be known before configuration. Data type supported: F32
85  * @param[in] box_ind One dimensional tensor containing the batch index of the 3D image in @p input that the corresponding
86  * box in @p boxes will be applied to. It has to be known before configuration. Data type supported: F32
87  * @param[out] output Destination tensor containing a cropped and resized image for each box in @p boxes. Data type supported: F32
88  * @param[in] crop_size The dimensions that each cropped image will be resized to.
89  * @param[in] method The policy to be used when resizing image. Default is bilinear.
90  * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
91  */
92  void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *boxes, ICLTensor *box_ind, ICLTensor *output, Coordinates2D crop_size,
93  InterpolationPolicy method = InterpolationPolicy::BILINEAR, float extrapolation_value = 0);
94 
95  /** Static function to check if given info will lead to a valid configuration of @ref NESlice
96  *
97  * @note Supported tensor rank: up to 4
98  * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
99  * @note Start and end indices of boxes are inclusive.
100  *
101  * @param[in] input Source tensor info containing N batches of 3D images to be cropped. Data type supported: All
102  * @param[in] boxes Tensor info for the tensor containing the boxes used to crop the images. Data type supported: F32
103  * @param[in] box_ind Tensor info for the one dimensional tensor containing the batch index of the 3D image in @p input
104  * that the corresponding box in @p boxes will be applied to. Data type supported: F32
105  * @param[in] output Tensor info for the destination tensor containing a cropped and resized image for each box in @p boxes.
106  * Data type supported: F32
107  * @param[in] crop_size The dimensions that each cropped image will be resized to.
108  * @param[in] method The policy to be used when resizing image. Default is bilinear.
109  * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
110  *
111  * @return A status
112  */
113  static Status validate(const ITensorInfo *input, ITensorInfo *boxes, ITensorInfo *box_ind, const ITensorInfo *output,
114  Coordinates2D crop_size, InterpolationPolicy method, float extrapolation_value);
115 
116  void run() override;
117 
122  size_t _num_boxes;
125 
126  std::vector<std::unique_ptr<CLScale>> _scale;
127  std::vector<std::unique_ptr<CLCopyKernel>> _copy;
128  std::vector<std::unique_ptr<CLTensor>> _crop_results;
129  std::vector<std::unique_ptr<CLTensor>> _scaled_results;
130 
131  std::vector<std::unique_ptr<ICLKernel>> _internal_kernels;
132 };
133 } // namespace arm_compute
134 #endif /* ARM_COMPUTE_CL_CROP_RESIZE_H */
InterpolationPolicy
Interpolation method.
Definition: Types.h:369
std::vector< std::unique_ptr< CLTensor > > _crop_results
Definition: CLCropResize.h:128
CLCropResize()
Default constructor.
Base class for all functions.
Definition: IFunction.h:30
Output values are defined by bilinear interpolation between the pixels.
Store the tensor's metadata.
Definition: ITensorInfo.h:40
std::vector< std::unique_ptr< CLCopyKernel > > _copy
Definition: CLCropResize.h:127
Status class.
Definition: Error.h:52
Copyright (c) 2017-2020 Arm Limited.
std::vector< std::unique_ptr< CLTensor > > _scaled_results
Definition: CLCropResize.h:129
InterpolationPolicy _method
Definition: CLCropResize.h:123
static Status validate(const ITensorInfo *input, ITensorInfo *boxes, ITensorInfo *box_ind, const ITensorInfo *output, Coordinates2D crop_size, InterpolationPolicy method, float extrapolation_value)
Static function to check if given info will lead to a valid configuration of NESlice.
void run() override
Run the kernels contained in the function.
const ICLTensor * _input
Definition: CLCropResize.h:118
CLCompileContext class.
std::vector< std::unique_ptr< ICLKernel > > _internal_kernels
Definition: CLCropResize.h:131
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
Coordinate type.
Definition: Types.h:440
virtual ~CLCropResize()=default
Default destructor.
void configure(const ICLTensor *input, ICLTensor *boxes, ICLTensor *box_ind, ICLTensor *output, Coordinates2D crop_size, InterpolationPolicy method=InterpolationPolicy::BILINEAR, float extrapolation_value=0)
Configure kernel.
std::vector< std::unique_ptr< CLScale > > _scale
Definition: CLCropResize.h:126
Function to perform cropping and resizing.
Definition: CLCropResize.h:43
CLCropResize & operator=(const CLCropResize &)=delete
Prevent instances of this class from being copied (As this class contains pointers)