Compute Library
 21.02
NECropResize.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_NEON_CROP_RESIZE_H
25 #define ARM_COMPUTE_NEON_CROP_RESIZE_H
26 
28 
29 #include <memory>
30 
31 namespace arm_compute
32 {
33 // Forward Declarations
34 class ITensor;
35 class NECropKernel;
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 */
52  ~NECropResize();
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  *
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
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  *
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
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 
96  size_t _num_boxes;
99 
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;
104 };
105 } // namespace arm_compute
106 #endif /* ARM_COMPUTE_NEON_CROP_RESIZE_H */
InterpolationPolicy
Interpolation method.
Definition: Types.h:392
Base class for all functions.
Definition: IFunction.h:30
void configure(const ITensor *input, const ITensor *boxes, const ITensor *box_ind, ITensor *output, Coordinates2D crop_size, InterpolationPolicy method=InterpolationPolicy::BILINEAR, float extrapolation_value=0)
Configure kernel.
~NECropResize()
Default destructor.
std::vector< std::unique_ptr< NECropKernel > > _crop
Definition: NECropResize.h:100
std::vector< std::unique_ptr< Tensor > > _scaled_results
Definition: NECropResize.h:103
Output values are defined by bilinear interpolation between the pixels.
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
Interface for Neon tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
Function to perform cropping and resizing.
Definition: NECropResize.h:38
static Status validate(const ITensorInfo *input, const ITensorInfo *boxes, const 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.
std::vector< std::unique_ptr< NEScale > > _scale
Definition: NECropResize.h:101
NECropResize()
Default constructor.
Coordinate type.
Definition: Types.h:463
void run() override
Run the kernels contained in the function.
InterpolationPolicy _method
Definition: NECropResize.h:97
NECropResize & operator=(const NECropResize &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
std::vector< std::unique_ptr< Tensor > > _crop_results
Definition: NECropResize.h:102