diff options
author | Matthew Jackson <matthew.jackson@arm.com> | 2019-08-22 16:13:27 +0100 |
---|---|---|
committer | Matthew Jackson <matthew.jackson@arm.com> | 2019-08-28 09:22:18 +0000 |
commit | b9070a42a44ec1a0102e2f0b04523d2e96392903 (patch) | |
tree | 476ae6897e26380a00e4ccfdcd315d6b6f884622 /tests/validation/reference | |
parent | 275f99cb09606191c5589952d57175be655de74a (diff) | |
download | ComputeLibrary-b9070a42a44ec1a0102e2f0b04523d2e96392903.tar.gz |
COMPMID-2605: Add asymmetric padding support for Deconvolution layer
Change-Id: I63b773bdce25f1342ccd3a08ded623a1508f70fe
Signed-off-by: Matthew Jackson <matthew.jackson@arm.com>
Reviewed-on: https://review.mlplatform.org/c/1797
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
Reviewed-by: Giuseppe Rossini <giuseppe.rossini@arm.com>
Diffstat (limited to 'tests/validation/reference')
-rw-r--r-- | tests/validation/reference/DeconvolutionLayer.cpp | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/tests/validation/reference/DeconvolutionLayer.cpp b/tests/validation/reference/DeconvolutionLayer.cpp index af59830722..343ea5e725 100644 --- a/tests/validation/reference/DeconvolutionLayer.cpp +++ b/tests/validation/reference/DeconvolutionLayer.cpp @@ -38,21 +38,44 @@ SimpleTensor<T> deconvolution_layer(const SimpleTensor<T> &src, const SimpleTens const PadStrideInfo &info) { // Create reference - const int stride_x = info.stride().first; - const int stride_y = info.stride().second; - const int weights_width = weights.shape().x(); - const int weights_height = weights.shape().y(); - const int weights_upper_dims = weights.shape().total_size() / (weights_width * weights_height); + const unsigned int pad_left = info.pad_left(); + const unsigned int pad_right = info.pad_right(); + const unsigned int pad_top = info.pad_top(); + const unsigned int pad_bottom = info.pad_bottom(); + const int stride_x = info.stride().first; + const int stride_y = info.stride().second; + const int weights_width = weights.shape().x(); + const int weights_height = weights.shape().y(); + const int weights_upper_dims = weights.shape().total_size() / (weights_width * weights_height); + + ARM_COMPUTE_ERROR_ON(pad_left > (weights.shape().x() - 1)); + ARM_COMPUTE_ERROR_ON(pad_right > (weights.shape().x() - 1)); + ARM_COMPUTE_ERROR_ON(pad_top > (weights.shape().y() - 1)); + ARM_COMPUTE_ERROR_ON(pad_bottom > (weights.shape().y() - 1)); // Find the upsampled dimensions unsigned int out_x = (src.shape().x() - 1) * stride_x + 1; unsigned int out_y = (src.shape().y() - 1) * stride_y + 1; // Find the padding needed for the convolution with stride 1 in order to match output shape - unsigned int padx = output_shape.x() - (out_x - weights_width + 1); - unsigned int pady = output_shape.y() - (out_y - weights_height + 1); - out_x += padx; - out_y += pady; + unsigned int deconv_pad_x = output_shape.x() - (out_x - weights_width + 1); + unsigned int deconv_pad_y = output_shape.y() - (out_y - weights_height + 1); + out_x += deconv_pad_x; + out_y += deconv_pad_y; + + unsigned int deconv_pad_left = pad_right > pad_left ? pad_right - pad_left : 0; + unsigned int deconv_pad_right = pad_left > pad_right ? pad_left - pad_right : 0; + deconv_pad_x -= deconv_pad_left + deconv_pad_right; + ARM_COMPUTE_ERROR_ON((deconv_pad_x % 2) != 0); + deconv_pad_left += deconv_pad_x / 2; + deconv_pad_right += deconv_pad_x / 2; + + unsigned int deconv_pad_top = pad_bottom > pad_top ? pad_bottom - pad_top : 0; + unsigned int deconv_pad_bottom = pad_top > pad_bottom ? pad_top - pad_bottom : 0; + deconv_pad_y -= deconv_pad_top + deconv_pad_bottom; + ARM_COMPUTE_ERROR_ON((deconv_pad_y % 2) != 0); + deconv_pad_top += deconv_pad_y / 2; + deconv_pad_bottom += deconv_pad_y / 2; TensorShape scaled_shape = src.shape(); scaled_shape.set(0, out_x); @@ -64,7 +87,6 @@ SimpleTensor<T> deconvolution_layer(const SimpleTensor<T> &src, const SimpleTens const int width_scaled = scaled.shape().x(); const int height_scaled = scaled.shape().y(); const int num_2d_slices = src.shape().total_size() / (width_in * height_in); - ARM_COMPUTE_ERROR_ON(info.pad().first > (weights.shape().x() - 1)); if(src.data_type() == DataType::QASYMM8) { @@ -94,10 +116,10 @@ SimpleTensor<T> deconvolution_layer(const SimpleTensor<T> &src, const SimpleTens { const int offset_slice_in = slice * width_in * height_in; const int offset_slice_out = slice * width_scaled * height_scaled; - const int start_x = padx / 2; - const int start_y = pady / 2; - const int end_y = height_scaled - pady / 2; - const int end_x = width_scaled - padx / 2; + const int start_x = deconv_pad_left; + const int start_y = deconv_pad_top; + const int end_x = width_scaled - deconv_pad_right; + const int end_y = height_scaled - deconv_pad_bottom; for(int yi = start_y, in_y = 0; yi < end_y; yi += stride_y, in_y++) { |