blob: e790e68b5fd59a51d1edfb3c8266956b796772c0 [file] [log] [blame]
George Wort05398a92019-01-25 15:38:33 +00001/*
2 * Copyright (c) 2019 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
27#include "arm_compute/core/NEON/kernels/NECropKernel.h"
28#include "arm_compute/runtime/NEON/functions/NEScale.h"
29
30#include <cstdint>
31#include <memory>
32
33namespace arm_compute
34{
35// Forward Declarations
36class ITensor;
37
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 */
53 virtual ~NECropResize() = default;
54
55 /** Configure kernel
56 *
57 * @note Supported tensor rank: up to 4
58 * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
59 * @note Start and end indices of boxes are inclusive.
60 *
61 * @param[in] input Source tensor containing N batches of 3D images to be cropped. Data type supported: U16/S16/U32/S32/F16/F32
62 * @param[in] boxes Tensor containing the boxes used to crop the images. Data type supported: F32
63 * @param[in] box_ind One dimensional tensor containing the batch index of the 3D image in @p input that the corresponding
64 * box in @p boxes will be applied to. Data type supported: F32
65 * @param[out] output Destination tensor containing a cropped and resized image for each box in @p boxes. Data type supported: F32
66 * @param[in] crop_size The dimensions that each cropped image will be resized to.
67 * @param[in] method The policy to be used when resizing image. Default is bilinear.
68 * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
69 */
70 void configure(const ITensor *input, const ITensor *boxes, const ITensor *box_ind, ITensor *output, Coordinates2D crop_size,
71 InterpolationPolicy method = InterpolationPolicy::BILINEAR, float extrapolation_value = 0);
72
73 /** Static function to check if given info will lead to a valid configuration of @ref NESlice
74 *
75 * @note Supported tensor rank: up to 4
76 * @note Box indices may be outside of the bounds, in which case @p extrapolation_value is used.
77 * @note Start and end indices of boxes are inclusive.
78 *
79 * @param[in] input Source tensor containing N batches of 3D images to be cropped. Data type supported: U16/S16/U32/S32/F16/F32
80 * @param[in] boxes Tensor info for the tensor containing the boxes used to crop the images. Data type supported: F32
81 * @param[in] box_ind Tensor info for the one dimensional tensor containing the batch index of the 3D image in @p input
82 * that the corresponding box in @p boxes will be applied to. Data type supported: F32
83 * @param[in] output Tensor info for the destination tensor containing a cropped and resized image for each box in @p boxes.
84 * Data type supported: F32
85 * @param[in] crop_size The dimensions that each cropped image will be resized to.
86 * @param[in] method The policy to be used when resizing image. Default is bilinear.
87 * @param[in] extrapolation_value Value to be used for values outside of the image for cropping and resizing. Default is 0.
88 *
89 * @return A status
90 */
91 static Status validate(const ITensorInfo *input, const ITensorInfo *boxes, const ITensorInfo *box_ind, const ITensorInfo *output,
92 Coordinates2D crop_size, InterpolationPolicy method, float extrapolation_value);
93
94 void run() override;
95
96 ITensor *_output;
97 size_t _num_boxes;
98 InterpolationPolicy _method;
99 float _extrapolation_value;
100
101 std::unique_ptr<NECropKernel[]> _crop;
102 std::unique_ptr<NEScale[]> _scale;
103 std::unique_ptr<Tensor[]> _crop_results{ nullptr };
104 std::unique_ptr<Tensor[]> _scaled_results{ nullptr };
105};
106} // namespace arm_compute
107#endif /* __ARM_COMPUTE_NEON_CROP_RESIZE_H__ */