aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAron Virginas-Tar <Aron.Virginas-Tar@arm.com>2019-02-22 17:03:44 +0000
committerAron Virginas-Tar <aron.virginas-tar@arm.com>2019-02-27 14:39:42 +0000
commitad402709dc137a001cab024cd3b4ad97132a2bf0 (patch)
tree16102291542725726dda37568418ec8824a1f88e
parentb56292c0040aa125cdaafcee1a4299c5cd144200 (diff)
downloadarmnn-ad402709dc137a001cab024cd3b4ad97132a2bf0.tar.gz
IVGCVSW-2752 Make biases optional in INetwork
* Added new version of AddConvolution2dLayer, AddDepthwiseConvolution2dLayer and AddFullyConnectedLayer with Optional<ConstTensor> biases * Deprecated old AddConvolution2dLayer, AddDepthwiseConvolution2dLayer and AddFullyConnectedLayer methods * Made necessary changes to implementation functions Change-Id: I65eddb28dc72a9c74429c331815a96c2bfdc8c51 Signed-off-by: Aron Virginas-Tar <Aron.Virginas-Tar@arm.com>
-rw-r--r--include/armnn/INetwork.hpp48
-rw-r--r--src/armnn/Network.cpp75
-rw-r--r--src/armnn/Network.hpp62
3 files changed, 134 insertions, 51 deletions
diff --git a/include/armnn/INetwork.hpp b/include/armnn/INetwork.hpp
index a59000b334..a4dd0da25d 100644
--- a/include/armnn/INetwork.hpp
+++ b/include/armnn/INetwork.hpp
@@ -104,29 +104,44 @@ public:
/// Adds a 2D convolution layer to the network.
/// @param convolution2dDescriptor - Description of the 2D convolution layer.
/// @param weights - Tensor for the weights data.
- /// @param biases - (Optional) Tensor for the bias data. Must match the output tensor shape.
+ /// @param biases - Optional tensor for the bias data. If specified, must match the output tensor shape.
/// @param name - Optional name for the layer.
/// @return - Interface for configuring the layer.
virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
- const ConstTensor& weights,
- const char* name = nullptr) = 0;
+ const ConstTensor& weights,
+ const Optional<ConstTensor>& biases,
+ const char* name = nullptr) = 0;
+ /// @deprecated
virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
- const ConstTensor& weights,
- const ConstTensor& biases,
- const char* name = nullptr) = 0;
+ const ConstTensor& weights,
+ const char* name = nullptr) = 0;
+
+ /// @deprecated
+ virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
+ const ConstTensor& weights,
+ const ConstTensor& biases,
+ const char* name = nullptr) = 0;
/// Adds a 2D depthwise convolution layer to the network.
/// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer.
/// @param weights - Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width].
- /// @param biases (Optional) - Tensor for the bias data. Must match the output tensor shape.
+ /// @param biases Optional tensor for the bias data. If specified, must match the output tensor shape.
/// @param name - Optional name for the layer.
/// @return - Interface for configuring the layer.
virtual IConnectableLayer* AddDepthwiseConvolution2dLayer(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
+ const Optional<ConstTensor>& biases,
+ const char* name = nullptr) = 0;
+
+ /// @deprecated
+ virtual IConnectableLayer* AddDepthwiseConvolution2dLayer(
+ const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
+ const ConstTensor& weights,
const char* name = nullptr) = 0;
+ /// @deprecated
virtual IConnectableLayer* AddDepthwiseConvolution2dLayer(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
@@ -146,17 +161,24 @@ public:
/// Adds a fully connected layer to the network.
/// @param fullyConnectedDescriptor - Description of the fully connected layer.
/// @param weights - Tensor for the weights data.
- /// @param biases - (Optional) Tensor for the bias data.
+ /// @param biases - Optional tensor for the bias data.
/// @param name - Optional name for the layer.
/// @return - Interface for configuring the layer.
virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
- const ConstTensor& weights,
- const char* name = nullptr) = 0;
+ const ConstTensor& weights,
+ const Optional<ConstTensor>& biases,
+ const char* name = nullptr) = 0;
+ /// @deprecated
virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
- const ConstTensor& weights,
- const ConstTensor& biases,
- const char* name = nullptr) = 0;
+ const ConstTensor& weights,
+ const char* name = nullptr) = 0;
+
+ /// @deprecated
+ virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
+ const ConstTensor& weights,
+ const ConstTensor& biases,
+ const char* name = nullptr) = 0;
/// Adds a permute layer to the network.
/// @param permuteDescriptor - PermuteDescriptor to configure the permute.
diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp
index cad1690cbd..bd5adccf86 100644
--- a/src/armnn/Network.cpp
+++ b/src/armnn/Network.cpp
@@ -537,12 +537,12 @@ IConnectableLayer* Network::AddBatchToSpaceNdLayer(const BatchToSpaceNdDescripto
IConnectableLayer* Network::AddFullyConnectedLayerImpl(const FullyConnectedDescriptor& fullyConnectedDescriptor,
const ConstTensor& weights,
- const ConstTensor* biases,
+ const Optional<ConstTensor>& biases,
const char* name)
{
- if (fullyConnectedDescriptor.m_BiasEnabled && (biases == nullptr))
+ if (fullyConnectedDescriptor.m_BiasEnabled && !biases.has_value())
{
- throw InvalidArgumentException("AddFullyConnectedLayer: biases cannot be NULL");
+ throw InvalidArgumentException("AddFullyConnectedLayer: biases cannot be empty");
}
const auto layer = m_Graph->AddLayer<FullyConnectedLayer>(fullyConnectedDescriptor, name);
@@ -551,7 +551,7 @@ IConnectableLayer* Network::AddFullyConnectedLayerImpl(const FullyConnectedDescr
if (fullyConnectedDescriptor.m_BiasEnabled)
{
- layer->m_Bias = std::make_unique<ScopedCpuTensorHandle>(*biases);
+ layer->m_Bias = std::make_unique<ScopedCpuTensorHandle>(biases.value());
}
return layer;
@@ -559,27 +559,39 @@ IConnectableLayer* Network::AddFullyConnectedLayerImpl(const FullyConnectedDescr
IConnectableLayer* Network::AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
const ConstTensor& weights,
+ const Optional<ConstTensor>& biases,
const char* name)
{
- return AddFullyConnectedLayerImpl(fullyConnectedDescriptor, weights, nullptr, name);
+ return AddFullyConnectedLayerImpl(fullyConnectedDescriptor, weights, biases, name);
}
+/// @deprecated
+IConnectableLayer* Network::AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
+ const ConstTensor& weights,
+ const char* name)
+{
+ Optional<ConstTensor> biases = EmptyOptional();
+ return AddFullyConnectedLayerImpl(fullyConnectedDescriptor, weights, biases, name);
+}
+
+/// @deprecated
IConnectableLayer* Network::AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
const ConstTensor& weights,
const ConstTensor& biases,
const char* name)
{
- return AddFullyConnectedLayerImpl(fullyConnectedDescriptor, weights, &biases, name);
+ Optional<ConstTensor> optionalBiases(biases);
+ return AddFullyConnectedLayerImpl(fullyConnectedDescriptor, weights, optionalBiases, name);
}
IConnectableLayer* Network::AddConvolution2dLayerImpl(const Convolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
- const ConstTensor* biases,
+ const Optional<ConstTensor>& biases,
const char* name)
{
- if (convolution2dDescriptor.m_BiasEnabled && (biases == nullptr))
+ if (convolution2dDescriptor.m_BiasEnabled && !biases.has_value())
{
- throw InvalidArgumentException("AddConvolution2dLayer: biases cannot be NULL");
+ throw InvalidArgumentException("AddConvolution2dLayer: biases cannot be empty");
}
const auto layer = m_Graph->AddLayer<Convolution2dLayer>(convolution2dDescriptor, name);
@@ -588,7 +600,7 @@ IConnectableLayer* Network::AddConvolution2dLayerImpl(const Convolution2dDescrip
if (convolution2dDescriptor.m_BiasEnabled)
{
- layer->m_Bias = std::make_unique<ScopedCpuTensorHandle>(*biases);
+ layer->m_Bias = std::make_unique<ScopedCpuTensorHandle>(biases.value());
}
return layer;
@@ -596,27 +608,40 @@ IConnectableLayer* Network::AddConvolution2dLayerImpl(const Convolution2dDescrip
IConnectableLayer* Network::AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
+ const Optional<ConstTensor>& biases,
+ const char* name)
+{
+ return AddConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name);
+}
+
+/// @deprecated
+IConnectableLayer* Network::AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
+ const ConstTensor& weights,
const char* name)
{
- return AddConvolution2dLayerImpl(convolution2dDescriptor, weights, nullptr, name);
+ Optional<ConstTensor> biases = EmptyOptional();
+ return AddConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name);
}
+
+/// @deprecated
IConnectableLayer* Network::AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
const ConstTensor& biases,
const char* name)
{
- return AddConvolution2dLayerImpl(convolution2dDescriptor, weights, &biases, name);
+ Optional<ConstTensor> optionalBiases(biases);
+ return AddConvolution2dLayerImpl(convolution2dDescriptor, weights, optionalBiases, name);
}
IConnectableLayer* Network::AddDepthwiseConvolution2dLayerImpl(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
- const ConstTensor* biases,
+ const Optional<ConstTensor>& biases,
const char* name)
{
- if (convolution2dDescriptor.m_BiasEnabled && (biases == nullptr))
+ if (convolution2dDescriptor.m_BiasEnabled && !biases.has_value())
{
- throw InvalidArgumentException("AddDepthwiseConvolution2dLayer: biases cannot be NULL");
+ throw InvalidArgumentException("AddDepthwiseConvolution2dLayer: biases cannot be empty");
}
const auto layer = m_Graph->AddLayer<DepthwiseConvolution2dLayer>(convolution2dDescriptor, name);
@@ -625,26 +650,40 @@ IConnectableLayer* Network::AddDepthwiseConvolution2dLayerImpl(
if (convolution2dDescriptor.m_BiasEnabled)
{
- layer->m_Bias = std::make_unique<ScopedCpuTensorHandle>(*biases);
+ layer->m_Bias = std::make_unique<ScopedCpuTensorHandle>(biases.value());
}
return layer;
}
IConnectableLayer* Network::AddDepthwiseConvolution2dLayer(
+ const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
+ const ConstTensor& weights,
+ const Optional<ConstTensor>& biases,
+ const char* name)
+{
+ return AddDepthwiseConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name);
+}
+
+/// @deprecated
+IConnectableLayer* Network::AddDepthwiseConvolution2dLayer(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
const char* name)
{
- return AddDepthwiseConvolution2dLayerImpl(convolution2dDescriptor, weights, nullptr, name);
+ Optional<ConstTensor> biases = EmptyOptional();
+ return AddDepthwiseConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name);
}
+
+/// @deprecated
IConnectableLayer* Network::AddDepthwiseConvolution2dLayer(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
const ConstTensor& biases,
const char* name)
{
- return AddDepthwiseConvolution2dLayerImpl(convolution2dDescriptor, weights, &biases, name);
+ Optional<ConstTensor> optionalBiases(biases);
+ return AddDepthwiseConvolution2dLayerImpl(convolution2dDescriptor, weights, optionalBiases, name);
}
IConnectableLayer* Network::AddDetectionPostProcessLayer(const armnn::DetectionPostProcessDescriptor& descriptor,
diff --git a/src/armnn/Network.hpp b/src/armnn/Network.hpp
index 3754c2e6d1..e50ce79052 100644
--- a/src/armnn/Network.hpp
+++ b/src/armnn/Network.hpp
@@ -38,24 +38,39 @@ public:
const char* name = nullptr) override;
IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
- const ConstTensor& weights,
- const char* name = nullptr) override;
+ const ConstTensor& weights,
+ const Optional<ConstTensor>& biases,
+ const char* name = nullptr) override;
+
+ /// @deprecated
+ IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
+ const ConstTensor& weights,
+ const char* name = nullptr) override;
+ /// @deprecated
IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
+ const ConstTensor& weights,
+ const ConstTensor& biases,
+ const char* name = nullptr) override;
+
+ IConnectableLayer* AddDepthwiseConvolution2dLayer(
+ const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
- const ConstTensor& biases,
+ const Optional<ConstTensor>& biases,
const char* name = nullptr) override;
+ /// @deprecated
IConnectableLayer* AddDepthwiseConvolution2dLayer(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
- const ConstTensor& weights,
- const char* name = nullptr) override;
+ const ConstTensor& weights,
+ const char* name = nullptr) override;
+ /// @deprecated
IConnectableLayer* AddDepthwiseConvolution2dLayer(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
- const ConstTensor& weights,
- const ConstTensor& biases,
- const char* name = nullptr) override;
+ const ConstTensor& weights,
+ const ConstTensor& biases,
+ const char* name = nullptr) override;
IConnectableLayer* AddDetectionPostProcessLayer(
const DetectionPostProcessDescriptor& descriptor,
@@ -63,13 +78,20 @@ public:
const char* name = nullptr) override;
IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
- const ConstTensor& weights,
- const char* name = nullptr) override;
+ const ConstTensor& weights,
+ const Optional<ConstTensor>& biases,
+ const char* name = nullptr) override;
+ /// @deprecated
IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
- const ConstTensor& weights,
- const ConstTensor& biases,
- const char* name = nullptr) override;
+ const ConstTensor& weights,
+ const char* name = nullptr) override;
+
+ /// @deprecated
+ IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
+ const ConstTensor& weights,
+ const ConstTensor& biases,
+ const char* name = nullptr) override;
IConnectableLayer* AddGatherLayer(const char* name = nullptr) override;
@@ -152,19 +174,19 @@ public:
private:
IConnectableLayer* AddFullyConnectedLayerImpl(const FullyConnectedDescriptor& fullyConnectedDescriptor,
- const ConstTensor& weights,
- const ConstTensor* biases,
- const char* name);
+ const ConstTensor& weights,
+ const Optional<ConstTensor>& biases,
+ const char* name);
IConnectableLayer* AddConvolution2dLayerImpl(const Convolution2dDescriptor& convolution2dDescriptor,
- const ConstTensor& weights,
- const ConstTensor* biases,
- const char* name);
+ const ConstTensor& weights,
+ const Optional<ConstTensor>& biases,
+ const char* name);
IConnectableLayer* AddDepthwiseConvolution2dLayerImpl(
const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
const ConstTensor& weights,
- const ConstTensor* biases,
+ const Optional<ConstTensor>& biases,
const char* name);
std::unique_ptr<Graph> m_Graph;