diff options
Diffstat (limited to 'src/armnn/Network.cpp')
-rw-r--r-- | src/armnn/Network.cpp | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp index 226d478110..1f4e72771c 100644 --- a/src/armnn/Network.cpp +++ b/src/armnn/Network.cpp @@ -129,12 +129,22 @@ IConnectableLayer* INetwork::AddDepthToSpaceLayer(const DepthToSpaceDescriptor& IConnectableLayer* INetwork::AddDepthwiseConvolution2dLayer( const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, + const char* name) +{ + return pNetworkImpl->AddDepthwiseConvolution2dLayer(convolution2dDescriptor, name); +} + + +ARMNN_NO_DEPRECATE_WARN_BEGIN +IConnectableLayer* INetwork::AddDepthwiseConvolution2dLayer( + const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, const ConstTensor& weights, const Optional<ConstTensor>& biases, const char* name) { return pNetworkImpl->AddDepthwiseConvolution2dLayer(convolution2dDescriptor, weights, biases, name); } +ARMNN_NO_DEPRECATE_WARN_END IConnectableLayer* INetwork::AddDequantizeLayer(const char* name) @@ -1727,7 +1737,6 @@ IOptimizedNetworkPtr Optimize(const Graph& inGraph, PermuteAsReshape(), TransposeAsReshape(), OptimizeConsecutiveReshapes(), - RedirectMembersToConstantInputs(), FoldPadIntoConvolution2d(), FoldPadIntoDepthwiseConvolution2d(), FoldPadIntoPooling2d(), @@ -1736,7 +1745,8 @@ IOptimizedNetworkPtr Optimize(const Graph& inGraph, FuseBatchNormIntoConvolution2DFloat32(), FuseBatchNormIntoConvolution2DFloat16(), FuseBatchNormIntoDepthwiseConvolution2DFloat32(), - FuseBatchNormIntoDepthwiseConvolution2DFloat16())); + FuseBatchNormIntoDepthwiseConvolution2DFloat16(), + RedirectMembersToConstantInputs())); // If Fp32 to Fp16 optimization is set convert Fp32 network to Fp16 if (options.m_ReduceFp32ToFp16) @@ -2066,38 +2076,43 @@ IConnectableLayer* NetworkImpl::AddDepthToSpaceLayer(const DepthToSpaceDescripto return m_Graph->AddLayer<DepthToSpaceLayer>(depthToSpaceDescriptor, name); } -IConnectableLayer* NetworkImpl::AddDepthwiseConvolution2dLayerImpl( - const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, - const ConstTensor& weights, - const Optional<ConstTensor>& biases, - const char* name) +IConnectableLayer* NetworkImpl::AddDepthwiseConvolution2dLayer( + const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, + const char* name) { - if (convolution2dDescriptor.m_BiasEnabled && !biases.has_value()) - { - throw InvalidArgumentException("AddDepthwiseConvolution2dLayer: biases cannot be empty"); - } + return m_Graph->AddLayer<DepthwiseConvolution2dLayer>(convolution2dDescriptor, name); +} - const auto layer = m_Graph->AddLayer<DepthwiseConvolution2dLayer>(convolution2dDescriptor, name); +IConnectableLayer* NetworkImpl::AddDepthwiseConvolution2dLayer( + const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, + const ConstTensor& weights, + const Optional<ConstTensor>& biases, + const char* name) +{ + auto layer = m_Graph->AddLayer<DepthwiseConvolution2dLayer>(convolution2dDescriptor, name); + // Add a constant layer for weights + ConstantLayer* weightsLayer = m_Graph->AddLayer<ConstantLayer>("Weights"); + weightsLayer->m_LayerOutput = std::make_shared<ScopedTensorHandle>(weights); layer->m_Weight = std::make_shared<ScopedTensorHandle>(weights); - if (convolution2dDescriptor.m_BiasEnabled) + weightsLayer->GetOutputSlot(0).SetTensorInfo(weightsLayer->m_LayerOutput->GetTensorInfo()); + weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); + + // Add a constant layer for biases + if (biases.has_value() && convolution2dDescriptor.m_BiasEnabled) { + ConstantLayer* biasLayer = m_Graph->AddLayer<ConstantLayer>("Bias"); + biasLayer->m_LayerOutput = std::make_shared<ScopedTensorHandle>(biases.value()); layer->m_Bias = std::make_shared<ScopedTensorHandle>(biases.value()); + + biasLayer->GetOutputSlot(0).SetTensorInfo(biasLayer->m_LayerOutput->GetTensorInfo()); + biasLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(2)); } return layer; } -IConnectableLayer* NetworkImpl::AddDepthwiseConvolution2dLayer( - const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, - const ConstTensor& weights, - const Optional<ConstTensor>& biases, - const char* name) -{ - return AddDepthwiseConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name); -} - IConnectableLayer* NetworkImpl::AddDetectionPostProcessLayer(const armnn::DetectionPostProcessDescriptor& descriptor, const ConstTensor& anchors, const char* name) { |