diff options
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r-- | src/armnnDeserializer/Deserializer.cpp | 47 | ||||
-rw-r--r-- | src/armnnDeserializer/Deserializer.hpp | 1 | ||||
-rw-r--r-- | src/armnnDeserializer/test/DeserializeFullyConnected.cpp | 140 |
3 files changed, 188 insertions, 0 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp index ead4fc5453..9ec7835021 100644 --- a/src/armnnDeserializer/Deserializer.cpp +++ b/src/armnnDeserializer/Deserializer.cpp @@ -174,6 +174,7 @@ m_ParserFunctions(Layer_MAX+1, &Deserializer::ParseUnsupportedLayer) m_ParserFunctions[Layer_AdditionLayer] = &Deserializer::ParseAdd; m_ParserFunctions[Layer_Convolution2dLayer] = &Deserializer::ParseConvolution2d; m_ParserFunctions[Layer_DepthwiseConvolution2dLayer] = &Deserializer::ParseDepthwiseConvolution2d; + m_ParserFunctions[Layer_FullyConnectedLayer] = &Deserializer::ParseFullyConnected; m_ParserFunctions[Layer_MultiplicationLayer] = &Deserializer::ParseMultiplication; m_ParserFunctions[Layer_PermuteLayer] = &Deserializer::ParsePermute; m_ParserFunctions[Layer_Pooling2dLayer] = &Deserializer::ParsePooling2d; @@ -195,6 +196,8 @@ Deserializer::LayerBaseRawPtr Deserializer::GetBaseLayer(const GraphPtr& graphPt return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base(); case Layer::Layer_DepthwiseConvolution2dLayer: return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base(); + case Layer::Layer_FullyConnectedLayer: + return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base(); case Layer::Layer_InputLayer: return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base(); case Layer::Layer_MultiplicationLayer: @@ -834,6 +837,50 @@ void Deserializer::ParseMultiplication(unsigned int layerIndex) RegisterOutputSlots(layerIndex, layer); } +void Deserializer::ParseFullyConnected(unsigned int layerIndex) +{ + CHECK_LAYERS(m_Graph, 0, layerIndex); + auto inputs = GetInputs(m_Graph, layerIndex); + CHECK_LOCATION(); + CHECK_VALID_SIZE(inputs.size(), 1); + + auto outputs = GetOutputs(m_Graph, layerIndex); + CHECK_VALID_SIZE(outputs.size(), 1); + + auto layerName = boost::str(boost::format("FullyConnected:%1%") % layerIndex); + + auto flatBufferLayer = m_Graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer(); + auto flatBufferDescriptor = flatBufferLayer->descriptor(); + + armnn::FullyConnectedDescriptor fullyConnectedDescriptor; + fullyConnectedDescriptor.m_BiasEnabled = flatBufferDescriptor->biasEnabled(); + fullyConnectedDescriptor.m_TransposeWeightMatrix = flatBufferDescriptor->transposeWeightsMatrix(); + + armnn::ConstTensor weightsTensor = ToConstTensor(flatBufferLayer->weights()); + + armnn::IConnectableLayer* layer; + if (flatBufferDescriptor->biasEnabled()) + { + armnn::ConstTensor biasTensorData = ToConstTensor(flatBufferLayer->biases()); + layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor, + weightsTensor, + biasTensorData, + layerName.c_str()); + } + else + { + layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor, + weightsTensor, + layerName.c_str()); + } + + armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); + layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); + + RegisterInputSlots(layerIndex, layer); + RegisterOutputSlots(layerIndex, layer); +} + void Deserializer::ParsePermute(unsigned int layerIndex) { CHECK_LAYERS(m_Graph, 0, layerIndex); diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp index 6af1afb776..25c651a50b 100644 --- a/src/armnnDeserializer/Deserializer.hpp +++ b/src/armnnDeserializer/Deserializer.hpp @@ -72,6 +72,7 @@ private: void ParseAdd(unsigned int layerIndex); void ParseConvolution2d(unsigned int layerIndex); void ParseDepthwiseConvolution2d(unsigned int layerIndex); + void ParseFullyConnected(unsigned int layerIndex); void ParseMultiplication(unsigned int layerIndex); void ParsePermute(unsigned int layerIndex); void ParsePooling2d(unsigned int layerIndex); diff --git a/src/armnnDeserializer/test/DeserializeFullyConnected.cpp b/src/armnnDeserializer/test/DeserializeFullyConnected.cpp new file mode 100644 index 0000000000..77d0acc782 --- /dev/null +++ b/src/armnnDeserializer/test/DeserializeFullyConnected.cpp @@ -0,0 +1,140 @@ +// +// 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(DeserializeParser) + +struct FullyConnectedFixture : public ParserFlatbuffersSerializeFixture +{ + explicit FullyConnectedFixture(const std::string & inputShape1, + const std::string & outputShape, + const std::string & weightsShape, + 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: )" + inputShape1 + R"(, + dataType: )" + dataType + R"(, + quantizationScale: 1.0, + quantizationOffset: 0 + }, + }] + }, + } + }, + }, + { + layer_type: "FullyConnectedLayer", + layer : { + base: { + index:1, + layerName: "FullyConnectedLayer", + layerType: "FullyConnected", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [{ + index: 0, + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"(, + quantizationScale: 2.0, + quantizationOffset: 0 + }, + }], + }, + descriptor: { + biasEnabled: false, + transposeWeightsMatrix: true + }, + weights: { + info: { + dimensions: )" + weightsShape + R"(, + dataType: )" + dataType + R"(, + quantizationScale: 1.0, + quantizationOffset: 0 + }, + data_type: ByteData, + data: { + data: [ + 2, 3, 4, 5 + ], + } + } + }, + }, + { + layer_type: "OutputLayer", + layer: { + base:{ + layerBindingId: 0, + 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 FullyConnectedWithNoBiasFixture : FullyConnectedFixture +{ + FullyConnectedWithNoBiasFixture() + : FullyConnectedFixture("[ 1, 4, 1, 1 ]", // inputShape + "[ 1, 1 ]", // outputShape + "[ 1, 4 ]", // filterShape + "QuantisedAsymm8") // filterData + {} +}; + +BOOST_FIXTURE_TEST_CASE(FullyConnectedWithNoBias, FullyConnectedWithNoBiasFixture) +{ + RunTest<2, armnn::DataType::QuantisedAsymm8>( + 0, + {{"InputLayer", { 10, 20, 30, 40 }}}, + {{"OutputLayer", { 400/2 }}}); +} + +BOOST_AUTO_TEST_SUITE_END() |