list(APPEND unittest_sources
src/armnnSerializer/test/ActivationSerializationTests.cpp
src/armnnSerializer/test/SerializerTests.cpp
+ src/armnnDeserializer/test/DeserializeAbs.cpp
src/armnnDeserializer/test/DeserializeActivation.cpp
src/armnnDeserializer/test/DeserializeAdd.cpp
src/armnnDeserializer/test/DeserializeBatchToSpaceNd.cpp
m_ParserFunctions(Layer_MAX+1, &Deserializer::ParseUnsupportedLayer)
{
// register supported layers
+ m_ParserFunctions[Layer_AbsLayer] = &Deserializer::ParseAbs;
m_ParserFunctions[Layer_ActivationLayer] = &Deserializer::ParseActivation;
m_ParserFunctions[Layer_AdditionLayer] = &Deserializer::ParseAdd;
m_ParserFunctions[Layer_BatchToSpaceNdLayer] = &Deserializer::ParseBatchToSpaceNd;
switch(layerType)
{
+ case Layer::Layer_AbsLayer:
+ return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base();
case Layer::Layer_ActivationLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base();
case Layer::Layer_AdditionLayer:
connections.outputSlots[outputSlotIndex] = outputSlot;
}
+void Deserializer::ParseAbs(armnnDeserializer::Deserializer::GraphPtr graph, unsigned int layerIndex)
+{
+ CHECK_LAYERS(graph, 0, layerIndex);
+ auto inputs = GetInputs(graph, layerIndex);
+ CHECK_LOCATION();
+ CHECK_VALID_SIZE(inputs.size(), 1);
+
+ auto outputs = GetOutputs(graph, layerIndex);
+ CHECK_VALID_SIZE(outputs.size(), 1);
+
+ auto layerName = GetLayerName(graph, layerIndex);
+
+ IConnectableLayer* layer = m_Network->AddAbsLayer(layerName.c_str());
+ armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
+ layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
+
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
+}
+
void Deserializer::ParseActivation(GraphPtr graph, unsigned int layerIndex)
{
CHECK_LAYERS(graph, 0, layerIndex);
using LayerParsingFunction = void(Deserializer::*)(GraphPtr graph, unsigned int layerIndex);
void ParseUnsupportedLayer(GraphPtr graph, unsigned int layerIndex);
+ void ParseAbs(GraphPtr graph, unsigned int layerIndex);
void ParseActivation(GraphPtr graph, unsigned int layerIndex);
void ParseAdd(GraphPtr graph, unsigned int layerIndex);
void ParseBatchToSpaceNd(GraphPtr graph, unsigned int layerIndex);
The Arm NN SDK Deserialize parser currently supports the following layers:
+* Abs
* Activation
* Addition
* BatchToSpaceNd
--- /dev/null
+//
+// 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 AbsFixture : public ParserFlatbuffersSerializeFixture
+ {
+ explicit AbsFixture(const std::string &inputShape,
+ 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: "AbsLayer",
+ layer: {
+ base: {
+ index: 1,
+ layerName: "AbsLayer",
+ layerType: "Abs",
+ inputSlots: [{
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ }],
+ outputSlots: [{
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType + 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"(
+ },
+ }],
+ }
+ }
+ },
+ }
+ ]
+ }
+ )";
+ Setup();
+ }
+ };
+
+ struct SimpleAbsFixture : AbsFixture
+ {
+ SimpleAbsFixture()
+ : AbsFixture("[ 1, 2, 2, 2 ]", // inputShape
+ "[ 1, 2, 2, 2 ]", // outputShape
+ "Float32") // dataType
+ {}
+ };
+
+ BOOST_FIXTURE_TEST_CASE(SimpleAbsTest, SimpleAbsFixture)
+ {
+ RunTest<4, armnn::DataType::Float32>(
+ 0,
+ {{"InputLayer", { -100.0f, -50.5f, -25.9999f, -0.5f , 0.0f, 1.5555f, 25.5f, 100.0f }}},
+ {{"OutputLayer", { 100.0f, 50.0f, 25.9999f, 0.5f , 0.0f, 1.5555f, 25.5f, 100.0f }}});
+ }
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
TransposeConvolution2d = 42,
Resize = 43,
Stack = 44,
- QuantizedLstm = 45
+ QuantizedLstm = 45,
+ Abs = 46
}
// Base layer table to be used as part of other layers
}
// Table for each layer defined below
+
+table AbsLayer {
+ base:LayerBase;
+}
+
table ActivationLayer {
base:LayerBase;
descriptor:ActivationDescriptor;
PreluLayer,
TransposeConvolution2dLayer,
ResizeLayer,
- StackLayer
+ StackLayer,
+ AbsLayer
}
table AnyLayer {
void SerializerVisitor::VisitAbsLayer(const armnn::IConnectableLayer* layer, const char* name)
{
- throw UnimplementedException("SerializerVisitor::VisitAbsLayer is not implemented");
+ auto flatBufferBaseLayer = CreateLayerBase(layer, serializer::LayerType::LayerType_Abs);
+ auto flatBufferAbsLayer = serializer::CreateAbsLayer(m_flatBufferBuilder, flatBufferBaseLayer);
+
+ CreateAnyLayer(flatBufferAbsLayer.o, serializer::Layer::Layer_AbsLayer);
}
// Build FlatBuffer for Activation Layer
The Arm NN SDK Serializer currently supports the following layers:
+* Abs
* Activation
* Addition
* BatchToSpaceNd
BOOST_AUTO_TEST_SUITE(SerializerTests)
+BOOST_AUTO_TEST_CASE(SerializeAbs)
+{
+ class AbsLayerVerifier : public LayerVerifierBase
+ {
+ public:
+ AbsLayerVerifier(const std::string& layerName,
+ const std::vector<armnn::TensorInfo>& inputInfos,
+ const std::vector<armnn::TensorInfo>& outputInfos)
+ : LayerVerifierBase(layerName, inputInfos, outputInfos) {}
+
+ void VisitAbsLayer(const armnn::IConnectableLayer* layer, const char* name) override
+ {
+ VerifyNameAndConnections(layer, name);
+ }
+ };
+
+ const std::string layerName("abs");
+ const armnn::TensorInfo tensorInfo({1, 2, 3}, armnn::DataType::Float32);
+
+ armnn::INetworkPtr network = armnn::INetwork::Create();
+ armnn::IConnectableLayer* const inputLayer = network->AddInputLayer(0);
+
+ armnn::IConnectableLayer* const absLayer = network->AddAbsLayer(layerName.c_str());
+ armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0);
+
+ inputLayer->GetOutputSlot(0).Connect(absLayer->GetInputSlot(0));
+ absLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
+
+ inputLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
+ absLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
+
+ armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network));
+ BOOST_CHECK(deserializedNetwork);
+
+ AbsLayerVerifier verifier(layerName, {tensorInfo}, {tensorInfo});
+ deserializedNetwork->Accept(verifier);
+}
+
BOOST_AUTO_TEST_CASE(SerializeAddition)
{
class AdditionLayerVerifier : public LayerVerifierBase