aboutsummaryrefslogtreecommitdiff
path: root/src/armnnDeserializer
diff options
context:
space:
mode:
authorSadik Armagan <sadik.armagan@arm.com>2019-03-04 17:44:21 +0000
committerSadik Armagan <sadik.armagan@arm.com>2019-03-07 09:24:37 +0000
commitac97c8cda28f81ce76834b8b769967d42b02e2ac (patch)
tree7bf1b1104a4bfb041ee5d74cabe1e1be2664af70 /src/armnnDeserializer
parentc192f35edefd0977396db8d381adc7598e3660cc (diff)
downloadarmnn-ac97c8cda28f81ce76834b8b769967d42b02e2ac.tar.gz
IVGCVSW-2696 Serialize / de-serialize the Mean layer
Change-Id: Iee4bab5a6d6b992cf4bba8697a2918f854c906a3 Signed-off-by: Sadik Armagan <sadik.armagan@arm.com>
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r--src/armnnDeserializer/Deserializer.cpp33
-rw-r--r--src/armnnDeserializer/Deserializer.hpp3
-rw-r--r--src/armnnDeserializer/DeserializerSupport.md1
-rw-r--r--src/armnnDeserializer/test/DeserializeMean.cpp125
4 files changed, 160 insertions, 2 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp
index 79713d4dbe..96879bb65a 100644
--- a/src/armnnDeserializer/Deserializer.cpp
+++ b/src/armnnDeserializer/Deserializer.cpp
@@ -198,8 +198,9 @@ m_ParserFunctions(Layer_MAX+1, &Deserializer::ParseUnsupportedLayer)
m_ParserFunctions[Layer_FloorLayer] = &Deserializer::ParseFloor;
m_ParserFunctions[Layer_GatherLayer] = &Deserializer::ParseGather;
m_ParserFunctions[Layer_GreaterLayer] = &Deserializer::ParseGreater;
- m_ParserFunctions[Layer_MinimumLayer] = &Deserializer::ParseMinimum;
m_ParserFunctions[Layer_MaximumLayer] = &Deserializer::ParseMaximum;
+ m_ParserFunctions[Layer_MeanLayer] = &Deserializer::ParseMean;
+ m_ParserFunctions[Layer_MinimumLayer] = &Deserializer::ParseMinimum;
m_ParserFunctions[Layer_MultiplicationLayer] = &Deserializer::ParseMultiplication;
m_ParserFunctions[Layer_NormalizationLayer] = &Deserializer::ParseNormalization;
m_ParserFunctions[Layer_PadLayer] = &Deserializer::ParsePad;
@@ -248,6 +249,8 @@ Deserializer::LayerBaseRawPtr Deserializer::GetBaseLayer(const GraphPtr& graphPt
return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
case Layer::Layer_InputLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base();
+ case Layer::Layer_MeanLayer:
+ return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base();
case Layer::Layer_MinimumLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base();
case Layer::Layer_MaximumLayer:
@@ -1733,4 +1736,32 @@ void Deserializer::ParseGather(GraphPtr graph, unsigned int layerIndex)
RegisterOutputSlots(graph, layerIndex, layer);
}
+void Deserializer::ParseMean(GraphPtr graph, unsigned int layerIndex)
+{
+ CHECK_LAYERS(graph, 0, layerIndex);
+
+ Deserializer::TensorRawPtrVector inputs = GetInputs(graph, layerIndex);
+ CHECK_VALID_SIZE(inputs.size(), 1);
+
+ Deserializer::TensorRawPtrVector outputs = GetOutputs(graph, layerIndex);
+ CHECK_VALID_SIZE(outputs.size(), 1);
+
+ auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_MeanLayer()->descriptor();
+ auto flatBufferAxis = flatBufferDescriptor->axis();
+ auto flatBufferKeepDims = flatBufferDescriptor->keepDims();
+
+ armnn::MeanDescriptor descriptor;
+ descriptor.m_Axis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
+ descriptor.m_KeepDims = flatBufferKeepDims;
+
+ auto layerName = GetLayerName(graph, layerIndex);
+ IConnectableLayer* layer = m_Network->AddMeanLayer(descriptor, layerName.c_str());
+
+ armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
+ layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
+
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
+}
+
} // namespace armnnDeserializer
diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp
index 058002548a..4d9c13818b 100644
--- a/src/armnnDeserializer/Deserializer.hpp
+++ b/src/armnnDeserializer/Deserializer.hpp
@@ -84,8 +84,9 @@ private:
void ParseFullyConnected(GraphPtr graph, unsigned int layerIndex);
void ParseGather(GraphPtr graph, unsigned int layerIndex);
void ParseGreater(GraphPtr graph, unsigned int layerIndex);
- void ParseMinimum(GraphPtr graph, unsigned int layerIndex);
void ParseMaximum(GraphPtr graph, unsigned int layerIndex);
+ void ParseMean(GraphPtr graph, unsigned int layerIndex);
+ void ParseMinimum(GraphPtr graph, unsigned int layerIndex);
void ParseMultiplication(GraphPtr graph, unsigned int layerIndex);
void ParseNormalization(GraphPtr graph, unsigned int layerIndex);
void ParsePad(GraphPtr graph, unsigned int layerIndex);
diff --git a/src/armnnDeserializer/DeserializerSupport.md b/src/armnnDeserializer/DeserializerSupport.md
index cc7c62662a..0f3d91d1e7 100644
--- a/src/armnnDeserializer/DeserializerSupport.md
+++ b/src/armnnDeserializer/DeserializerSupport.md
@@ -20,6 +20,7 @@ The Arm NN SDK Deserialize parser currently supports the following layers:
* Gather
* Greater
* Maximum
+* Mean
* Minimum
* Multiplication
* Normalization
diff --git a/src/armnnDeserializer/test/DeserializeMean.cpp b/src/armnnDeserializer/test/DeserializeMean.cpp
new file mode 100644
index 0000000000..4ea745628c
--- /dev/null
+++ b/src/armnnDeserializer/test/DeserializeMean.cpp
@@ -0,0 +1,125 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <boost/test/unit_test.hpp>
+#include "ParserFlatbuffersSerializeFixture.hpp"
+#include "../Deserializer.hpp"
+
+#include <string>
+#include <iostream>
+
+BOOST_AUTO_TEST_SUITE(Deserializer)
+
+struct MeanFixture : public ParserFlatbuffersSerializeFixture
+{
+ explicit MeanFixture(const std::string &inputShape,
+ const std::string &outputShape,
+ const std::string &axis,
+ const std::string &dataType)
+ {
+ m_JsonString = R"(
+ {
+ inputIds: [0],
+ outputIds: [2],
+ layers: [
+ {
+ layer_type: "InputLayer",
+ layer: {
+ base: {
+ layerBindingId: 0,
+ base: {
+ index: 0,
+ layerName: "InputLayer",
+ layerType: "Input",
+ inputSlots: [{
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ }],
+ outputSlots: [{
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + inputShape + R"(,
+ dataType: )" + dataType + R"(
+ }
+ }]
+ }
+ }
+ }
+ },
+ {
+ layer_type: "MeanLayer",
+ layer: {
+ base: {
+ index: 1,
+ layerName: "MeanLayer",
+ layerType: "Mean",
+ inputSlots: [{
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ }],
+ outputSlots: [{
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType + R"(
+ }
+ }]
+ },
+ descriptor: {
+ axis: )" + axis + R"(,
+ keepDims: true
+ }
+ }
+ },
+ {
+ layer_type: "OutputLayer",
+ layer: {
+ base:{
+ layerBindingId: 2,
+ base: {
+ index: 2,
+ layerName: "OutputLayer",
+ layerType: "Output",
+ inputSlots: [{
+ index: 0,
+ connection: {sourceLayerIndex:1, outputSlotIndex:0 },
+ }],
+ outputSlots: [{
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType + R"(
+ },
+ }],
+ }
+ }
+ },
+ }
+ ]
+ }
+ )";
+ Setup();
+ }
+};
+
+struct SimpleMeanFixture : MeanFixture
+{
+ SimpleMeanFixture()
+ : MeanFixture("[ 1, 1, 3, 2 ]", // inputShape
+ "[ 1, 1, 1, 2 ]", // outputShape
+ "[ 2 ]", // axis
+ "Float32") // dataType
+ {}
+};
+
+BOOST_FIXTURE_TEST_CASE(SimpleMean, SimpleMeanFixture)
+{
+ RunTest<4, armnn::DataType::Float32>(
+ 0,
+ {{"InputLayer", { 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f }}},
+ {{"OutputLayer", { 2.0f, 2.0f }}});
+}
+
+BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file