diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/CL/kernels/CLScaleKernel.cpp | 18 | ||||
-rw-r--r-- | src/core/NEON/kernels/NEScaleKernel.cpp | 28 | ||||
-rw-r--r-- | src/runtime/NEON/functions/NEScale.cpp | 13 |
3 files changed, 26 insertions, 33 deletions
diff --git a/src/core/CL/kernels/CLScaleKernel.cpp b/src/core/CL/kernels/CLScaleKernel.cpp index f41664f4e0..e19da32ac3 100644 --- a/src/core/CL/kernels/CLScaleKernel.cpp +++ b/src/core/CL/kernels/CLScaleKernel.cpp @@ -60,7 +60,7 @@ inline std::pair<float, float> calculate_scale_factors(const ITensorInfo &input, return std::make_pair(wr, hr); } -Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, InterpolationPolicy policy, bool align_corners) +Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, InterpolationPolicy policy, SamplingPolicy sampling_policy, bool align_corners) { ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::U8, DataType::S16, DataType::F16, DataType::F32); @@ -68,6 +68,7 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, I ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(input, output); ARM_COMPUTE_RETURN_ERROR_ON(output == input); + ARM_COMPUTE_RETURN_ERROR_ON(align_corners && !is_align_corners_allowed(sampling_policy)); if(align_corners) { @@ -160,11 +161,9 @@ BorderSize CLScaleKernel::border_size() const Status CLScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *output, InterpolationPolicy policy, BorderMode border_mode, SamplingPolicy sampling_policy, bool align_corners) { - BorderSize border = BorderSize(1); - const bool is_align_corners = policy == InterpolationPolicy::BILINEAR - && sampling_policy == SamplingPolicy::TOP_LEFT - && align_corners; - ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, policy, is_align_corners)); + BorderSize border = BorderSize(1); + + ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, policy, sampling_policy, align_corners)); ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), policy, border_mode, sampling_policy, border).first); return Status{}; @@ -188,16 +187,13 @@ void CLScaleKernel::configure(const ICLTensor *input, ICLTensor *output, Interpo void CLScaleKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, InterpolationPolicy policy, BorderMode border_mode, SamplingPolicy sampling_policy, bool align_corners) { - _align_corners = policy == InterpolationPolicy::BILINEAR - && sampling_policy == SamplingPolicy::TOP_LEFT - && align_corners; - - ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), policy, _align_corners)); + ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), policy, sampling_policy, align_corners)); _input = input; _output = output; _interpolationPolicy = policy; _data_layout = input->info()->data_layout(); + _align_corners = align_corners; float wr = 0.f; float hr = 0.f; diff --git a/src/core/NEON/kernels/NEScaleKernel.cpp b/src/core/NEON/kernels/NEScaleKernel.cpp index 763ad49cb7..857084ef7e 100644 --- a/src/core/NEON/kernels/NEScaleKernel.cpp +++ b/src/core/NEON/kernels/NEScaleKernel.cpp @@ -66,18 +66,20 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *dx, const ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32); ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dx, 1, DataType::F32); ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dy, 1, DataType::F32); + } - if(info.align_corners) - { - // For bilinear method with aligned corners, the resize ratio will - // be calculated by (input_size - 1)/(output_size - 1). Belows are - // checking possible overflows. - const auto input_width = input->dimension(width_index); - const auto input_height = input->dimension(height_index); - - ARM_COMPUTE_RETURN_ERROR_ON(input_width == 0 || input_height == 0); - ARM_COMPUTE_RETURN_ERROR_ON((output_width - 1 == 0) || (output_height - 1 == 0)); - } + ARM_COMPUTE_RETURN_ERROR_ON(info.align_corners && !is_align_corners_allowed(info.sampling_policy)); + + if(info.align_corners && is_align_corners_allowed(info.sampling_policy)) + { + // For bilinear method with aligned corners, the resize ratio will + // be calculated by (input_size - 1)/(output_size - 1). Belows are + // checking possible overflows. + const auto input_width = input->dimension(width_index); + const auto input_height = input->dimension(height_index); + + ARM_COMPUTE_RETURN_ERROR_ON(input_width == 0 || input_height == 0); + ARM_COMPUTE_RETURN_ERROR_ON((output_width - 1 == 0) || (output_height - 1 == 0)); } if(info.interpolation_policy == InterpolationPolicy::AREA) @@ -376,9 +378,7 @@ void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITe _border_mode = info.border_mode; _constant_border_value = info.constant_border_value; _use_padding = info.use_padding; - _align_corners = info.interpolation_policy == InterpolationPolicy::BILINEAR - && info.sampling_policy == SamplingPolicy::TOP_LEFT - && info.align_corners; + _align_corners = info.align_corners; if(info.sampling_policy == SamplingPolicy::CENTER) { diff --git a/src/runtime/NEON/functions/NEScale.cpp b/src/runtime/NEON/functions/NEScale.cpp index acde0cfcc5..a5d3ac76a5 100644 --- a/src/runtime/NEON/functions/NEScale.cpp +++ b/src/runtime/NEON/functions/NEScale.cpp @@ -97,8 +97,7 @@ NEScale::NEScale() // NOLINT _dy(), _scale_kernel(), _border_handler(), - _use_padding(true), - _align_corners(false) + _use_padding(true) { } @@ -107,10 +106,8 @@ void NEScale::configure(ITensor *input, ITensor *output, const ScaleKernelInfo & ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); ARM_COMPUTE_ERROR_THROW_ON(NEScale::validate(input->info(), output->info(), info)); - _use_padding = info.use_padding; - _align_corners = info.interpolation_policy == InterpolationPolicy::BILINEAR - && info.sampling_policy == SamplingPolicy::TOP_LEFT - && info.align_corners; + _use_padding = info.use_padding; + const bool is_align_corners_used = info.align_corners && is_align_corners_allowed(info.sampling_policy); // Get data layout and width/height indices const DataLayout data_layout = input->info()->data_layout(); @@ -121,8 +118,8 @@ void NEScale::configure(ITensor *input, ITensor *output, const ScaleKernelInfo & const TensorShape shape(output->info()->dimension(idx_width), output->info()->dimension(idx_height)); // Compute the ratio between source width/height and destination width/height - const auto wr = arm_compute::calculate_resize_ratio(input->info()->dimension(idx_width), output->info()->dimension(idx_width), _align_corners); - const auto hr = arm_compute::calculate_resize_ratio(input->info()->dimension(idx_height), output->info()->dimension(idx_height), _align_corners); + const auto wr = arm_compute::calculate_resize_ratio(input->info()->dimension(idx_width), output->info()->dimension(idx_width), is_align_corners_used); + const auto hr = arm_compute::calculate_resize_ratio(input->info()->dimension(idx_height), output->info()->dimension(idx_height), is_align_corners_used); // Get the element size of the input image const size_t input_element_size = input->info()->element_size(); |