From 563494c2f447e201e88e6d7133a41e12971777eb Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Mon, 30 Apr 2018 17:29:41 +0100 Subject: COMPMID-1084 Rework the way validation is performed for NHWC data layout Change-Id: I00b95f560548da76718298b642c8166f92421097 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/129520 Tested-by: Jenkins Reviewed-by: Michele DiGiorgio Reviewed-by: Anthony Barbier --- tests/validation/Validation.h | 72 +++++++++++++++++----- .../fixtures/BatchNormalizationLayerFixture.h | 18 +++--- .../fixtures/DepthwiseConvolutionLayerFixture.h | 27 ++++---- .../fixtures/DirectConvolutionLayerFixture.h | 55 +++++------------ tests/validation/fixtures/Im2ColFixture.h | 2 +- tests/validation/fixtures/PoolingLayerFixture.h | 20 +++--- .../reference/BatchNormalizationLayer.cpp | 20 ++---- .../reference/DepthwiseConvolutionLayer.cpp | 39 ++++-------- tests/validation/reference/PoolingLayer.cpp | 36 ++--------- 9 files changed, 128 insertions(+), 161 deletions(-) (limited to 'tests/validation') diff --git a/tests/validation/Validation.h b/tests/validation/Validation.h index 508fb027ca..ac3643ea4a 100644 --- a/tests/validation/Validation.h +++ b/tests/validation/Validation.h @@ -137,19 +137,45 @@ inline ::std::ostream &operator<<(::std::ostream &os, const RelativeTolerance } template -bool compare_dimensions(const Dimensions &dimensions1, const Dimensions &dimensions2) +bool compare_dimensions(const Dimensions &dimensions1, const Dimensions &dimensions2, const DataLayout &data_layout = DataLayout::NCHW) { - if(dimensions1.num_dimensions() != dimensions2.num_dimensions()) + ARM_COMPUTE_ERROR_ON(data_layout == DataLayout::UNKNOWN); + + if(data_layout == DataLayout::NCHW) { - return false; - } + if(dimensions1.num_dimensions() != dimensions2.num_dimensions()) + { + return false; + } - for(unsigned int i = 0; i < dimensions1.num_dimensions(); ++i) + for(unsigned int i = 0; i < dimensions1.num_dimensions(); ++i) + { + if(dimensions1[i] != dimensions2[i]) + { + return false; + } + } + } + else { - if(dimensions1[i] != dimensions2[i]) + // In case a 2D shape becomes 3D after permutation, the permuted tensor will have one dimension more and the first value will be 1 + if((dimensions1.num_dimensions() != dimensions2.num_dimensions()) && ((dimensions1.num_dimensions() != (dimensions2.num_dimensions() + 1)) || (dimensions1.x() != 1))) + { + return false; + } + + if((dimensions1[0] != dimensions2[2]) || (dimensions1[1] != dimensions2[0]) || (dimensions1[2] != dimensions2[1])) { return false; } + + for(unsigned int i = 3; i < dimensions1.num_dimensions(); ++i) + { + if(dimensions1[i] != dimensions2[i]) + { + return false; + } + } } return true; @@ -342,14 +368,14 @@ template void validate(const IAccessor &tensor, const SimpleTensor &reference, U tolerance_value, float tolerance_number, float absolute_tolerance_value) { // Validate with valid region covering the entire shape - validate(tensor, reference, shape_to_valid_region(tensor.shape()), tolerance_value, tolerance_number, absolute_tolerance_value); + validate(tensor, reference, shape_to_valid_region(reference.shape()), tolerance_value, tolerance_number, absolute_tolerance_value); } template ::value>::type> void validate_wrap(const IAccessor &tensor, const SimpleTensor &reference, U tolerance_value, float tolerance_number) { // Validate with valid region covering the entire shape - validate_wrap(tensor, reference, shape_to_valid_region(tensor.shape()), tolerance_value, tolerance_number); + validate_wrap(tensor, reference, shape_to_valid_region(reference.shape()), tolerance_value, tolerance_number); } template @@ -367,7 +393,7 @@ void validate(const IAccessor &tensor, const SimpleTensor &reference, const V } ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape()), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape(), tensor.data_layout()), framework::LogLevel::ERRORS); const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); @@ -377,12 +403,18 @@ void validate(const IAccessor &tensor, const SimpleTensor &reference, const V { const Coordinates id = index2coord(reference.shape(), element_idx); + Coordinates target_id(id); + if(tensor.data_layout() == DataLayout::NHWC) + { + permute(target_id, PermutationVector(2U, 0U, 1U)); + } + if(is_in_valid_region(valid_region, id)) { // Iterate over all channels within one element for(int c = 0; c < min_channels; ++c) { - const T &target_value = reinterpret_cast(tensor(id))[c]; + const T &target_value = reinterpret_cast(tensor(target_id))[c]; const T &reference_value = reinterpret_cast(reference(id))[c]; if(!compare(target_value, reference_value, tolerance_value)) @@ -436,7 +468,7 @@ void validate_wrap(const IAccessor &tensor, const SimpleTensor &reference, co } ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape()), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape(), tensor.data_layout()), framework::LogLevel::ERRORS); const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); @@ -446,12 +478,18 @@ void validate_wrap(const IAccessor &tensor, const SimpleTensor &reference, co { const Coordinates id = index2coord(reference.shape(), element_idx); + Coordinates target_id(id); + if(tensor.data_layout() == DataLayout::NHWC) + { + permute(target_id, PermutationVector(2U, 0U, 1U)); + } + if(is_in_valid_region(valid_region, id)) { // Iterate over all channels within one element for(int c = 0; c < min_channels; ++c) { - const T &target_value = reinterpret_cast(tensor(id))[c]; + const T &target_value = reinterpret_cast(tensor(target_id))[c]; const T &reference_value = reinterpret_cast(reference(id))[c]; bool equal = compare(target_value, reference_value, tolerance_value); @@ -518,7 +556,7 @@ void validate(const IAccessor &tensor, const SimpleTensor &reference, const S } ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape()), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape(), tensor.data_layout()), framework::LogLevel::ERRORS); const int min_elements = std::min(tensor.num_elements(), reference.num_elements()); const int min_channels = std::min(tensor.num_channels(), reference.num_channels()); @@ -528,12 +566,18 @@ void validate(const IAccessor &tensor, const SimpleTensor &reference, const S { const Coordinates id = index2coord(reference.shape(), element_idx); + Coordinates target_id(id); + if(tensor.data_layout() == DataLayout::NHWC) + { + permute(target_id, PermutationVector(2U, 0U, 1U)); + } + if(valid_mask[element_idx] == 1) { // Iterate over all channels within one element for(int c = 0; c < min_channels; ++c) { - const T &target_value = reinterpret_cast(tensor(id))[c]; + const T &target_value = reinterpret_cast(tensor(target_id))[c]; const T &reference_value = reinterpret_cast(reference(id))[c]; if(!compare(target_value, reference_value, tolerance_value)) diff --git a/tests/validation/fixtures/BatchNormalizationLayerFixture.h b/tests/validation/fixtures/BatchNormalizationLayerFixture.h index 7e072e7023..b7e32a6f37 100644 --- a/tests/validation/fixtures/BatchNormalizationLayerFixture.h +++ b/tests/validation/fixtures/BatchNormalizationLayerFixture.h @@ -52,13 +52,8 @@ public: _use_beta = use_beta; _use_gamma = use_gamma; - if(data_layout == DataLayout::NHWC) - { - permute(shape0, PermutationVector(2U, 0U, 1U)); - } - _target = compute_target(shape0, shape1, epsilon, act_info, dt, data_layout, fractional_bits); - _reference = compute_reference(shape0, shape1, epsilon, act_info, dt, data_layout, fractional_bits); + _reference = compute_reference(shape0, shape1, epsilon, act_info, dt, fractional_bits); } protected: @@ -125,8 +120,13 @@ protected: } } - TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, float epsilon, ActivationLayerInfo act_info, DataType dt, DataLayout data_layout, int fixed_point_position) + TensorType compute_target(TensorShape shape0, const TensorShape &shape1, float epsilon, ActivationLayerInfo act_info, DataType dt, DataLayout data_layout, int fixed_point_position) { + if(data_layout == DataLayout::NHWC) + { + permute(shape0, PermutationVector(2U, 0U, 1U)); + } + // Create tensors TensorType src = create_tensor(shape0, dt, 1, fixed_point_position, QuantizationInfo(), data_layout); TensorType dst = create_tensor(shape0, dt, 1, fixed_point_position, QuantizationInfo(), data_layout); @@ -172,10 +172,10 @@ protected: return dst; } - SimpleTensor compute_reference(const TensorShape &shape0, const TensorShape &shape1, float epsilon, ActivationLayerInfo act_info, DataType dt, DataLayout data_layout, int fixed_point_position) + SimpleTensor compute_reference(const TensorShape &shape0, const TensorShape &shape1, float epsilon, ActivationLayerInfo act_info, DataType dt, int fixed_point_position) { // Create reference - SimpleTensor ref_src{ shape0, dt, 1, fixed_point_position, QuantizationInfo(), data_layout }; + SimpleTensor ref_src{ shape0, dt, 1, fixed_point_position }; SimpleTensor ref_mean{ shape1, dt, 1, fixed_point_position }; SimpleTensor ref_var{ shape1, dt, 1, fixed_point_position }; SimpleTensor ref_beta{ shape1, dt, 1, fixed_point_position }; diff --git a/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h b/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h index b7bca8dbf3..2f01f43d8b 100644 --- a/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h +++ b/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h @@ -70,15 +70,8 @@ public: weights_shape.set(2, out_shape.z()); const TensorShape biases_shape(weights_shape[2]); - if(data_layout == DataLayout::NHWC) - { - permute(in_shape, PermutationVector(2U, 0U, 1U)); - permute(weights_shape, PermutationVector(2U, 0U, 1U)); - permute(out_shape, PermutationVector(2U, 0U, 1U)); - } - _target = compute_target(in_shape, weights_shape, biases_shape, out_shape, pad_stride_info, depth_multiplier, data_type, bias_data_type, quantization_info, data_layout); - _reference = compute_reference(in_shape, weights_shape, biases_shape, out_shape, pad_stride_info, depth_multiplier, data_type, bias_data_type, quantization_info, data_layout); + _reference = compute_reference(in_shape, weights_shape, biases_shape, out_shape, pad_stride_info, depth_multiplier, data_type, bias_data_type, quantization_info); } protected: @@ -111,10 +104,16 @@ protected: } } - TensorType compute_target(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const TensorShape &output_shape, PadStrideInfo &pad_stride_info, - unsigned int depth_multiplier, + TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, TensorShape biases_shape, TensorShape output_shape, PadStrideInfo &pad_stride_info, unsigned int depth_multiplier, const DataType data_type, const DataType bias_data_type, const QuantizationInfo quantization_info, const DataLayout data_layout) { + if(data_layout == DataLayout::NHWC) + { + permute(input_shape, PermutationVector(2U, 0U, 1U)); + permute(weights_shape, PermutationVector(2U, 0U, 1U)); + permute(output_shape, PermutationVector(2U, 0U, 1U)); + } + // Create tensors TensorType src = create_tensor(input_shape, data_type, 1, 0, quantization_info, data_layout); TensorType weights = create_tensor(weights_shape, data_type, 1, 0, quantization_info, data_layout); @@ -154,11 +153,11 @@ protected: SimpleTensor compute_reference(const TensorShape &in_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const TensorShape &out_shape, const PadStrideInfo &pad_stride_info, unsigned int depth_multiplier, - const DataType data_type, const DataType bias_data_type, const QuantizationInfo quantization_info, const DataLayout data_layout) + const DataType data_type, const DataType bias_data_type, const QuantizationInfo quantization_info) { - SimpleTensor src{ in_shape, data_type, 1, 0, quantization_info, data_layout }; - SimpleTensor weights{ weights_shape, data_type, 1, 0, quantization_info, data_layout }; - SimpleTensor biases{ biases_shape, bias_data_type, 1, 0, quantization_info, data_layout }; + SimpleTensor src{ in_shape, data_type, 1, 0, quantization_info }; + SimpleTensor weights{ weights_shape, data_type, 1, 0, quantization_info }; + SimpleTensor biases{ biases_shape, bias_data_type, 1, 0, quantization_info }; fill(src, 0); fill(weights, 1); diff --git a/tests/validation/fixtures/DirectConvolutionLayerFixture.h b/tests/validation/fixtures/DirectConvolutionLayerFixture.h index 9ea4061e53..38ddf33e24 100644 --- a/tests/validation/fixtures/DirectConvolutionLayerFixture.h +++ b/tests/validation/fixtures/DirectConvolutionLayerFixture.h @@ -67,22 +67,13 @@ public: const PadStrideInfo info(stride_x, stride_y, pad_x, pad_y, DimensionRoundingType::FLOOR); const DataType bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type; - if(data_layout == DataLayout::NHWC) - { - permute(input_shape, PermutationVector(2U, 0U, 1U)); - permute(weights_shape, PermutationVector(2U, 0U, 1U)); - } - TensorInfo input_info = TensorInfo(input_shape, 1, data_type, _fractional_bits); TensorInfo weights_info = TensorInfo(weights_shape, 1, data_type, _fractional_bits); - input_info.set_data_layout(data_layout); - weights_info.set_data_layout(data_layout); - const TensorShape output_shape = compute_deep_convolution_shape(input_info, weights_info, info); _target = compute_target(input_shape, weights_shape, bias_shape, output_shape, info, data_type, bias_data_type, fractional_bits, quantization_info, act_info, data_layout); - _reference = compute_reference(input_shape, weights_shape, bias_shape, output_shape, info, data_type, bias_data_type, fractional_bits, quantization_info, act_info, data_layout); + _reference = compute_reference(input_shape, weights_shape, bias_shape, output_shape, info, data_type, bias_data_type, fractional_bits, quantization_info, act_info); } template @@ -98,15 +89,8 @@ public: const DataType bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type; - if(data_layout == DataLayout::NHWC) - { - permute(input_shape, PermutationVector(2U, 0U, 1U)); - permute(weights_shape, PermutationVector(2U, 0U, 1U)); - permute(output_shape, PermutationVector(2U, 0U, 1U)); - } - _target = compute_target(input_shape, weights_shape, bias_shape, output_shape, info, data_type, bias_data_type, fractional_bits, quantization_info, act_info, data_layout); - _reference = compute_reference(input_shape, weights_shape, bias_shape, output_shape, info, data_type, bias_data_type, fractional_bits, quantization_info, act_info, data_layout); + _reference = compute_reference(input_shape, weights_shape, bias_shape, output_shape, info, data_type, bias_data_type, fractional_bits, quantization_info, act_info); } protected: @@ -139,9 +123,16 @@ protected: } } - TensorType compute_target(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, const PadStrideInfo &info, + TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, const TensorShape &bias_shape, TensorShape output_shape, const PadStrideInfo &info, DataType data_type, DataType bias_data_type, int fixed_point_position, QuantizationInfo quantization_info, ActivationLayerInfo act_info, const DataLayout &data_layout) { + if(data_layout == DataLayout::NHWC) + { + permute(input_shape, PermutationVector(2U, 0U, 1U)); + permute(weights_shape, PermutationVector(2U, 0U, 1U)); + permute(output_shape, PermutationVector(2U, 0U, 1U)); + } + // Create tensors TensorType src = create_tensor(input_shape, data_type, 1, fixed_point_position, quantization_info, data_layout); TensorType weights = create_tensor(weights_shape, data_type, 1, fixed_point_position, quantization_info, data_layout); @@ -180,13 +171,11 @@ protected: } SimpleTensor compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, const PadStrideInfo &info, - DataType data_type, DataType bias_data_type, int fixed_point_position, QuantizationInfo quantization_info, ActivationLayerInfo act_info, const DataLayout &data_layout) + DataType data_type, DataType bias_data_type, int fixed_point_position, QuantizationInfo quantization_info, ActivationLayerInfo act_info) { - ARM_COMPUTE_ERROR_ON(data_layout == DataLayout::UNKNOWN); - // Create reference - SimpleTensor src{ input_shape, data_type, 1, fixed_point_position, quantization_info, data_layout }; - SimpleTensor weights{ weights_shape, data_type, 1, fixed_point_position, quantization_info, data_layout }; + SimpleTensor src{ input_shape, data_type, 1, fixed_point_position, quantization_info }; + SimpleTensor weights{ weights_shape, data_type, 1, fixed_point_position, quantization_info }; SimpleTensor bias{ bias_shape, bias_data_type, 1, fixed_point_position, quantization_info }; // Fill reference @@ -194,23 +183,7 @@ protected: fill(weights, 1); fill(bias, 2); - SimpleTensor dst; - - // FIXME: move to reference once all functions that call reference::convolution_layer<>() support NHWC - if(src.data_layout() == DataLayout::NHWC) - { - SimpleTensor src_nchw = reference::permute(src, PermutationVector(1U, 2U, 0U)); - SimpleTensor weights_nchw = reference::permute(weights, PermutationVector(1U, 2U, 0U)); - - TensorShape output_shape_nchw{ output_shape }; - permute(output_shape_nchw, PermutationVector(1U, 2U, 0U)); - - dst = reference::permute(reference::convolution_layer(src_nchw, weights_nchw, bias, output_shape_nchw, info), PermutationVector(2U, 0U, 1U)); - } - else - { - dst = reference::convolution_layer(src, weights, bias, output_shape, info); - } + SimpleTensor dst = reference::convolution_layer(src, weights, bias, output_shape, info); return (act_info.enabled()) ? reference::activation_layer(dst, act_info) : dst; } diff --git a/tests/validation/fixtures/Im2ColFixture.h b/tests/validation/fixtures/Im2ColFixture.h index b6e4cd0023..7ef3cdcdcd 100644 --- a/tests/validation/fixtures/Im2ColFixture.h +++ b/tests/validation/fixtures/Im2ColFixture.h @@ -83,7 +83,7 @@ protected: { // Create tensors TensorType src = create_tensor(input_shape, data_type, 1, 0, _quant_info, _data_layout); - TensorType dst = create_tensor(output_shape, data_type, 1, 0, _quant_info, _data_layout); + TensorType dst = create_tensor(output_shape, data_type, 1, 0, _quant_info); // Create and configure function FunctionType im2col_func; diff --git a/tests/validation/fixtures/PoolingLayerFixture.h b/tests/validation/fixtures/PoolingLayerFixture.h index a40baf415a..27b033a06c 100644 --- a/tests/validation/fixtures/PoolingLayerFixture.h +++ b/tests/validation/fixtures/PoolingLayerFixture.h @@ -53,14 +53,8 @@ public: _quantization_info = quantization_info; _pool_info = pool_info; - // Change shape in case of NHWC. - if(data_layout == DataLayout::NHWC) - { - permute(shape, PermutationVector(2U, 0U, 1U)); - } - _target = compute_target(shape, pool_info, data_type, data_layout, fractional_bits, quantization_info); - _reference = compute_reference(shape, pool_info, data_type, data_layout, fractional_bits, quantization_info); + _reference = compute_reference(shape, pool_info, data_type, fractional_bits, quantization_info); } protected: @@ -84,9 +78,15 @@ protected: } } - TensorType compute_target(const TensorShape &shape, PoolingLayerInfo info, + TensorType compute_target(TensorShape shape, PoolingLayerInfo info, DataType data_type, DataLayout data_layout, int fixed_point_position, QuantizationInfo quantization_info) { + // Change shape in case of NHWC. + if(data_layout == DataLayout::NHWC) + { + permute(shape, PermutationVector(2U, 0U, 1U)); + } + // Create tensors TensorType src = create_tensor(shape, data_type, 1, fixed_point_position, quantization_info, data_layout); TensorType dst; @@ -115,10 +115,10 @@ protected: } SimpleTensor compute_reference(const TensorShape &shape, PoolingLayerInfo info, - DataType data_type, DataLayout data_layout, int fixed_point_position, QuantizationInfo quantization_info) + DataType data_type, int fixed_point_position, QuantizationInfo quantization_info) { // Create reference - SimpleTensor src{ shape, data_type, 1, fixed_point_position, quantization_info, data_layout }; + SimpleTensor src{ shape, data_type, 1, fixed_point_position, quantization_info }; // Fill reference fill(src); diff --git a/tests/validation/reference/BatchNormalizationLayer.cpp b/tests/validation/reference/BatchNormalizationLayer.cpp index ae309d9093..c8badacc79 100644 --- a/tests/validation/reference/BatchNormalizationLayer.cpp +++ b/tests/validation/reference/BatchNormalizationLayer.cpp @@ -27,7 +27,6 @@ #include "tests/validation/FixedPoint.h" #include "tests/validation/Helpers.h" -#include "tests/validation/reference/Permute.h" namespace arm_compute { @@ -42,7 +41,6 @@ template ::value, int>:: SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, const SimpleTensor &gamma, float epsilon, ActivationLayerInfo act_info, int fixed_point_position) { - ARM_COMPUTE_ERROR_ON_MSG(src.data_layout() == DataLayout::NHWC, "Unsupported NHWC format"); ARM_COMPUTE_UNUSED(act_info); SimpleTensor result(src.shape(), src.data_type()); @@ -88,14 +86,12 @@ SimpleTensor batch_normalization_layer(const SimpleTensor &src, const Simp { ARM_COMPUTE_UNUSED(fixed_point_position); - const bool is_nhwc = src.data_layout() == DataLayout::NHWC; - const SimpleTensor perm_src = (is_nhwc) ? permute(src, PermutationVector(1U, 2U, 0U)) : src; - SimpleTensor result(perm_src.shape(), perm_src.data_type()); + SimpleTensor result(src.shape(), src.data_type()); - const auto cols = static_cast(perm_src.shape()[0]); - const auto rows = static_cast(perm_src.shape()[1]); - const auto depth = static_cast(perm_src.shape()[2]); - const int upper_dims = perm_src.shape().total_size() / (cols * rows * depth); + const auto cols = static_cast(src.shape()[0]); + const auto rows = static_cast(src.shape()[1]); + const auto depth = static_cast(src.shape()[2]); + const int upper_dims = src.shape().total_size() / (cols * rows * depth); for(int r = 0; r < upper_dims; ++r) { @@ -107,7 +103,7 @@ SimpleTensor batch_normalization_layer(const SimpleTensor &src, const Simp { const int pos = l + k * cols + i * rows * cols + r * cols * rows * depth; const float denominator = sqrt(var[i] + epsilon); - const float numerator = perm_src[pos] - mean[i]; + const float numerator = src[pos] - mean[i]; const float x_bar = numerator / denominator; result[pos] = beta[i] + x_bar * gamma[i]; } @@ -120,10 +116,6 @@ SimpleTensor batch_normalization_layer(const SimpleTensor &src, const Simp result = activation_layer(result, act_info); } - if(is_nhwc) - { - result = permute(result, PermutationVector(2U, 0U, 1U)); - } return result; } template SimpleTensor batch_normalization_layer(const SimpleTensor &src, const SimpleTensor &mean, const SimpleTensor &var, const SimpleTensor &beta, diff --git a/tests/validation/reference/DepthwiseConvolutionLayer.cpp b/tests/validation/reference/DepthwiseConvolutionLayer.cpp index 207e5fc45c..10c617e953 100644 --- a/tests/validation/reference/DepthwiseConvolutionLayer.cpp +++ b/tests/validation/reference/DepthwiseConvolutionLayer.cpp @@ -24,7 +24,6 @@ #include "DepthwiseConvolutionLayer.h" #include "ConvolutionLayer.h" -#include "Permute.h" #include "Utils.h" #include "tests/validation/FixedPoint.h" @@ -51,9 +50,11 @@ namespace reference * */ template -void depthwise_convolution_nchw(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, SimpleTensor &dst, const PadStrideInfo &conv_info, - unsigned int depth_multiplier) +SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, const PadStrideInfo &conv_info, + unsigned int depth_multiplier) { + SimpleTensor dst{ dst_shape, src.data_type(), 1, src.fixed_point_position() }; + // Compute reference const int filter_width = weights.shape().x(); const int filter_height = weights.shape().y(); @@ -113,11 +114,16 @@ void depthwise_convolution_nchw(const SimpleTensor &src, const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, SimpleTensor &dst, const PadStrideInfo &conv_info, - unsigned int depth_multiplier) +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) { + SimpleTensor dst{ dst_shape, src.data_type(), 1, src.fixed_point_position(), src.quantization_info() }; + // Create reference const int input_offset = -src.quantization_info().offset; const float input_scale = src.quantization_info().scale; @@ -196,33 +202,10 @@ void depthwise_convolution_nchw(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) -{ - SimpleTensor dst{ dst_shape, src.data_type(), 1, src.fixed_point_position(), src.quantization_info() }; - - if(src.data_layout() == DataLayout::NHWC) - { - SimpleTensor src_nchw = reference::permute(src, PermutationVector(1U, 2U, 0U)); - SimpleTensor weights_nchw = reference::permute(weights, PermutationVector(1U, 2U, 0U)); - SimpleTensor dst_nchw = reference::permute(dst, PermutationVector(1U, 2U, 0U)); - - depthwise_convolution_nchw(src_nchw, weights_nchw, biases, dst_nchw, conv_info, depth_multiplier); - - return reference::permute(dst_nchw, PermutationVector(2U, 0U, 1U)); - } - - depthwise_convolution_nchw(src, weights, biases, dst, conv_info, depth_multiplier); return dst; } -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); - 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); diff --git a/tests/validation/reference/PoolingLayer.cpp b/tests/validation/reference/PoolingLayer.cpp index f3f456b26e..69734545c9 100644 --- a/tests/validation/reference/PoolingLayer.cpp +++ b/tests/validation/reference/PoolingLayer.cpp @@ -23,7 +23,6 @@ */ #include "PoolingLayer.h" -#include "Permute.h" #include "arm_compute/core/Types.h" #include "arm_compute/core/utils/misc/ShapeCalculator.h" #include "tests/validation/FixedPoint.h" @@ -39,11 +38,14 @@ namespace reference { using namespace arm_compute::misc::shape_calculator; -template -SimpleTensor pooling_layer_nchw(const SimpleTensor &src, SimpleTensor &dst, const PoolingLayerInfo &info) +template ::value, int>::type> +SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info) { ARM_COMPUTE_ERROR_ON(info.is_global_pooling() && (src.shape().x() != src.shape().y())); + // Create reference + SimpleTensor dst{ compute_pool_shape(TensorInfo(src.shape(), 1, src.data_type(), src.fixed_point_position()), info), src.data_type(), 1, src.fixed_point_position() }; + const int pool_size_x = info.is_global_pooling() ? src.shape().x() : info.pool_size().width; const int pool_size_y = info.is_global_pooling() ? src.shape().y() : info.pool_size().height; PoolingType type = info.pool_type(); @@ -171,10 +173,7 @@ SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo bool exclude_padding = info.exclude_padding(); // Create reference - TensorInfo src_info(src.shape(), 1, src.data_type(), src.fixed_point_position()); - src_info.set_data_layout(src.data_layout()); - - SimpleTensor dst{ compute_pool_shape(src_info, info), src.data_type(), 1, src.fixed_point_position() }; + SimpleTensor dst{ compute_pool_shape(TensorInfo(src.shape(), 1, src.data_type(), src.fixed_point_position()), info), src.data_type(), 1, src.fixed_point_position() }; const auto w_dst = static_cast(dst.shape()[0]); const auto h_dst = static_cast(dst.shape()[1]); @@ -284,29 +283,6 @@ SimpleTensor pooling_layer(const SimpleTensor &src, c return dst; } -template ::value, int>::type> -SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info) -{ - TensorInfo src_info(src.shape(), 1, src.data_type(), src.fixed_point_position()); - src_info.set_data_layout(src.data_layout()); - - SimpleTensor dst{ compute_pool_shape(src_info, info), src.data_type(), 1, src.fixed_point_position() }; - - if(src.data_layout() == DataLayout::NHWC) - { - SimpleTensor src_nchw = reference::permute(src, PermutationVector(1U, 2U, 0U)); - SimpleTensor dst_nchw = reference::permute(dst, PermutationVector(1U, 2U, 0U)); - - pooling_layer_nchw(src_nchw, dst_nchw, info); - - return reference::permute(dst_nchw, PermutationVector(2U, 0U, 1U)); - } - else - { - return pooling_layer_nchw(src, dst, info); - } -} - template SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info); template SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info); template SimpleTensor pooling_layer(const SimpleTensor &src, const PoolingLayerInfo &info); -- cgit v1.2.1