IVGCVSW-4315 Fix Fully Connected infer output shape bug

Change-Id: If4fd1abdedf7de2046435d418fb1ee95ceb73419
Signed-off-by: FinnWilliamsArm <Finn.Williams@Arm.com>
diff --git a/1.0/FullyConnected.hpp b/1.0/FullyConnected.hpp
index 26d61e4..56997ad 100644
--- a/1.0/FullyConnected.hpp
+++ b/1.0/FullyConnected.hpp
@@ -12,8 +12,8 @@
 namespace armnn_driver
 {
 
-inline armnn::TensorShape FlattenFullyConnectedInput(const armnn::TensorShape &inputShape,
-                                                     const armnn::TensorShape &weightsShape)
+inline armnn::TensorShape FlattenFullyConnectedInput(const armnn::TensorShape& inputShape,
+                                                     const armnn::TensorShape& weightsShape)
 {
     if (inputShape.GetNumDimensions() > 2U)
     {
@@ -35,4 +35,13 @@
     }
 }
 
+inline bool VerifyFullyConnectedShapes(const armnn::TensorShape& inputShape,
+                                       const armnn::TensorShape& weightsShape,
+                                       const armnn::TensorShape& outputShape,
+                                       bool  transposeWeightMatrix)
+{
+    unsigned int dimIdx = transposeWeightMatrix ? 0 : 1;
+    return (inputShape[0] == outputShape[0] && weightsShape[dimIdx] == outputShape[1]);
+}
+
 }
\ No newline at end of file
diff --git a/ConversionUtils.hpp b/ConversionUtils.hpp
index a342d39..3a144f7 100644
--- a/ConversionUtils.hpp
+++ b/ConversionUtils.hpp
@@ -2645,6 +2645,14 @@
     desc.m_TransposeWeightMatrix = true;
     desc.m_BiasEnabled           = true;
 
+    if (!VerifyFullyConnectedShapes(reshapedInfo.GetShape(),
+                                    weights.GetInfo().GetShape(),
+                                    outputInfo.GetShape(),
+                                    desc.m_TransposeWeightMatrix))
+    {
+        return Fail("%s: Expected outputShape does not match actual outputShape", __func__);
+    }
+
     bool isSupported = false;
     FORWARD_LAYER_SUPPORT_FUNC(__func__,
                                IsFullyConnectedSupported,