aboutsummaryrefslogtreecommitdiff
path: root/delegate/src/Convolution.hpp
diff options
context:
space:
mode:
authorSadik Armagan <sadik.armagan@arm.com>2022-08-05 16:12:49 +0100
committerSadik Armagan <sadik.armagan@arm.com>2022-08-08 09:23:37 +0100
commit351f334b5480d7aacc8b8ddd916a3ecb74d0c6c1 (patch)
tree1b4ea68c8f66e726373814682e747cea8f50be51 /delegate/src/Convolution.hpp
parent7dbaaa57148c061396c241911936d2e40fd68b7a (diff)
downloadarmnn-351f334b5480d7aacc8b8ddd916a3ecb74d0c6c1.tar.gz
IVGCVSW-7154 'Constant Tensors As Inputs'
* Fixed the issues about converting Conv2D and DepthwiseConv2d input issues * Read 1D input tensors that do not have shape specified Signed-off-by: Sadik Armagan <sadik.armagan@arm.com> Change-Id: I12f3d1c57a2afedac42c6e7b31e4b1fc689abeca
Diffstat (limited to 'delegate/src/Convolution.hpp')
-rw-r--r--delegate/src/Convolution.hpp44
1 files changed, 25 insertions, 19 deletions
diff --git a/delegate/src/Convolution.hpp b/delegate/src/Convolution.hpp
index 679f4dbe39..93da4c8ce2 100644
--- a/delegate/src/Convolution.hpp
+++ b/delegate/src/Convolution.hpp
@@ -1,5 +1,5 @@
//
-// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
@@ -98,7 +98,7 @@ TfLiteStatus VisitConv2dOperator(DelegateData& delegateData,
}
const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteInputTensor);
- const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor);
+ const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor, true);
armnn::TensorInfo filterTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteFilterTensor);
@@ -163,14 +163,17 @@ TfLiteStatus VisitConv2dOperator(DelegateData& delegateData,
// Set up filter and biases
armnn::IConnectableLayer* layer = delegateData.m_Network->AddConvolution2dLayer(descriptor);
- auto filter =
- CreateConstTensor(&tfLiteContext->tensors[tfLiteNode->inputs->data[1]],
- filterTensorInfo,
- armnn::Optional<armnn::PermutationVector&>());
+ if(tflite::IsConstantTensor(&tfLiteContext->tensors[tfLiteNode->inputs->data[1]]))
+ {
+ auto filter =
+ CreateConstTensor(&tfLiteContext->tensors[tfLiteNode->inputs->data[1]],
+ filterTensorInfo,
+ armnn::Optional<armnn::PermutationVector &>());
- armnn::IConnectableLayer* weightsLayer = delegateData.m_Network->AddConstantLayer(filter);
- weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u));
- weightsLayer->GetOutputSlot(0).SetTensorInfo(filterTensorInfo);
+ armnn::IConnectableLayer *weightsLayer = delegateData.m_Network->AddConstantLayer(filter);
+ weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u));
+ weightsLayer->GetOutputSlot(0).SetTensorInfo(filterTensorInfo);
+ }
if (biasEnabled)
{
@@ -255,7 +258,7 @@ TfLiteStatus VisitConv3dOperator(DelegateData& delegateData,
}
const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteInputTensor);
- const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor);
+ const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor, true);
armnn::TensorInfo filterTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteFilterTensor);
@@ -449,7 +452,7 @@ TfLiteStatus VisitDepthwiseConv2dOperator(DelegateData& delegateData,
}
const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteInputTensor);
- const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor);
+ const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor, true);
armnn::TensorInfo filterTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteFilterTensor);
@@ -494,9 +497,6 @@ TfLiteStatus VisitDepthwiseConv2dOperator(DelegateData& delegateData,
biasTensorInfo = armnn::TensorInfo(armnn::TensorShape({1}), GetDataType(tfLiteInputTensor));
}
- // For depthwise the weights layout is the same as for tflite [1, H, W, I*M]. No permutation required.
- auto filter = CreateConstTensor(&tfLiteFilterTensor, filterTensorInfo);
-
if (!delegateData.m_Network)
{
bool isSupported = false;
@@ -508,16 +508,22 @@ TfLiteStatus VisitDepthwiseConv2dOperator(DelegateData& delegateData,
inputTensorInfo,
outputTensorInfo,
descriptor,
- filter.GetInfo(),
+ filterTensorInfo,
armnn::Optional<armnn::TensorInfo>(biasTensorInfo));
return isSupported ? kTfLiteOk : kTfLiteError;
}
armnn::IConnectableLayer* layer = delegateData.m_Network->AddDepthwiseConvolution2dLayer(descriptor);
- armnn::IConnectableLayer* weightsLayer = delegateData.m_Network->AddConstantLayer(filter);
- weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u));
- weightsLayer->GetOutputSlot(0).SetTensorInfo(filterTensorInfo);
+ if(tflite::IsConstantTensor(&tfLiteFilterTensor))
+ {
+ // For depthwise the weights layout is the same as for tflite [1, H, W, I*M]. No permutation required.
+ auto filter = CreateConstTensor(&tfLiteFilterTensor, filterTensorInfo);
+
+ armnn::IConnectableLayer* weightsLayer = delegateData.m_Network->AddConstantLayer(filter);
+ weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u));
+ weightsLayer->GetOutputSlot(0).SetTensorInfo(filterTensorInfo);
+ }
if (biasEnabled)
{
@@ -663,7 +669,7 @@ TfLiteStatus VisitTransposeConv2dOperator(DelegateData& delegateData,
}
const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteInputTensor);
- const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor);
+ const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor, true);
armnn::TensorInfo filterTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteFilterTensor);
// TfLite uses NHWC tensors