From 0cbb927ac309e332ac6e6f1ab9170f041f0138ab Mon Sep 17 00:00:00 2001 From: Michele Di Giorgio Date: Thu, 1 Mar 2018 16:56:48 +0000 Subject: COMPMID-804: Add NHWC data format support for NEON batch normalisation Change-Id: I04892e7be3f5aa58cd95917a4f90a6b4ffcf6efc Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/122897 Reviewed-by: Giorgio Arena Tested-by: Jenkins Reviewed-by: Anthony Barbier --- .../validation/reference/BatchNormalizationLayer.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'tests/validation/reference/BatchNormalizationLayer.cpp') diff --git a/tests/validation/reference/BatchNormalizationLayer.cpp b/tests/validation/reference/BatchNormalizationLayer.cpp index c8badacc79..ae309d9093 100644 --- a/tests/validation/reference/BatchNormalizationLayer.cpp +++ b/tests/validation/reference/BatchNormalizationLayer.cpp @@ -27,6 +27,7 @@ #include "tests/validation/FixedPoint.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/Permute.h" namespace arm_compute { @@ -41,6 +42,7 @@ 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()); @@ -86,12 +88,14 @@ SimpleTensor batch_normalization_layer(const SimpleTensor &src, const Simp { ARM_COMPUTE_UNUSED(fixed_point_position); - SimpleTensor result(src.shape(), src.data_type()); + 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()); - 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); + 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); for(int r = 0; r < upper_dims; ++r) { @@ -103,7 +107,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 = src[pos] - mean[i]; + const float numerator = perm_src[pos] - mean[i]; const float x_bar = numerator / denominator; result[pos] = beta[i] + x_bar * gamma[i]; } @@ -116,6 +120,10 @@ 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, -- cgit v1.2.1