diff options
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r-- | src/armnnDeserializer/Deserializer.cpp | 46 | ||||
-rw-r--r-- | src/armnnDeserializer/Deserializer.hpp | 1 | ||||
-rw-r--r-- | src/armnnDeserializer/DeserializerSupport.md | 1 | ||||
-rw-r--r-- | src/armnnDeserializer/test/DeserializeSpaceToBatchNd.cpp | 140 |
4 files changed, 188 insertions, 0 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp index b263c3a769..64f8e44429 100644 --- a/src/armnnDeserializer/Deserializer.cpp +++ b/src/armnnDeserializer/Deserializer.cpp @@ -196,6 +196,7 @@ m_ParserFunctions(Layer_MAX+1, &Deserializer::ParseUnsupportedLayer) m_ParserFunctions[Layer_Pooling2dLayer] = &Deserializer::ParsePooling2d; m_ParserFunctions[Layer_ReshapeLayer] = &Deserializer::ParseReshape; m_ParserFunctions[Layer_SoftmaxLayer] = &Deserializer::ParseSoftmax; + m_ParserFunctions[Layer_SpaceToBatchNdLayer] = &Deserializer::ParseSpaceToBatchNd; } Deserializer::LayerBaseRawPtr Deserializer::GetBaseLayer(const GraphPtr& graphPtr, unsigned int layerIndex) @@ -230,6 +231,8 @@ Deserializer::LayerBaseRawPtr Deserializer::GetBaseLayer(const GraphPtr& graphPt return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base(); case Layer::Layer_SoftmaxLayer: return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base(); + case Layer::Layer_SpaceToBatchNdLayer: + return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base(); case Layer::Layer_NONE: default: throw ParseException(boost::str( @@ -1176,4 +1179,47 @@ void Deserializer::ParseSoftmax(GraphPtr graph, unsigned int layerIndex) RegisterOutputSlots(graph, layerIndex, layer); } +void Deserializer::ParseSpaceToBatchNd(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_SpaceToBatchNdLayer()->descriptor(); + auto flatBufferPadList = flatBufferDescriptor->padList(); + auto flatBufferBlockShape = flatBufferDescriptor->blockShape(); + + if (flatBufferPadList->Length() % 2 != 0) + { + throw ParseException(boost::str( + boost::format("The size of the pad list must be divisible by 2 %1%") % CHECK_LOCATION().AsString())); + } + + std::vector<std::pair<unsigned int, unsigned int>> padList; + padList.reserve(flatBufferPadList->Length() / 2); + for (unsigned int i = 0; i < flatBufferPadList->Length() - 1; i += 2) + { + padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1)); + } + + armnn::SpaceToBatchNdDescriptor descriptor; + descriptor.m_DataLayout = ToDataLayout(flatBufferDescriptor->dataLayout()); + descriptor.m_BlockShape = + std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end()); + descriptor.m_PadList = padList; + + auto layerName = GetLayerName(graph, layerIndex); + IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(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 9159ff2f36..c88459d97a 100644 --- a/src/armnnDeserializer/Deserializer.hpp +++ b/src/armnnDeserializer/Deserializer.hpp @@ -79,6 +79,7 @@ private: void ParsePooling2d(GraphPtr graph, unsigned int layerIndex); void ParseReshape(GraphPtr graph, unsigned int layerIndex); void ParseSoftmax(GraphPtr graph, unsigned int layerIndex); + void ParseSpaceToBatchNd(GraphPtr graph, unsigned int layerIndex); void RegisterOutputSlotOfConnection(uint32_t connectionIndex, armnn::IOutputSlot* slot); void RegisterInputSlotOfConnection(uint32_t connectionIndex, armnn::IInputSlot* slot); diff --git a/src/armnnDeserializer/DeserializerSupport.md b/src/armnnDeserializer/DeserializerSupport.md index 988144425c..4ae9780bc7 100644 --- a/src/armnnDeserializer/DeserializerSupport.md +++ b/src/armnnDeserializer/DeserializerSupport.md @@ -17,5 +17,6 @@ The Arm NN SDK Deserialize parser currently supports the following layers: * Pooling2d * Reshape * Softmax +* SpaceToBatchNd More machine learning layers will be supported in future releases. diff --git a/src/armnnDeserializer/test/DeserializeSpaceToBatchNd.cpp b/src/armnnDeserializer/test/DeserializeSpaceToBatchNd.cpp new file mode 100644 index 0000000000..4b34390ed5 --- /dev/null +++ b/src/armnnDeserializer/test/DeserializeSpaceToBatchNd.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> + +BOOST_AUTO_TEST_SUITE(Deserializer) + +struct SpaceToBatchNdFixture : public ParserFlatbuffersSerializeFixture +{ + explicit SpaceToBatchNdFixture(const std::string &inputShape, + const std::string &blockShape, + const std::string &padList, + const std::string &dataLayout, + const std::string &outputShape, + 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: "SpaceToBatchNdLayer", + layer: { + base: { + index: 1, + layerName: "SpaceToBatchNdLayer", + layerType: "SpaceToBatchNd", + inputSlots: [{ + index: 0, + connection: {sourceLayerIndex:0, outputSlotIndex:0 }, + }], + outputSlots: [{ + index: 0, + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"( + } + }] + }, + descriptor: { + blockShape: )" + blockShape + R"(, + padList: )" + padList + R"(, + dataLayout: )" + dataLayout + R"(, + } + } + }, + { + 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"( + }, + }], + } + } + }, + } + ] + } + )"; + SetupSingleInputSingleOutput("InputLayer", "OutputLayer"); + } +}; + +struct SimpleSpaceToBatchNdFixture : SpaceToBatchNdFixture +{ + SimpleSpaceToBatchNdFixture() : SpaceToBatchNdFixture("[ 2, 1, 2, 4 ]", + "[ 2, 2 ]", + "[ 0, 0, 2, 0 ]", + "NCHW", + "[ 8, 1, 1, 3 ]", + "Float32") {} +}; + +BOOST_FIXTURE_TEST_CASE(SimpleSpaceToBatchNdFloat32, SimpleSpaceToBatchNdFixture) +{ + RunTest<4, armnn::DataType::Float32>(0, + { + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f + }, + { + 0.0f, 1.0f, 3.0f, + 0.0f, 9.0f, 11.0f, + 0.0f, 2.0f, 4.0f, + 0.0f, 10.0f, 12.0f, + 0.0f, 5.0f, 7.0f, + 0.0f, 13.0f, 15.0f, + 0.0f, 6.0f, 8.0f, + 0.0f, 14.0f, 16.0f + }); +} + +BOOST_AUTO_TEST_SUITE_END() |