From 595408218a0e17f04d91ff131a8227a4f352ff61 Mon Sep 17 00:00:00 2001 From: James Conroy Date: Thu, 11 Oct 2018 12:39:05 +0100 Subject: IVGCVSW-1978: Support NHWC for ResizeBilinear CpuRef * Adds implementation to plumb DataLayout parameter for ResizeBilinear on CpuRef. * Adds unit tests to execute ResizeBilinear on CpuRef using the NHWC data layout. * Adds DataLayoutIndexed API, allowing easy access to the Channels, Height and Width of a tensor based on its data layout. This reduces code duplication. * Refactors original ResizeBilinear implementation and tests to use the DataLayoutIndexed API when required. Change-Id: Ic2b8916cdd2e370d070175547079d774daf6d7bf --- src/backends/reference/workloads/ResizeBilinear.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/backends/reference/workloads/ResizeBilinear.cpp') diff --git a/src/backends/reference/workloads/ResizeBilinear.cpp b/src/backends/reference/workloads/ResizeBilinear.cpp index 0bce3c7ed8..e098c6c20d 100644 --- a/src/backends/reference/workloads/ResizeBilinear.cpp +++ b/src/backends/reference/workloads/ResizeBilinear.cpp @@ -25,27 +25,31 @@ inline float Lerp(float a, float b, float w) } -void ResizeBilinear(const float* in, const TensorInfo& inputInfo, float* out, const TensorInfo& outputInfo) +void ResizeBilinear(const float* in, + const TensorInfo& inputInfo, + float* out, + const TensorInfo& outputInfo, + DataLayoutIndexed dataLayout) { // We follow the definition of TensorFlow and AndroidNN: the top-left corner of a texel in the output // image is projected into the input image to figure out the interpolants and weights. Note that this // will yield different results than if projecting the centre of output texels. const unsigned int batchSize = inputInfo.GetShape()[0]; - const unsigned int channelCount = inputInfo.GetShape()[1]; + const unsigned int channelCount = inputInfo.GetShape()[dataLayout.GetChannelsIndex()]; - const unsigned int inputHeight = inputInfo.GetShape()[2]; - const unsigned int inputWidth = inputInfo.GetShape()[3]; - const unsigned int outputHeight = outputInfo.GetShape()[2]; - const unsigned int outputWidth = outputInfo.GetShape()[3]; + const unsigned int inputHeight = inputInfo.GetShape()[dataLayout.GetHeightIndex()]; + const unsigned int inputWidth = inputInfo.GetShape()[dataLayout.GetWidthIndex()]; + const unsigned int outputHeight = outputInfo.GetShape()[dataLayout.GetHeightIndex()]; + const unsigned int outputWidth = outputInfo.GetShape()[dataLayout.GetWidthIndex()]; // How much to scale pixel coordinates in the output image, to get the corresponding pixel coordinates // in the input image. const float scaleY = boost::numeric_cast(inputHeight) / boost::numeric_cast(outputHeight); const float scaleX = boost::numeric_cast(inputWidth) / boost::numeric_cast(outputWidth); - TensorBufferArrayView input(inputInfo.GetShape(), in); - TensorBufferArrayView output(outputInfo.GetShape(), out); + TensorBufferArrayView input(inputInfo.GetShape(), in, dataLayout); + TensorBufferArrayView output(outputInfo.GetShape(), out, dataLayout); for (unsigned int n = 0; n < batchSize; ++n) { -- cgit v1.2.1