blob: f806762158c75797d0cb0ee2c3945042ee826441 [file] [log] [blame]
George Wort05398a92019-01-25 15:38:33 +00001/*
Manuel Bottini10b38262021-02-19 18:16:44 +00002 * Copyright (c) 2019-2021 Arm Limited.
George Wort05398a92019-01-25 15:38:33 +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_NEON_CROP_RESIZE_H
25#define ARM_COMPUTE_NEON_CROP_RESIZE_H
George Wort05398a92019-01-25 15:38:33 +000026
George Wort05398a92019-01-25 15:38:33 +000027#include "arm_compute/runtime/NEON/functions/NEScale.h"
28
George Wort05398a92019-01-25 15:38:33 +000029#include <memory>
30
31namespace arm_compute
32{
33// Forward Declarations
Manuel Bottini10b38262021-02-19 18:16:44 +000034class Tensor;
George Wort05398a92019-01-25 15:38:33 +000035class ITensor;
Michalis Spyrouebcebf12020-10-21 00:04:14 +010036class NECropKernel;
George Wort05398a92019-01-25 15:38:33 +000037
38/** Function to perform cropping and resizing */
39class NECropResize : public IFunction
40{
41public:
42 /** Default constructor */
43 NECropResize();
44 /** Prevent instances of this class from being copied (As this class contains pointers) */
45 NECropResize(const NECropResize &) = delete;
46 /** Prevent instances of this class from being copied (As this class contains pointers) */
47 NECropResize &operator=(const NECropResize &) = delete;
48 /** Allow instances of this class to be moved */
49 NECropResize(NECropResize &&) = default;
50 /** Allow instances of this class to be moved */
51 NECropResize &operator=(NECropResize &&) = default;
52 /** Default destructor */
Michalis Spyrouebcebf12020-10-21 00:04:14 +010053 ~NECropResize();
George Wort05398a92019-01-25 15:38:33 +000054
55 /** Configure kernel
56 *
Teresa Charlin62687422021-04-28 10:58:49 +010057 * Valid data layouts:
58 * - NHWC
59 *
60 * Valid data type configurations:
61 * |src0 |src1 |src2 |dst |
62 * |:--------|:--------|:------|:--------|
63 * |All |F32 |F32 |F32 |
64 *
George Wort05398a92019-01-25 15:38:33 +000065 * @note Supported tensor rank: up to 4
66 * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
67 * @note Start and end indices of boxes are inclusive.
68 *
Michele Di Giorgio17101332020-06-01 12:07:50 +010069 * @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 Wort05398a92019-01-25 15:38:33 +000070 * @param[in] boxes Tensor containing the boxes used to crop the images. Data type supported: F32
71 * @param[in] box_ind One dimensional tensor containing the batch index of the 3D image in @p input that the corresponding
72 * box in @p boxes will be applied to. Data type supported: F32
73 * @param[out] output Destination tensor containing a cropped and resized image for each box in @p boxes. Data type supported: F32
74 * @param[in] crop_size The dimensions that each cropped image will be resized to.
75 * @param[in] method The policy to be used when resizing image. Default is bilinear.
76 * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
77 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010078 void configure(const ITensor *input,
79 const ITensor *boxes,
80 const ITensor *box_ind,
81 ITensor *output,
82 Coordinates2D crop_size,
83 InterpolationPolicy method = InterpolationPolicy::BILINEAR,
84 float extrapolation_value = 0);
George Wort05398a92019-01-25 15:38:33 +000085
86 /** Static function to check if given info will lead to a valid configuration of @ref NESlice
87 *
88 * @note Supported tensor rank: up to 4
89 * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
90 * @note Start and end indices of boxes are inclusive.
91 *
Michele Di Giorgio17101332020-06-01 12:07:50 +010092 * @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 Wort05398a92019-01-25 15:38:33 +000093 * @param[in] boxes Tensor info for the tensor containing the boxes used to crop the images. Data type supported: F32
94 * @param[in] box_ind Tensor info for the one dimensional tensor containing the batch index of the 3D image in @p input
95 * that the corresponding box in @p boxes will be applied to. Data type supported: F32
96 * @param[in] output Tensor info for the destination tensor containing a cropped and resized image for each box in @p boxes.
97 * Data type supported: F32
98 * @param[in] crop_size The dimensions that each cropped image will be resized to.
99 * @param[in] method The policy to be used when resizing image. Default is bilinear.
100 * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
101 *
102 * @return A status
103 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100104 static Status validate(const ITensorInfo *input,
105 const ITensorInfo *boxes,
106 const ITensorInfo *box_ind,
107 const ITensorInfo *output,
108 Coordinates2D crop_size,
109 InterpolationPolicy method,
110 float extrapolation_value);
George Wort05398a92019-01-25 15:38:33 +0000111
112 void run() override;
113
114 ITensor *_output;
115 size_t _num_boxes;
116 InterpolationPolicy _method;
117 float _extrapolation_value;
118
Michalis Spyrou299fdd32019-05-01 13:03:59 +0100119 std::vector<std::unique_ptr<NECropKernel>> _crop;
120 std::vector<std::unique_ptr<NEScale>> _scale;
121 std::vector<std::unique_ptr<Tensor>> _crop_results;
122 std::vector<std::unique_ptr<Tensor>> _scaled_results;
George Wort05398a92019-01-25 15:38:33 +0000123};
124} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000125#endif /* ARM_COMPUTE_NEON_CROP_RESIZE_H */