From 7b1845206d723a91aec811edaf7cb0cf832dfd25 Mon Sep 17 00:00:00 2001 From: Teresa Charlin Date: Thu, 18 Jul 2019 16:23:58 +0100 Subject: IVGCVSW-3476 Add InferOutputShapes unit tests for convolution workloads * Convolution2d, DepthwiseConvolution2d & TransposeConvolution2d Signed-off-by: Teresa Charlin Change-Id: I2490c684765d8c7349183572f46e86c201b8eefd --- src/armnn/test/InferOutputTests.cpp | 9 ++++ src/armnn/test/InferOutputTests.hpp | 97 +++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) (limited to 'src/armnn/test') diff --git a/src/armnn/test/InferOutputTests.cpp b/src/armnn/test/InferOutputTests.cpp index 24ae8b263b..4581d87a5b 100644 --- a/src/armnn/test/InferOutputTests.cpp +++ b/src/armnn/test/InferOutputTests.cpp @@ -31,4 +31,13 @@ ARMNN_SIMPLE_TEST_CASE(StackInferOutputShapeFromInputsNoMatch, StackInferOut ARMNN_SIMPLE_TEST_CASE(StackValidateTensorShapesFromInputsMatch, StackValidateTensorShapesFromInputsMatchTest) ARMNN_SIMPLE_TEST_CASE(StackValidateTensorShapesFromInputsNoMatch, StackValidateTensorShapesFromInputsNoMatchTest) +// Convolution2D +ARMNN_SIMPLE_TEST_CASE(Convolution2dInferOutputShape, Convolution2dInferOutputShapeTest) + +// DepthwiseConvolution2D +ARMNN_SIMPLE_TEST_CASE(DepthwiseConvolution2dInferOutputShape, DepthwiseConvolution2dInferOutputShapeTest) + +// TransposeConvolution2D +ARMNN_SIMPLE_TEST_CASE(TransposeConvolution2dInferOutputShape, TransposeConvolution2dInferOutputShapeTest) + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnn/test/InferOutputTests.hpp b/src/armnn/test/InferOutputTests.hpp index 47eabd3cb0..58a081a130 100644 --- a/src/armnn/test/InferOutputTests.hpp +++ b/src/armnn/test/InferOutputTests.hpp @@ -347,3 +347,100 @@ void StackValidateTensorShapesFromInputsNoMatchTest() // Graph::InferTensorInfos calls Layer::ValidateTensorShapesFromInputs BOOST_CHECK_THROW(graph.InferTensorInfos(), armnn::LayerValidationException); } + +void Convolution2dInferOutputShapeTest() +{ + armnn::Graph graph; + + armnn::Convolution2dDescriptor descriptor; + descriptor.m_DilationX = 2; + descriptor.m_DilationY = 2; + descriptor.m_PadTop = 1; + descriptor.m_PadBottom = 1; + descriptor.m_PadLeft = 1; + descriptor.m_PadRight = 1; + descriptor.m_StrideX = 3; + descriptor.m_StrideY = 3; + descriptor.m_DataLayout = armnn::DataLayout::NCHW; + + armnn::Convolution2dLayer* const convolution2dLayer = + graph.AddLayer(descriptor, "convolution2d"); + + std::vector shapes; + const std::vector inputSize = {1, 2, 10, 10}; + armnn::TensorShape inputShape(4, inputSize.data()); + shapes.push_back(inputShape); + + const std::vector filterSize = { 1, 2, 2, 2}; + armnn::TensorShape filterShape(4, filterSize.data()); + shapes.push_back(filterShape); + + const std::vector expectedOutputSizes = {1, 1, 4, 4}; + armnn::TensorShape expectedOutputShape(4, expectedOutputSizes.data()); + + BOOST_CHECK(expectedOutputShape == convolution2dLayer->InferOutputShapes(shapes).at(0)); +} + +void TransposeConvolution2dInferOutputShapeTest() +{ + armnn::Graph graph; + + armnn::TransposeConvolution2dDescriptor descriptor; + descriptor.m_PadTop = 0; + descriptor.m_PadBottom = 1; + descriptor.m_PadLeft = 0; + descriptor.m_PadRight = 1; + descriptor.m_StrideX = 2; + descriptor.m_StrideY = 2; + descriptor.m_DataLayout = armnn::DataLayout::NCHW; + + armnn::TransposeConvolution2dLayer* const transposeConvolution2dLayer = + graph.AddLayer(descriptor, "TransposeConvolution2d"); + + std::vector shapes; + const std::vector inputSize = {1, 2, 3, 3}; + armnn::TensorShape inputShape(4, inputSize.data()); + shapes.push_back(inputShape); + + const std::vector filterSize = { 1, 2, 3, 3}; + armnn::TensorShape filterShape(4, filterSize.data()); + shapes.push_back(filterShape); + + const std::vector expectedOutputSizes = {1, 2, 6, 6}; + armnn::TensorShape expectedOutputShape(4, expectedOutputSizes.data()); + + BOOST_CHECK(expectedOutputShape == transposeConvolution2dLayer->InferOutputShapes(shapes).at(0)); +} + +void DepthwiseConvolution2dInferOutputShapeTest() +{ + armnn::Graph graph; + + armnn::DepthwiseConvolution2dDescriptor descriptor; + descriptor.m_DilationX = 3; + descriptor.m_DilationY = 3; + descriptor.m_PadTop = 1; + descriptor.m_PadBottom = 2; + descriptor.m_PadLeft = 1; + descriptor.m_PadRight = 2; + descriptor.m_StrideX = 2; + descriptor.m_StrideY = 2; + descriptor.m_DataLayout = armnn::DataLayout::NCHW; + + armnn::DepthwiseConvolution2dLayer* const depthwiseConvolution2dLayer = + graph.AddLayer(descriptor, "DepthwiseConvolution2d"); + + std::vector shapes; + const std::vector inputSize = {1, 2, 10, 10}; + armnn::TensorShape inputShape(4, inputSize.data()); + shapes.push_back(inputShape); + + const std::vector filterSize = { 1, 2, 3, 3}; + armnn::TensorShape filterShape(4, filterSize.data()); + shapes.push_back(filterShape); + + const std::vector expectedOutputSizes = {1, 2, 4, 4}; + armnn::TensorShape expectedOutputShape(4, expectedOutputSizes.data()); + + BOOST_CHECK(expectedOutputShape == depthwiseConvolution2dLayer->InferOutputShapes(shapes).at(0)); +} \ No newline at end of file -- cgit v1.2.1