aboutsummaryrefslogtreecommitdiff
path: root/src/armnn
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnn')
-rw-r--r--src/armnn/Graph.cpp69
-rw-r--r--src/armnn/Graph.hpp5
-rw-r--r--src/armnn/test/TestUtils.cpp24
3 files changed, 84 insertions, 14 deletions
diff --git a/src/armnn/Graph.cpp b/src/armnn/Graph.cpp
index 60bf328c9c..95104049a2 100644
--- a/src/armnn/Graph.cpp
+++ b/src/armnn/Graph.cpp
@@ -534,7 +534,7 @@ void Graph::VerifyConstantLayerSetTensorInfo() const
{
for (auto&& layer : TopologicalSort())
{
- if(layer->GetType() == armnn::LayerType::Constant)
+ if (layer->GetType() == armnn::LayerType::Constant)
{
for (auto&& output: layer->GetOutputSlots())
{
@@ -562,15 +562,9 @@ void Graph::InferTensorInfos()
const IOutputSlot* source = input.GetConnectedOutputSlot();
if (source == NULL)
{
- std::ostringstream message;
- message << "Input slot "
- << input.GetSlotIndex()
- << " not connected to an output slot on "
- << GetLayerTypeAsCString(layer->GetType())
- << " layer \""
- << layer->GetName()
- << "\"";
- throw LayerValidationException(message.str());
+ // Throws exception due to a layer input not being connected to an output slot.
+ // Verifies input slot weights and bias are set for FullyConnected layers.
+ ConstructErrorMessageForUnconnectedInputs(layer, input.GetSlotIndex());
}
if (!source->IsTensorInfoSet())
@@ -578,9 +572,8 @@ void Graph::InferTensorInfos()
std::ostringstream message;
message << "Output slot TensorInfo not set on "
<< GetLayerTypeAsCString(layer->GetType())
- << " layer \""
- << layer->GetName()
- << "\"";
+ << " layer "
+ << std::quoted(layer->GetName());
throw LayerValidationException(message.str());
}
}
@@ -592,4 +585,54 @@ void Graph::InferTensorInfos()
}
}
+/// Throws exception due to a layer input not being connected to an output slot.
+/// Verifies weights and bias are set for FullyConnected layers on input slots 1
+/// and 2 respectively. Method checks if bias is enabled before ensuring it is set.
+///
+/// @param layer constant pointer to a Layer object
+/// @param slotIndex input slot index of layer
+/// @throws LayerValidationException
+void Graph::ConstructErrorMessageForUnconnectedInputs(Layer* const layer,
+ unsigned int slotIndex)
+{
+ std::ostringstream message;
+ bool noWeightsAndBias = false;
+
+ if (layer->GetType() == armnn::LayerType::FullyConnected && slotIndex > 0)
+ {
+ // If weights are not set and is bias enabled, also check if bias is set
+ if (slotIndex == 1 && layer->GetNumInputSlots() == 3)
+ {
+ const IOutputSlot* biasSource = layer->GetInputSlot(2).GetConnectedOutputSlot();
+ if (biasSource == NULL)
+ {
+ message << "FullyConnected layer weights and bias not set: ";
+ noWeightsAndBias = true;
+ }
+ }
+
+ // Only weights or bias are not set
+ if (!noWeightsAndBias)
+ {
+ if (slotIndex == 1)
+ {
+ message << "FullyConnected layer weights not set: ";
+ }
+ else
+ {
+ message << "FullyConnected layer bias not set: ";
+ }
+ }
+ }
+
+ std::string slotString = noWeightsAndBias ? "1 & 2" : std::to_string(slotIndex);
+ message << "Input slot(s) "
+ << slotString
+ << " not connected to an output slot on "
+ << GetLayerTypeAsCString(layer->GetType())
+ << " layer "
+ << std::quoted(layer->GetName());
+ throw LayerValidationException(message.str());
+}
+
} // namespace armnn
diff --git a/src/armnn/Graph.hpp b/src/armnn/Graph.hpp
index d5fbeafed0..e2321bb0e4 100644
--- a/src/armnn/Graph.hpp
+++ b/src/armnn/Graph.hpp
@@ -268,6 +268,11 @@ private:
std::map<const GraphEvent, std::list<IGraphObservable*>> m_Views;
ShapeInferenceMethod m_ShapeInferenceMethod;
+
+ // Throws exception due to a layer input not being connected to an output slot.
+ /// Also verifies weights and bias are set for FullyConnected layers.
+ void ConstructErrorMessageForUnconnectedInputs(Layer* const layer,
+ unsigned int slotIndex);
};
/// Common base class for layers in the graph.
diff --git a/src/armnn/test/TestUtils.cpp b/src/armnn/test/TestUtils.cpp
index 6020c7631c..97cc80c8a2 100644
--- a/src/armnn/test/TestUtils.cpp
+++ b/src/armnn/test/TestUtils.cpp
@@ -15,7 +15,29 @@ void Connect(armnn::IConnectableLayer* from, armnn::IConnectableLayer* to, const
ARMNN_ASSERT(from);
ARMNN_ASSERT(to);
- from->GetOutputSlot(fromIndex).Connect(to->GetInputSlot(toIndex));
+ try
+ {
+ from->GetOutputSlot(fromIndex).Connect(to->GetInputSlot(toIndex));
+ }
+ catch (const std::out_of_range& exc)
+ {
+ std::ostringstream message;
+
+ if (to->GetType() == armnn::LayerType::FullyConnected && toIndex == 2)
+ {
+ message << "Tried to connect bias to FullyConnected layer when bias is not enabled: ";
+ }
+
+ message << "Failed to connect to input slot "
+ << toIndex
+ << " on "
+ << GetLayerTypeAsCString(to->GetType())
+ << " layer "
+ << std::quoted(to->GetName())
+ << " as the slot does not exist or is unavailable";
+ throw LayerValidationException(message.str());
+ }
+
from->GetOutputSlot(fromIndex).SetTensorInfo(tensorInfo);
}