diff options
author | James Conroy <james.conroy@arm.com> | 2020-01-22 16:40:57 +0000 |
---|---|---|
committer | Narumol Prangnawarat <narumol.prangnawarat@arm.com> | 2020-01-24 14:02:34 +0000 |
commit | 1bde8e31935ac375fd0aaa0dfddb0f7851c16087 (patch) | |
tree | 71352ab311dfac773551694013477ec8befe0a86 | |
parent | f2e175c99612189d640cb3dbb05a5dbb3c92b22f (diff) | |
download | android-nn-driver-1bde8e31935ac375fd0aaa0dfddb0f7851c16087.tar.gz |
IVGCVSW-4260 Fix Transpose CpuRef VTS failures
* Adds missing conversion for permutation vector
from ANN/TF/Numpy format to ArmNN format.
* Corrects legacy tests based on incorrect
permutation vectors.
Signed-off-by: James Conroy <james.conroy@arm.com>
Change-Id: I767142378055e484d22f3ffba34580c528370cfe
-rw-r--r-- | ConversionUtils.hpp | 14 | ||||
-rw-r--r-- | test/1.1/Transpose.cpp | 6 |
2 files changed, 16 insertions, 4 deletions
diff --git a/ConversionUtils.hpp b/ConversionUtils.hpp index f8622dd6..72a668f7 100644 --- a/ConversionUtils.hpp +++ b/ConversionUtils.hpp @@ -3370,8 +3370,20 @@ bool ConvertTranspose(const HalOperation& operation, const HalModel& model, Conv std::vector<uint32_t> outputDims(perm.begin(), perm.begin() + rank); + // Permutation vectors (outputDims) are given in ANN/Tf format, we must convert them to ArmNN format + // For ANN/Tf/ACL: output[i] = input[ perm[i] ] + // For ArmNN: output[ perm[i] ] = input[i] + // e.g. 3,0,1,2 -> 1,2,3,0 + std::vector<unsigned int> armnnPermuteShape(rank); + std::vector<unsigned int>::iterator it; + for (unsigned int i = 0u; i < rank; ++i) + { + it = std::find(outputDims.begin(), outputDims.end(), i); + armnnPermuteShape[i] = static_cast<unsigned int>(std::distance(outputDims.begin(), it)); + } + armnn::PermuteDescriptor permuteDesc; - permuteDesc.m_DimMappings = armnn::PermutationVector(outputDims.data(), outputDims.size()); + permuteDesc.m_DimMappings = armnn::PermutationVector(armnnPermuteShape.data(), armnnPermuteShape.size()); const HalOperand* output = GetOutputOperand<HalPolicy>(operation, 0, model); if (!output) diff --git a/test/1.1/Transpose.cpp b/test/1.1/Transpose.cpp index 1b30aa6b..4d4238ba 100644 --- a/test/1.1/Transpose.cpp +++ b/test/1.1/Transpose.cpp @@ -102,7 +102,7 @@ void TransposeTestImpl(const TestTensor & inputs, int32_t perm[], BOOST_DATA_TEST_CASE(Transpose , COMPUTE_DEVICES) { - int32_t perm[] = {3, 2, 0, 1}; + int32_t perm[] = {2, 3, 1, 0}; TestTensor input{armnn::TensorShape{1, 2, 2, 2},{1, 2, 3, 4, 5, 6, 7, 8}}; TestTensor expected{armnn::TensorShape{2, 2, 2, 1},{1, 5, 2, 6, 3, 7, 4, 8}}; @@ -111,7 +111,7 @@ BOOST_DATA_TEST_CASE(Transpose , COMPUTE_DEVICES) BOOST_DATA_TEST_CASE(TransposeNHWCToArmNN , COMPUTE_DEVICES) { - int32_t perm[] = {0, 2, 3, 1}; + int32_t perm[] = {0, 3, 1, 2}; TestTensor input{armnn::TensorShape{1, 2, 2, 3},{1, 2, 3, 11, 12, 13, 21, 22, 23, 31, 32, 33}}; TestTensor expected{armnn::TensorShape{1, 3, 2, 2},{1, 11, 21, 31, 2, 12, 22, 32, 3, 13, 23, 33}}; @@ -120,7 +120,7 @@ BOOST_DATA_TEST_CASE(TransposeNHWCToArmNN , COMPUTE_DEVICES) BOOST_DATA_TEST_CASE(TransposeArmNNToNHWC , COMPUTE_DEVICES) { - int32_t perm[] = {0, 3, 1, 2}; + int32_t perm[] = {0, 2, 3, 1}; TestTensor input{armnn::TensorShape{1, 2, 2, 2},{1, 2, 3, 4, 5, 6, 7, 8}}; TestTensor expected{armnn::TensorShape{1, 2, 2, 2},{1, 5, 2, 6, 3, 7, 4, 8}}; |