From bb123bd6f64444141161562aad06cb406762d47a Mon Sep 17 00:00:00 2001 From: Sang-Hoon Park Date: Fri, 3 Jan 2020 10:57:30 +0000 Subject: MLCE-139 add align_corners parameter to NEScale Change-Id: I497ceb54c5fd8af1af8c529f90fd5a00a45263c8 Signed-off-by: Sang-Hoon Park Reviewed-on: https://review.mlplatform.org/c/2538 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio Reviewed-by: Pablo Marquez --- arm_compute/core/NEON/kernels/NEScaleKernel.h | 9 ++++++--- arm_compute/core/Utils.h | 12 +++++++++++- arm_compute/runtime/CL/functions/CLScale.h | 10 +++++++--- arm_compute/runtime/GLES_COMPUTE/functions/GCScale.h | 6 ++++-- arm_compute/runtime/NEON/functions/NEScale.h | 11 +++++++---- 5 files changed, 35 insertions(+), 13 deletions(-) (limited to 'arm_compute') diff --git a/arm_compute/core/NEON/kernels/NEScaleKernel.h b/arm_compute/core/NEON/kernels/NEScaleKernel.h index b720288c5c..e6790371a6 100644 --- a/arm_compute/core/NEON/kernels/NEScaleKernel.h +++ b/arm_compute/core/NEON/kernels/NEScaleKernel.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019 ARM Limited. + * Copyright (c) 2016-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -67,10 +67,11 @@ public: * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT and use_padding is set to false. * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true. + * @param[in] align_corners (Optional) Align corners of input and output, only affecting bilinear policy with TOP_LEFT sampling policy. Defaults to false. */ void configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, ITensor *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value = PixelValue(), - SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true); + SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true, bool align_corners = false); /** Static function to check if given info will lead to a valid configuration of @ref NEScaleKernel * * @note dx, dy and offsets have the same dimensions (width and height) of the output tensor @@ -86,10 +87,11 @@ public: * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT and use_padding is set to false. * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true. + * @param[in] align_corners (Optional) Align corners of input and output, only affecting bilinear policy with TOP_LEFT sampling policy. Defaults to false. */ static Status validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value = PixelValue(), - SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true); + SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true, bool align_corners = false); // Inherited methods overridden: void run(const Window &window, const ThreadInfo &info) override; @@ -121,6 +123,7 @@ private: PixelValue _constant_border_value; float _sampling_offset; bool _use_padding; + bool _align_corners; }; } // namespace arm_compute #endif /*ARM_COMPUTE_NESCALEKERNEL_H */ diff --git a/arm_compute/core/Utils.h b/arm_compute/core/Utils.h index 0a7eeefded..3a8f6b319f 100644 --- a/arm_compute/core/Utils.h +++ b/arm_compute/core/Utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019 ARM Limited. + * Copyright (c) 2016-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -967,6 +967,16 @@ bool needs_serialized_reduction(ReductionOperation op, DataType dt, unsigned int */ QuantizationInfo get_softmax_output_quantization_info(DataType input_type, bool is_log); +/** Returns resize ratio between input and output with consideration of aligned corners + * + * @param[in] input_size The input size + * @param[in] output_size the output size + * @param[in] align_corners True to align corners of input and output. Defaults to false. + * + * @return The ratio between input and output (i.e., the input size divided by the output size) + */ +float calculate_resize_ratio(size_t input_size, size_t output_size, bool align_corners = false); + /** Convert a tensor format into a string. * * @param[in] format @ref Format to be translated to string. diff --git a/arm_compute/runtime/CL/functions/CLScale.h b/arm_compute/runtime/CL/functions/CLScale.h index 6a638e9f3a..2bef54e352 100644 --- a/arm_compute/runtime/CL/functions/CLScale.h +++ b/arm_compute/runtime/CL/functions/CLScale.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019 ARM Limited. + * Copyright (c) 2016-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -46,9 +46,11 @@ public: * @param[in] border_mode Strategy to use for borders. * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT. * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER + * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true. + * @param[in] align_corners (Optional) Align corners of input and output, only affecting bilinear policy. Defaults to false. */ void configure(ICLTensor *input, ICLTensor *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value = PixelValue(), - SamplingPolicy sampling_policy = SamplingPolicy::CENTER); + SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true, bool align_corners = false); /** Static function to check if given info will lead to a valid configuration of @ref CLScale * @@ -59,11 +61,13 @@ public: * @param[in] border_mode Strategy to use for borders. * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT. * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER + * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true. + * @param[in] align_corners (Optional) Align corners of input and output, only affecting bilinear policy. Defaults to false. * * @return a status */ static Status validate(const ITensorInfo *input, const ITensorInfo *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value = PixelValue(), - SamplingPolicy sampling_policy = SamplingPolicy::CENTER); + SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true, bool align_corners = false); }; } #endif /*ARM_COMPUTE_CLSCALE_H */ diff --git a/arm_compute/runtime/GLES_COMPUTE/functions/GCScale.h b/arm_compute/runtime/GLES_COMPUTE/functions/GCScale.h index 72d9b3c3e8..d4295d57fa 100644 --- a/arm_compute/runtime/GLES_COMPUTE/functions/GCScale.h +++ b/arm_compute/runtime/GLES_COMPUTE/functions/GCScale.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019 ARM Limited. + * Copyright (c) 2016-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -46,9 +46,11 @@ public: * @param[in] border_mode Strategy to use for borders. * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT. * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER + * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true. + * @param[in] align_corners (Optional) Align corners of input and output, only affecting bilinear policy with TOP_LEFT sampling policy. Defaults to false. */ void configure(IGCTensor *input, IGCTensor *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value = PixelValue(), - SamplingPolicy sampling_policy = SamplingPolicy::CENTER); + SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true, bool align_corners = false); }; } #endif /*ARM_COMPUTE_GCSCALE_H */ diff --git a/arm_compute/runtime/NEON/functions/NEScale.h b/arm_compute/runtime/NEON/functions/NEScale.h index 69698a47a9..75acb96b55 100644 --- a/arm_compute/runtime/NEON/functions/NEScale.h +++ b/arm_compute/runtime/NEON/functions/NEScale.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019 ARM Limited. + * Copyright (c) 2016-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -54,9 +54,10 @@ public: * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT. * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true. + * @param[in] align_corners (Optional) Align corners of input and output, only affecting bilinear policy with TOP_LEFT sampling policy. Defaults to false. */ void configure(ITensor *input, ITensor *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value = PixelValue(), - SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true); + SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true, bool align_corners = false); /** Static function to check if given info will lead to a valid configuration of @ref NEScale * * @param[in] input Source tensor. Data type supported: U8/S16/F16/F32. (Written to only for @p border_mode != UNDEFINED) @@ -66,11 +67,12 @@ public: * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT. * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true. + * @param[in] align_corners (Optional) Align corners of input and output, only affecting bilinear policy with TOP_LEFT sampling policy. Defaults to false. * * @return a status */ static Status validate(const ITensorInfo *input, const ITensorInfo *output, InterpolationPolicy policy, BorderMode border_mode, - PixelValue constant_border_value = PixelValue(), SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true); + PixelValue constant_border_value = PixelValue(), SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true, bool align_corners = false); // Inherited methods overridden: void run() override; @@ -82,6 +84,7 @@ private: NEScaleKernel _scale_kernel; /**< Kernel to perform the scaling */ NEFillBorderKernel _border_handler; /**< kernel to handle tensor borders */ bool _use_padding; /**< Is padding used on the tensors */ + bool _align_corners; /**< Align corners of input and output */ }; -} +} // namespace arm_compute #endif /*ARM_COMPUTE_NESCALEIMAGE_H */ -- cgit v1.2.1