From 3e92459cb1167f85570ea4c648761dc1aee60a01 Mon Sep 17 00:00:00 2001 From: Usama Date: Mon, 1 Apr 2019 11:58:18 +0100 Subject: COMPMID-2047: Reference implementation for dilation in DepthwiseConvolution. Change-Id: I6f57a4d207219457292b72098598b7a9e773672d Signed-off-by: Usama Arif Reviewed-on: https://review.mlplatform.org/c/931 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Pablo Marquez --- .../reference/DepthwiseConvolutionLayer.cpp | 46 +++++++++++----------- .../reference/DepthwiseConvolutionLayer.h | 4 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/validation/reference/DepthwiseConvolutionLayer.cpp b/tests/validation/reference/DepthwiseConvolutionLayer.cpp index 39429e2449..f27610afb8 100644 --- a/tests/validation/reference/DepthwiseConvolutionLayer.cpp +++ b/tests/validation/reference/DepthwiseConvolutionLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -50,7 +50,7 @@ namespace reference */ template SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, const PadStrideInfo &conv_info, - unsigned int depth_multiplier) + unsigned int depth_multiplier, const Size2D &dilation) { SimpleTensor dst{ dst_shape, src.data_type(), 1 }; @@ -63,18 +63,18 @@ SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTe const int input_depth = src.shape().z(); const int num_batches = src.shape().total_size() / (input_width * input_height * input_depth); - const int filter_half_width = filter_width / 2; - const int filter_half_height = filter_height / 2; - const int pad_left = conv_info.pad_left(); const int pad_top = conv_info.pad_top(); const int pad_right = conv_info.pad_right(); const int pad_bottom = conv_info.pad_bottom(); - const int minimum_x = -pad_left + filter_half_width; - const int minimum_y = -pad_top + filter_half_height; - const int maximum_x = input_width + pad_left - filter_half_width + pad_right - filter_half_width; - const int maximum_y = input_height + pad_top - filter_half_height + pad_bottom - filter_half_height; + const int patch_half_width = (filter_width + (dilation.x() - 1) * (filter_width - 1)) / 2; + const int patch_half_height = (filter_height + (dilation.y() - 1) * (filter_height - 1)) / 2; + + const int minimum_x = -pad_left + patch_half_width; + const int minimum_y = -pad_top + patch_half_height; + const int maximum_x = input_width + pad_left + pad_right - patch_half_width * 2; + const int maximum_y = input_height + pad_top + pad_bottom - patch_half_height * 2; const T border_value(0); @@ -95,9 +95,9 @@ SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTe size_t filter_offset = filter_plane * out_z; T val(0); - for(int j = y - filter_half_height; j <= static_cast(y + filter_half_height); ++j) + for(int j = y - patch_half_height; j <= y + patch_half_height; j += dilation.y()) { - for(int i = x - filter_half_width; i <= static_cast(x + filter_half_width); ++i) + for(int i = x - patch_half_width; i <= x + patch_half_width; i += dilation.x()) { coords.set(0, i); coords.set(1, j); @@ -119,7 +119,7 @@ SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTe template <> SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, - const PadStrideInfo &conv_info, unsigned int depth_multiplier) + const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation) { SimpleTensor dst{ dst_shape, src.data_type(), 1, src.quantization_info() }; @@ -145,18 +145,18 @@ SimpleTensor depthwise_convolution(const SimpleTensor &src, co const int input_depth = src.shape().z(); const int num_batches = src.shape().total_size() / (input_width * input_height * input_depth); - const int filter_half_width = filter_width / 2; - const int filter_half_height = filter_height / 2; - const int pad_left = conv_info.pad_left(); const int pad_top = conv_info.pad_top(); const int pad_right = conv_info.pad_right(); const int pad_bottom = conv_info.pad_bottom(); - const int minimum_x = -pad_left + filter_half_width; - const int minimum_y = -pad_top + filter_half_height; - const int maximum_x = input_width + pad_left - filter_half_width + pad_right - filter_half_width; - const int maximum_y = input_height + pad_top - filter_half_height + pad_bottom - filter_half_height; + const int patch_half_width = (filter_width + (dilation.x() - 1) * (filter_width - 1)) / 2; + const int patch_half_height = (filter_height + (dilation.y() - 1) * (filter_height - 1)) / 2; + + const int minimum_x = -pad_left + patch_half_width; + const int minimum_y = -pad_top + patch_half_height; + const int maximum_x = input_width + pad_left + pad_right - patch_half_width * 2; + const int maximum_y = input_height + pad_top + pad_bottom - patch_half_height * 2; int out_pos = 0; for(int r = 0; r < num_batches; ++r) @@ -176,9 +176,9 @@ SimpleTensor depthwise_convolution(const SimpleTensor &src, co int filter_offset = filter_plane * out_z; int32_t val = 0; - for(int j = y - filter_half_height; j <= (y + filter_half_height); ++j) + for(int j = y - patch_half_height; j <= y + patch_half_height; j += dilation.y()) { - for(int i = x - filter_half_width; i <= (x + filter_half_width); ++i) + for(int i = x - patch_half_width; i <= x + patch_half_width; i += dilation.x()) { coords.set(0, i); coords.set(1, j); @@ -206,10 +206,10 @@ SimpleTensor depthwise_convolution(const SimpleTensor &src, co } template SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, - const PadStrideInfo &conv_info, unsigned int depth_multiplier); + const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation); template SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, - const PadStrideInfo &conv_info, unsigned int depth_multiplier); + const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/DepthwiseConvolutionLayer.h b/tests/validation/reference/DepthwiseConvolutionLayer.h index bab338723d..2146611d13 100644 --- a/tests/validation/reference/DepthwiseConvolutionLayer.h +++ b/tests/validation/reference/DepthwiseConvolutionLayer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -37,7 +37,7 @@ namespace reference { template SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, const PadStrideInfo &conv_info, - unsigned int depth_multiplier); + unsigned int depth_multiplier, const Size2D &dilation = Size2D(1U, 1U)); } // namespace reference } // namespace validation } // namespace test -- cgit v1.2.1