IVGCVSW-7957 Fix weights checking when converting Conv2d/DepthwiseConv2d

* An Operand can only have NO_VALUE if it is an optional argument
  of an operation
* Add a check to see if the operand is optional to IsWeightsValid

Signed-off-by: Kevin May <kevin.may@arm.com>
Change-Id: I6321934dbfa41dd2bd28d8871c135f3694d9674d
diff --git a/ConversionUtils_1_2.hpp b/ConversionUtils_1_2.hpp
index 7a629e5..e584046 100644
--- a/ConversionUtils_1_2.hpp
+++ b/ConversionUtils_1_2.hpp
@@ -27,7 +27,8 @@
         typename HalModel     = typename HalPolicy::Model>
 bool IsWeightsValid(const HalOperation& operation,
                     uint32_t inputIndex,
-                    const HalModel& model)
+                    const HalModel& model,
+                    const bool isOptional = true)
 {
     using HalOperand         = typename HalPolicy::Operand;
     using HalOperandLifeTime = typename HalPolicy::OperandLifeTime;
@@ -38,12 +39,19 @@
         return false;
     }
 
+    // If the operand is not an optional operand it cannot have a NO_VALUE lifetime
+    if (!isOptional && operand->lifetime == HalOperandLifeTime::NO_VALUE)
+    {
+        return false;
+    }
+
     if (operand->lifetime    != HalOperandLifeTime::CONSTANT_COPY
         && operand->lifetime != HalOperandLifeTime::CONSTANT_REFERENCE
         && operand->lifetime != HalOperandLifeTime::NO_VALUE)
     {
         return false;
     }
+
     return true;
 }
 
@@ -415,11 +423,10 @@
     // the DataLayout is NCHW
 
 
-    if (!IsWeightsValid<HalPolicy>(operation, 1, model) && desc.m_DataLayout == DataLayout::NCHW)
+    if (!IsWeightsValid<HalPolicy>(operation, 1, model, false) && desc.m_DataLayout == DataLayout::NCHW)
     {
         return Fail("%s: Operation has unsupported weights HalOperandLifeTime", __func__);
     }
-
     LayerInputHandle weightsInput = (desc.m_DataLayout == DataLayout::NCHW) ?
                                      ConvertToLayerInputHandle<HalPolicy>(operation, 1, model, data, OHWIToOIHW) :
                                      ConvertToLayerInputHandle<HalPolicy>(operation, 1, model, data);
@@ -562,12 +569,14 @@
     const TensorInfo& outputInfo = GetTensorInfoForOperand(*output);
 
     // ArmNN does not currently support non-fixed weights or bias
+    if (!IsWeightsValid<HalPolicy>(operation, 1, model, false))
+    {
+        return Fail("%s: This Operation has unsupported weights HalOperandLifeTime", __func__);
+    }
+
     // Find the shape of the weights tensor. In AndroidNN this will be [ 1, H, W, I * M ]
     const HalOperand* weightsOperand = GetInputOperand<HalPolicy>(operation, 1, model);
-    if (!weightsOperand)
-    {
-        return Fail("%s: Could not read weights", __func__);
-    }
+
     if (weightsOperand->dimensions[0] != 1)
     {
         return Fail("%s: Invalid weights; for depthwise convolution, dimension 0 must be 1 but it is %i",