IVGCVSW-3476 Add InferOutputShapes unit tests for convolution workloads

* Convolution2d, DepthwiseConvolution2d & TransposeConvolution2d

Signed-off-by: Teresa Charlin <teresa.charlinreyes@arm.com>
Change-Id: I2490c684765d8c7349183572f46e86c201b8eefd
diff --git a/src/armnn/test/InferOutputTests.cpp b/src/armnn/test/InferOutputTests.cpp
index 24ae8b2..4581d87 100644
--- a/src/armnn/test/InferOutputTests.cpp
+++ b/src/armnn/test/InferOutputTests.cpp
@@ -31,4 +31,13 @@
 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 47eabd3..58a081a 100644
--- a/src/armnn/test/InferOutputTests.hpp
+++ b/src/armnn/test/InferOutputTests.hpp
@@ -347,3 +347,100 @@
     // 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<armnn::Convolution2dLayer>(descriptor, "convolution2d");
+
+    std::vector<armnn::TensorShape> shapes;
+    const std::vector<unsigned int> inputSize = {1, 2, 10, 10};
+    armnn::TensorShape inputShape(4, inputSize.data());
+    shapes.push_back(inputShape);
+
+    const std::vector<unsigned int> filterSize = { 1, 2, 2, 2};
+    armnn::TensorShape filterShape(4, filterSize.data());
+    shapes.push_back(filterShape);
+
+    const std::vector<unsigned int> 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<armnn::TransposeConvolution2dLayer>(descriptor, "TransposeConvolution2d");
+
+    std::vector<armnn::TensorShape> shapes;
+    const std::vector<unsigned int> inputSize = {1, 2, 3, 3};
+    armnn::TensorShape inputShape(4, inputSize.data());
+    shapes.push_back(inputShape);
+
+    const std::vector<unsigned int> filterSize = { 1, 2, 3, 3};
+    armnn::TensorShape filterShape(4, filterSize.data());
+    shapes.push_back(filterShape);
+
+    const std::vector<unsigned int> 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<armnn::DepthwiseConvolution2dLayer>(descriptor, "DepthwiseConvolution2d");
+
+    std::vector<armnn::TensorShape> shapes;
+    const std::vector<unsigned int> inputSize = {1, 2, 10, 10};
+    armnn::TensorShape inputShape(4, inputSize.data());
+    shapes.push_back(inputShape);
+
+    const std::vector<unsigned int> filterSize = { 1, 2, 3, 3};
+    armnn::TensorShape filterShape(4, filterSize.data());
+    shapes.push_back(filterShape);
+
+    const std::vector<unsigned int> 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