blob: 361c236293d123c955857fcc9c04e6acc7cd5347 [file] [log] [blame]
George Wort05398a92019-01-25 15:38:33 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 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
27#include "arm_compute/core/NEON/kernels/NECropKernel.h"
28#include "arm_compute/runtime/NEON/functions/NEScale.h"
29
George Wort05398a92019-01-25 15:38:33 +000030#include <memory>
31
32namespace arm_compute
33{
34// Forward Declarations
35class ITensor;
36
37/** Function to perform cropping and resizing */
38class NECropResize : public IFunction
39{
40public:
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 virtual ~NECropResize() = default;
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 *
Michele Di Giorgio17101332020-06-01 12:07:50 +010060 * @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 +000061 * @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 *
Michele Di Giorgio17101332020-06-01 12:07:50 +010078 * @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 +000079 * @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
95 ITensor *_output;
96 size_t _num_boxes;
97 InterpolationPolicy _method;
98 float _extrapolation_value;
99
Michalis Spyrou299fdd32019-05-01 13:03:59 +0100100 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;
George Wort05398a92019-01-25 15:38:33 +0000104};
105} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000106#endif /* ARM_COMPUTE_NEON_CROP_RESIZE_H */