diff options
author | Matthew Sloyan <matthew.sloyan@arm.com> | 2021-10-18 13:07:49 +0100 |
---|---|---|
committer | Matthew Sloyan <matthew.sloyan@arm.com> | 2021-10-20 16:03:04 +0100 |
commit | 5d7b0a314b3e354a6cbcf15f5dd78b50f1e02774 (patch) | |
tree | 3d844c4575193ffddfe3a17c51cb808c9f16ddb0 /src/armnnDeserializer | |
parent | 73010788725f8f07efb6df20711ece712ee213ea (diff) | |
download | armnn-5d7b0a314b3e354a6cbcf15f5dd78b50f1e02774.tar.gz |
Add ConstTensorsAsInput support for Conv3d
* Constant weights and biases are now stored as Constant layers.
* Updated Serializer, Deserializer and unit tests to reflect this.
* Updated TfLiteParser.
* Updated Ref backend to handle constant weights and
bias as inputs rather than reading from member variables.
* Added Conv3d EndToEnd test.
* Added NCDHW DataLayout and unit tests.
Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com>
Change-Id: I10cdd354ca5f1c748730f92ffdb36bf810f83c8e
Diffstat (limited to 'src/armnnDeserializer')
-rw-r--r-- | src/armnnDeserializer/Deserializer.cpp | 21 | ||||
-rw-r--r-- | src/armnnDeserializer/test/DeserializeConvolution3d.cpp | 92 |
2 files changed, 67 insertions, 46 deletions
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp index 6b73946af2..c088ef7b54 100644 --- a/src/armnnDeserializer/Deserializer.cpp +++ b/src/armnnDeserializer/Deserializer.cpp @@ -449,6 +449,8 @@ armnn::DataLayout ToDataLayout(armnnSerializer::DataLayout dataLayout) return armnn::DataLayout::NHWC; case armnnSerializer::DataLayout::DataLayout_NDHWC: return armnn::DataLayout::NDHWC; + case armnnSerializer::DataLayout::DataLayout_NCDHW: + return armnn::DataLayout::NCDHW; case armnnSerializer::DataLayout::DataLayout_NCHW: default: return armnn::DataLayout::NCHW; @@ -1402,7 +1404,6 @@ void IDeserializer::DeserializerImpl::ParseConvolution3d(GraphPtr graph, unsigne 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); @@ -1424,22 +1425,14 @@ void IDeserializer::DeserializerImpl::ParseConvolution3d(GraphPtr graph, unsigne descriptor.m_DilationX = serializerDescriptor->dilationX(); descriptor.m_DilationY = serializerDescriptor->dilationY(); descriptor.m_DilationZ = serializerDescriptor->dilationZ(); - descriptor.m_BiasEnabled = serializerDescriptor->biasEnabled();; + descriptor.m_BiasEnabled = serializerDescriptor->biasEnabled(); descriptor.m_DataLayout = ToDataLayout(serializerDescriptor->dataLayout()); - armnn::ConstTensor weights = ToConstTensor(serializerLayer->weights()); - armnn::ConstTensor biases; + uint32_t numInputs = descriptor.GetNumInputs(); + CHECK_VALID_SIZE(inputs.size(), numInputs); + + IConnectableLayer* layer = m_Network->AddConvolution3dLayer(descriptor, layerName.c_str()); - armnn::Optional<armnn::ConstTensor> optionalBiases = armnn::EmptyOptional(); - if (descriptor.m_BiasEnabled) - { - biases = ToConstTensor(serializerLayer->biases()); - optionalBiases = armnn::Optional<armnn::ConstTensor>(biases); - } - IConnectableLayer* layer = m_Network->AddConvolution3dLayer(descriptor, - weights, - optionalBiases, - layerName.c_str()); armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); diff --git a/src/armnnDeserializer/test/DeserializeConvolution3d.cpp b/src/armnnDeserializer/test/DeserializeConvolution3d.cpp index 057ab6fbda..23fd811cdb 100644 --- a/src/armnnDeserializer/test/DeserializeConvolution3d.cpp +++ b/src/armnnDeserializer/test/DeserializeConvolution3d.cpp @@ -30,13 +30,11 @@ struct Convolution3dFixture : public ParserFlatbuffersSerializeFixture base: { layerName: "InputLayer", layerType: "Input", - inputSlots: [{ - index: 0, - connection: {sourceLayerIndex:0, outputSlotIndex:0 }, - }], + inputSlots: [ + + ], outputSlots: [ { - index: 0, tensorInfo: { dimensions: )" + inputShape + R"(, dataType: )" + dataType + R"(, @@ -56,26 +54,19 @@ struct Convolution3dFixture : public ParserFlatbuffersSerializeFixture } }, { - layer_type: "Convolution3dLayer", + layer_type: "ConstantLayer", layer: { base: { index: 1, - layerName: "convolution3d", - layerType: "Convolution2d", + layerName: "Weights", + layerType: "Constant", inputSlots: [ - { - index: 0, - connection: { - sourceLayerIndex: 0, - outputSlotIndex: 0 - } - } + ], outputSlots: [ { - index: 0, tensorInfo: { - dimensions: )" + outputShape + R"(, + dimensions: )" + weightsShape + R"(, dataType: )" + dataType + R"(, quantizationScale: 0.1, dimensionSpecificity: [ @@ -89,12 +80,7 @@ struct Convolution3dFixture : public ParserFlatbuffersSerializeFixture } ] }, - descriptor: { - strideX: 2, - strideY: 2, - strideZ: 2 - }, - weights: { + input: { info: { dimensions: )" + weightsShape + R"(, dataType: )" + dataType + R"(, @@ -127,29 +113,71 @@ struct Convolution3dFixture : public ParserFlatbuffersSerializeFixture } }, { + layer_type: "Convolution3dLayer", + layer: { + base: { + index: 2, + layerName: "convolution3d", + layerType: "Convolution3d", + inputSlots: [ + { + connection: { + sourceLayerIndex: 0, + outputSlotIndex: 0 + } + }, + { + index: 1, + connection: { + sourceLayerIndex: 1, + outputSlotIndex: 0 + } + } + ], + outputSlots: [ + { + tensorInfo: { + dimensions: )" + outputShape + R"(, + dataType: )" + dataType + R"(, + quantizationScale: 0.1, + dimensionSpecificity: [ + true, + true, + true, + true, + true + ] + } + } + ] + }, + descriptor: { + strideX: 2, + strideY: 2, + strideZ: 2 + } + } + }, + { layer_type: "OutputLayer", layer: { base: { layerBindingId: 2, base: { - index: 2, + index: 3, layerName: "OutputLayer", layerType: "Output", inputSlots: [ { connection: { - sourceLayerIndex: 1, + sourceLayerIndex: 2, outputSlotIndex: 0 } } ], - outputSlots: [{ - index: 0, - tensorInfo: { - dimensions: )" + outputShape + R"(, - dataType: )" + dataType + R"( - }, - }] + outputSlots: [ + + ] } } } |