aboutsummaryrefslogtreecommitdiff
path: root/src/armnnDeserializer
diff options
context:
space:
mode:
authorTamas Nyiri <tamas.nyiri@arm.com>2021-11-05 14:55:33 +0000
committerTamas Nyiri <tamas.nyiri@arm.com>2021-11-17 11:32:55 +0000
commitd998a1cfbcc7b4ed9922532ffe19c51283fcae68 (patch)
tree53317946bb5845f4f253ebfd53b668c6698fcfee /src/armnnDeserializer
parent7b885b3cce70154596b1994b013ea91527117c26 (diff)
downloadarmnn-d998a1cfbcc7b4ed9922532ffe19c51283fcae68.tar.gz
IVGCVSW-6510 Serialization + Deserialization implementation
Subtask of story: IVGCVSW-6164 Add a Pooling3d FrontEnd and Ref Implementation * Add serialization support * Add deserialization support * Add corresponding unit tests Change-Id: I7cce5421f0a9b7c47a03524e733f3315131ba125 Signed-off-by: Tamas Nyiri <tamas.nyiri@arm.com>
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r--src/armnnDeserializer/Deserializer.cpp125
-rw-r--r--src/armnnDeserializer/Deserializer.hpp8
-rw-r--r--src/armnnDeserializer/test/DeserializePooling3d.cpp173
3 files changed, 302 insertions, 4 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp
index 8b1e9b970c..a5114ecfca 100644
--- a/src/armnnDeserializer/Deserializer.cpp
+++ b/src/armnnDeserializer/Deserializer.cpp
@@ -249,6 +249,7 @@ m_ParserFunctions(Layer_MAX+1, &IDeserializer::DeserializerImpl::ParseUnsupporte
m_ParserFunctions[Layer_PadLayer] = &DeserializerImpl::ParsePad;
m_ParserFunctions[Layer_PermuteLayer] = &DeserializerImpl::ParsePermute;
m_ParserFunctions[Layer_Pooling2dLayer] = &DeserializerImpl::ParsePooling2d;
+ m_ParserFunctions[Layer_Pooling3dLayer] = &DeserializerImpl::ParsePooling3d;
m_ParserFunctions[Layer_PreluLayer] = &DeserializerImpl::ParsePrelu;
m_ParserFunctions[Layer_QLstmLayer] = &DeserializerImpl::ParseQLstm;
m_ParserFunctions[Layer_QuantizeLayer] = &DeserializerImpl::ParseQuantize;
@@ -365,6 +366,8 @@ LayerBaseRawPtr IDeserializer::DeserializerImpl::GetBaseLayer(const GraphPtr& gr
return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
case Layer::Layer_Pooling2dLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
+ case Layer::Layer_Pooling3dLayer:
+ return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->base();
case Layer::Layer_PreluLayer:
return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base();
case Layer::Layer_QLstmLayer:
@@ -2130,7 +2133,7 @@ void IDeserializer::DeserializerImpl::ParsePermute(GraphPtr graph, unsigned int
RegisterOutputSlots(graph, layerIndex, layer);
}
-armnn::Pooling2dDescriptor IDeserializer::DeserializerImpl::GetPoolingDescriptor(PoolingDescriptor pooling2dDesc,
+armnn::Pooling2dDescriptor IDeserializer::DeserializerImpl::GetPooling2dDescriptor(Pooling2dDescriptor pooling2dDesc,
unsigned int layerIndex)
{
IgnoreUnused(layerIndex);
@@ -2225,7 +2228,104 @@ armnn::Pooling2dDescriptor IDeserializer::DeserializerImpl::GetPoolingDescriptor
return desc;
}
+armnn::Pooling3dDescriptor IDeserializer::DeserializerImpl::GetPooling3dDescriptor(Pooling3dDescriptor pooling3dDesc,
+ unsigned int layerIndex)
+{
+ IgnoreUnused(layerIndex);
+ armnn::Pooling3dDescriptor desc;
+
+ switch (pooling3dDesc->poolType())
+ {
+ case PoolingAlgorithm_Average:
+ {
+ desc.m_PoolType = armnn::PoolingAlgorithm::Average;
+ break;
+ }
+ case PoolingAlgorithm_Max:
+ {
+ desc.m_PoolType = armnn::PoolingAlgorithm::Max;
+ break;
+ }
+ case PoolingAlgorithm_L2:
+ {
+ desc.m_PoolType = armnn::PoolingAlgorithm::L2;
+ break;
+ }
+ default:
+ {
+ ARMNN_ASSERT_MSG(false, "Unsupported pooling algorithm");
+ }
+ }
+
+ switch (pooling3dDesc->outputShapeRounding())
+ {
+ case OutputShapeRounding_Floor:
+ {
+ desc.m_OutputShapeRounding = armnn::OutputShapeRounding::Floor;
+ break;
+ }
+ case OutputShapeRounding_Ceiling:
+ {
+ desc.m_OutputShapeRounding = armnn::OutputShapeRounding::Ceiling;
+ break;
+ }
+ default:
+ {
+ ARMNN_ASSERT_MSG(false, "Unsupported output shape rounding");
+ }
+ }
+
+ switch (pooling3dDesc->paddingMethod())
+ {
+ case PaddingMethod_Exclude:
+ {
+ desc.m_PaddingMethod = armnn::PaddingMethod::Exclude;
+ break;
+ }
+ case PaddingMethod_IgnoreValue:
+ {
+ desc.m_PaddingMethod = armnn::PaddingMethod::IgnoreValue;
+ break;
+ }
+ default:
+ {
+ ARMNN_ASSERT_MSG(false, "Unsupported padding method");
+ }
+ }
+
+ switch (pooling3dDesc->dataLayout())
+ {
+ case DataLayout_NCDHW:
+ {
+ desc.m_DataLayout = armnn::DataLayout::NCDHW;
+ break;
+ }
+ case DataLayout_NDHWC:
+ {
+ desc.m_DataLayout = armnn::DataLayout::NDHWC;
+ break;
+ }
+ default:
+ {
+ ARMNN_ASSERT_MSG(false, "Unsupported data layout");
+ }
+ }
+ desc.m_PadRight = pooling3dDesc->padRight();
+ desc.m_PadLeft = pooling3dDesc->padLeft();
+ desc.m_PadBottom = pooling3dDesc->padBottom();
+ desc.m_PadTop = pooling3dDesc->padTop();
+ desc.m_PadFront = pooling3dDesc->padFront();
+ desc.m_PadBack = pooling3dDesc->padBack();
+ desc.m_StrideX = pooling3dDesc->strideX();
+ desc.m_StrideY = pooling3dDesc->strideY();
+ desc.m_StrideZ = pooling3dDesc->strideZ();
+ desc.m_PoolWidth = pooling3dDesc->poolWidth();
+ desc.m_PoolHeight = pooling3dDesc->poolHeight();
+ desc.m_PoolDepth = pooling3dDesc->poolDepth();
+
+ return desc;
+}
void IDeserializer::DeserializerImpl::ParsePooling2d(GraphPtr graph, unsigned int layerIndex)
{
@@ -2239,7 +2339,7 @@ void IDeserializer::DeserializerImpl::ParsePooling2d(GraphPtr graph, unsigned in
CHECK_VALID_SIZE(outputs.size(), 1);
auto outputInfo = ToTensorInfo(outputs[0]);
- auto pooling2dDescriptor = GetPoolingDescriptor(pooling2dDes, layerIndex);
+ auto pooling2dDescriptor = GetPooling2dDescriptor(pooling2dDes, layerIndex);
auto layerName = GetLayerName(graph, layerIndex);
IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, layerName.c_str());
layer->GetOutputSlot(0).SetTensorInfo(outputInfo);
@@ -2248,6 +2348,27 @@ void IDeserializer::DeserializerImpl::ParsePooling2d(GraphPtr graph, unsigned in
RegisterOutputSlots(graph, layerIndex, layer);
}
+void IDeserializer::DeserializerImpl::ParsePooling3d(GraphPtr graph, unsigned int layerIndex)
+{
+ CHECK_LAYERS(graph, 0, layerIndex);
+
+ auto pooling3dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling3dLayer()->descriptor();
+ auto inputs = GetInputs(graph, layerIndex);
+ CHECK_VALID_SIZE(inputs.size(), 1);
+
+ auto outputs = GetOutputs(graph, layerIndex);
+ CHECK_VALID_SIZE(outputs.size(), 1);
+ auto outputInfo = ToTensorInfo(outputs[0]);
+
+ auto pooling3dDescriptor = GetPooling3dDescriptor(pooling3dDes, layerIndex);
+ auto layerName = GetLayerName(graph, layerIndex);
+ IConnectableLayer* layer = m_Network->AddPooling3dLayer(pooling3dDescriptor, layerName.c_str());
+ layer->GetOutputSlot(0).SetTensorInfo(outputInfo);
+
+ RegisterInputSlots(graph, layerIndex, layer);
+ RegisterOutputSlots(graph, layerIndex, layer);
+}
+
void IDeserializer::DeserializerImpl::ParseQuantize(GraphPtr graph, unsigned int layerIndex)
{
CHECK_LAYERS(graph, 0, layerIndex);
diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp
index d2291c07a7..8de492ed5f 100644
--- a/src/armnnDeserializer/Deserializer.hpp
+++ b/src/armnnDeserializer/Deserializer.hpp
@@ -18,7 +18,8 @@ namespace armnnDeserializer
using ConstTensorRawPtr = const armnnSerializer::ConstTensor *;
using GraphPtr = const armnnSerializer::SerializedGraph *;
using TensorRawPtr = const armnnSerializer::TensorInfo *;
-using PoolingDescriptor = const armnnSerializer::Pooling2dDescriptor *;
+using Pooling2dDescriptor = const armnnSerializer::Pooling2dDescriptor *;
+using Pooling3dDescriptor = const armnnSerializer::Pooling3dDescriptor *;
using NormalizationDescriptorPtr = const armnnSerializer::NormalizationDescriptor *;
using LstmDescriptorPtr = const armnnSerializer::LstmDescriptor *;
using LstmInputParamsPtr = const armnnSerializer::LstmInputParams *;
@@ -60,7 +61,9 @@ public:
static LayerBaseRawPtr GetBaseLayer(const GraphPtr& graphPtr, unsigned int layerIndex);
static int32_t GetBindingLayerInfo(const GraphPtr& graphPtr, unsigned int layerIndex);
static std::string GetLayerName(const GraphPtr& graph, unsigned int index);
- static armnn::Pooling2dDescriptor GetPoolingDescriptor(PoolingDescriptor pooling2dDescriptor,
+ static armnn::Pooling2dDescriptor GetPooling2dDescriptor(Pooling2dDescriptor pooling2dDescriptor,
+ unsigned int layerIndex);
+ static armnn::Pooling3dDescriptor GetPooling3dDescriptor(Pooling3dDescriptor pooling3dDescriptor,
unsigned int layerIndex);
static armnn::NormalizationDescriptor GetNormalizationDescriptor(
NormalizationDescriptorPtr normalizationDescriptor, unsigned int layerIndex);
@@ -121,6 +124,7 @@ private:
void ParsePad(GraphPtr graph, unsigned int layerIndex);
void ParsePermute(GraphPtr graph, unsigned int layerIndex);
void ParsePooling2d(GraphPtr graph, unsigned int layerIndex);
+ void ParsePooling3d(GraphPtr graph, unsigned int layerIndex);
void ParsePrelu(GraphPtr graph, unsigned int layerIndex);
void ParseQLstm(GraphPtr graph, unsigned int layerIndex);
void ParseQuantize(GraphPtr graph, unsigned int layerIndex);
diff --git a/src/armnnDeserializer/test/DeserializePooling3d.cpp b/src/armnnDeserializer/test/DeserializePooling3d.cpp
new file mode 100644
index 0000000000..62fdc5cd60
--- /dev/null
+++ b/src/armnnDeserializer/test/DeserializePooling3d.cpp
@@ -0,0 +1,173 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ParserFlatbuffersSerializeFixture.hpp"
+#include <armnnDeserializer/IDeserializer.hpp>
+
+#include <string>
+
+TEST_SUITE("Deserializer_Pooling3d")
+{
+struct Pooling3dFixture : public ParserFlatbuffersSerializeFixture
+{
+ explicit Pooling3dFixture(const std::string &inputShape,
+ const std::string &outputShape,
+ const std::string &dataType,
+ const std::string &dataLayout,
+ const std::string &poolingAlgorithm)
+ {
+ 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: "Pooling3dLayer",
+ layer: {
+ base: {
+ index: 1,
+ layerName: "Pooling3dLayer",
+ layerType: "Pooling3d",
+ inputSlots: [{
+ index: 0,
+ connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+ }],
+ outputSlots: [ {
+ index: 0,
+ tensorInfo: {
+ dimensions: )" + outputShape + R"(,
+ dataType: )" + dataType + R"(
+
+ }}]},
+ descriptor: {
+ poolType: )" + poolingAlgorithm + R"(,
+ outputShapeRounding: "Floor",
+ paddingMethod: Exclude,
+ dataLayout: )" + dataLayout + R"(,
+ padLeft: 0,
+ padRight: 0,
+ padTop: 0,
+ padBottom: 0,
+ padFront: 0,
+ padBack: 0,
+ poolWidth: 2,
+ poolHeight: 2,
+ poolDepth: 2,
+ strideX: 2,
+ strideY: 2,
+ strideZ: 2
+ }
+ }},
+ {
+ 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"(
+ },
+ }],
+ }}},
+ }]
+ }
+ )";
+ SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
+ }
+};
+
+struct SimpleAvgPooling3dFixture : Pooling3dFixture
+{
+ SimpleAvgPooling3dFixture() : Pooling3dFixture("[ 1, 2, 2, 2, 1 ]",
+ "[ 1, 1, 1, 1, 1 ]",
+ "Float32", "NDHWC", "Average") {}
+};
+
+struct SimpleAvgPooling3dFixture2 : Pooling3dFixture
+{
+ SimpleAvgPooling3dFixture2() : Pooling3dFixture("[ 1, 2, 2, 2, 1 ]",
+ "[ 1, 1, 1, 1, 1 ]",
+ "QuantisedAsymm8", "NDHWC", "Average") {}
+};
+
+struct SimpleMaxPooling3dFixture : Pooling3dFixture
+{
+ SimpleMaxPooling3dFixture() : Pooling3dFixture("[ 1, 1, 2, 2, 2 ]",
+ "[ 1, 1, 1, 1, 1 ]",
+ "Float32", "NCDHW", "Max") {}
+};
+
+struct SimpleMaxPooling3dFixture2 : Pooling3dFixture
+{
+ SimpleMaxPooling3dFixture2() : Pooling3dFixture("[ 1, 1, 2, 2, 2 ]",
+ "[ 1, 1, 1, 1, 1 ]",
+ "QuantisedAsymm8", "NCDHW", "Max") {}
+};
+
+struct SimpleL2Pooling3dFixture : Pooling3dFixture
+{
+ SimpleL2Pooling3dFixture() : Pooling3dFixture("[ 1, 2, 2, 2, 1 ]",
+ "[ 1, 1, 1, 1, 1 ]",
+ "Float32", "NDHWC", "L2") {}
+};
+
+TEST_CASE_FIXTURE(SimpleAvgPooling3dFixture, "Pooling3dFloat32Avg")
+{
+ RunTest<5, armnn::DataType::Float32>(0, { 2, 3, 5, 2, 3, 2, 3, 4 }, { 3 });
+}
+
+TEST_CASE_FIXTURE(SimpleAvgPooling3dFixture2, "Pooling3dQuantisedAsymm8Avg")
+{
+ RunTest<5, armnn::DataType::QAsymmU8>(0,{ 20, 40, 60, 80, 50, 60, 70, 30 },{ 50 });
+}
+
+TEST_CASE_FIXTURE(SimpleMaxPooling3dFixture, "Pooling3dFloat32Max")
+{
+ RunTest<5, armnn::DataType::Float32>(0, { 2, 5, 5, 2, 1, 3, 4, 0 }, { 5 });
+}
+
+TEST_CASE_FIXTURE(SimpleMaxPooling3dFixture2, "Pooling3dQuantisedAsymm8Max")
+{
+ RunTest<5, armnn::DataType::QAsymmU8>(0,{ 20, 40, 60, 80, 10, 40, 0, 70 },{ 80 });
+}
+
+TEST_CASE_FIXTURE(SimpleL2Pooling3dFixture, "Pooling3dFloat32L2")
+{
+ RunTest<5, armnn::DataType::Float32>(0, { 2, 3, 5, 2, 4, 1, 1, 3 }, { 2.93683503112f });
+}
+
+}
+