diff options
author | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-05-14 10:36:13 +0100 |
---|---|---|
committer | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-05-14 13:33:59 +0100 |
commit | fc598e15ff30bc375c95c9536d4a56662d867926 (patch) | |
tree | 0d17a7928ae4faab6978552e666123bfc1926d93 /src/armnn | |
parent | 906f94631aa7ef590b9d8ff45507e818a0d1ac2c (diff) | |
download | armnn-fc598e15ff30bc375c95c9536d4a56662d867926.tar.gz |
Use the new deprecation API
* Used the new ARMNN_DEPRECATED_MSG macro instead of @deprecated
* Refactored the code to no longer use the deprecated methods where
applicable
!android-nn-driver:1126
Change-Id: Ib0578d3d6fc5a763f5fb922f67ba91fafc7796f6
Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
Diffstat (limited to 'src/armnn')
-rw-r--r-- | src/armnn/Network.cpp | 12 | ||||
-rw-r--r-- | src/armnn/Network.hpp | 12 | ||||
-rw-r--r-- | src/armnn/QuantizerVisitor.cpp | 55 | ||||
-rw-r--r-- | src/armnn/test/ConstTensorLayerVisitor.cpp | 45 | ||||
-rw-r--r-- | src/armnn/test/CreateWorkload.hpp | 10 | ||||
-rw-r--r-- | src/armnn/test/NetworkTests.cpp | 6 | ||||
-rw-r--r-- | src/armnn/test/QuantizerTest.cpp | 30 |
7 files changed, 86 insertions, 84 deletions
diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp index 087ec0f8e9..956d2a4bde 100644 --- a/src/armnn/Network.cpp +++ b/src/armnn/Network.cpp @@ -583,16 +583,14 @@ IConnectableLayer* Network::AddFullyConnectedLayer(const FullyConnectedDescripto return AddFullyConnectedLayerImpl(fullyConnectedDescriptor, weights, biases, name); } -/// @deprecated IConnectableLayer* Network::AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, const ConstTensor& weights, const char* name) { - Optional<ConstTensor> biases = EmptyOptional(); + Optional<ConstTensor> biases; return AddFullyConnectedLayerImpl(fullyConnectedDescriptor, weights, biases, name); } -/// @deprecated IConnectableLayer* Network::AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, const ConstTensor& weights, const ConstTensor& biases, @@ -640,16 +638,14 @@ IConnectableLayer* Network::AddConvolution2dLayer(const Convolution2dDescriptor& return AddConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name); } -/// @deprecated IConnectableLayer* Network::AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, const ConstTensor& weights, const char* name) { - Optional<ConstTensor> biases = EmptyOptional(); + Optional<ConstTensor> biases; return AddConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name); } -/// @deprecated IConnectableLayer* Network::AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, const ConstTensor& weights, const ConstTensor& biases, @@ -691,17 +687,15 @@ IConnectableLayer* Network::AddDepthwiseConvolution2dLayer( return AddDepthwiseConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name); } -/// @deprecated IConnectableLayer* Network::AddDepthwiseConvolution2dLayer( const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, const ConstTensor& weights, const char* name) { - Optional<ConstTensor> biases = EmptyOptional(); + Optional<ConstTensor> biases; return AddDepthwiseConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name); } -/// @deprecated IConnectableLayer* Network::AddDepthwiseConvolution2dLayer( const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, const ConstTensor& weights, diff --git a/src/armnn/Network.hpp b/src/armnn/Network.hpp index a569a7c847..d26c2864ff 100644 --- a/src/armnn/Network.hpp +++ b/src/armnn/Network.hpp @@ -45,12 +45,12 @@ public: const Optional<ConstTensor>& biases, const char* name = nullptr) override; - /// @deprecated + ARMNN_DEPRECATED_MSG("This AddConvolution2dLayer overload is deprecated") IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, const ConstTensor& weights, const char* name = nullptr) override; - /// @deprecated + ARMNN_DEPRECATED_MSG("This AddConvolution2dLayer overload is deprecated") IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor, const ConstTensor& weights, const ConstTensor& biases, @@ -62,13 +62,13 @@ public: const Optional<ConstTensor>& biases, const char* name = nullptr) override; - /// @deprecated + ARMNN_DEPRECATED_MSG("This AddDepthwiseConvolution2dLayer overload is deprecated") IConnectableLayer* AddDepthwiseConvolution2dLayer( const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, const ConstTensor& weights, const char* name = nullptr) override; - /// @deprecated + ARMNN_DEPRECATED_MSG("This AddDepthwiseConvolution2dLayer overload is deprecated") IConnectableLayer* AddDepthwiseConvolution2dLayer( const DepthwiseConvolution2dDescriptor& convolution2dDescriptor, const ConstTensor& weights, @@ -87,12 +87,12 @@ public: const Optional<ConstTensor>& biases, const char* name = nullptr) override; - /// @deprecated + ARMNN_DEPRECATED_MSG("This AddFullyConnectedLayer overload is deprecated") IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, const ConstTensor& weights, const char* name = nullptr) override; - /// @deprecated + ARMNN_DEPRECATED_MSG("This AddFullyConnectedLayer overload is deprecated") IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor, const ConstTensor& weights, const ConstTensor& biases, diff --git a/src/armnn/QuantizerVisitor.cpp b/src/armnn/QuantizerVisitor.cpp index 38e33cf2a3..4a87ca16ce 100644 --- a/src/armnn/QuantizerVisitor.cpp +++ b/src/armnn/QuantizerVisitor.cpp @@ -90,19 +90,20 @@ void QuantizerVisitor::VisitFullyConnectedLayer(const IConnectableLayer *layer, { std::vector<uint8_t> weightsBacking; ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking); + Optional<ConstTensor> optionalQBiases; + std::vector<uint8_t> biasesBacking; - IConnectableLayer* newLayer; if (biases.has_value()) { - std::vector<uint8_t> biasBacking; - ConstTensor qBias = CreateQuantizedConst(biases.value(), biasBacking); - newLayer = m_QuantizedNetwork->AddFullyConnectedLayer(desc, qWeights, qBias, name); - } - else - { - newLayer = m_QuantizedNetwork->AddFullyConnectedLayer(desc, qWeights, name); + ConstTensor qBiases = CreateQuantizedConst(biases.value(), biasesBacking); + optionalQBiases = Optional<ConstTensor>(qBiases); } + IConnectableLayer* newLayer = m_QuantizedNetwork->AddFullyConnectedLayer(desc, + qWeights, + optionalQBiases, + name); + RecordLayer(layer, newLayer); SetQuantizedInputConnections(layer, newLayer); } @@ -185,23 +186,20 @@ void QuantizerVisitor::VisitConvolution2dLayer(const IConnectableLayer* layer, { std::vector<uint8_t> weightsBacking; ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking); + Optional<ConstTensor> optionalQBiases; + std::vector<uint8_t> biasesBacking; - IConnectableLayer* newLayer; if (biases.has_value()) { - std::vector<uint8_t> biasesBacking; ConstTensor qBiases = CreateQuantizedConst(biases.value(), biasesBacking); - - newLayer = m_QuantizedNetwork->AddConvolution2dLayer(convolution2dDescriptor, - qWeights, - qBiases, - name); - } - else - { - newLayer = m_QuantizedNetwork->AddConvolution2dLayer(convolution2dDescriptor, qWeights, name); + optionalQBiases = Optional<ConstTensor>(qBiases); } + IConnectableLayer* newLayer = m_QuantizedNetwork->AddConvolution2dLayer(convolution2dDescriptor, + qWeights, + optionalQBiases, + name); + RecordLayer(layer, newLayer); SetQuantizedInputConnections(layer, newLayer); } @@ -214,23 +212,20 @@ void QuantizerVisitor::VisitDepthwiseConvolution2dLayer(const IConnectableLayer* { std::vector<uint8_t> weightsBacking; ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking); + Optional<ConstTensor> optionalQBiases; + std::vector<uint8_t> biasesBacking; - IConnectableLayer* newLayer; if (biases.has_value()) { - std::vector<uint8_t> biasesBacking; ConstTensor qBiases = CreateQuantizedConst(biases.value(), biasesBacking); - - newLayer = m_QuantizedNetwork->AddDepthwiseConvolution2dLayer(desc, - qWeights, - qBiases, - name); - } - else - { - newLayer = m_QuantizedNetwork->AddDepthwiseConvolution2dLayer(desc, qWeights, name); + optionalQBiases = Optional<ConstTensor>(qBiases); } + IConnectableLayer* newLayer = m_QuantizedNetwork->AddDepthwiseConvolution2dLayer(desc, + qWeights, + optionalQBiases, + name); + RecordLayer(layer, newLayer); SetQuantizedInputConnections(layer, newLayer); } diff --git a/src/armnn/test/ConstTensorLayerVisitor.cpp b/src/armnn/test/ConstTensorLayerVisitor.cpp index 5b77ddeb97..e17ee46c81 100644 --- a/src/armnn/test/ConstTensorLayerVisitor.cpp +++ b/src/armnn/test/ConstTensorLayerVisitor.cpp @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer) Network net; - IConnectableLayer* const layer = net.AddConvolution2dLayer(descriptor, weights); + IConnectableLayer* const layer = net.AddConvolution2dLayer(descriptor, weights, EmptyOptional()); layer->Accept(visitor); } @@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE(CheckNamedConvolution2dLayer) Network net; - IConnectableLayer* const layer = net.AddConvolution2dLayer(descriptor, weights, layerName); + IConnectableLayer* const layer = net.AddConvolution2dLayer(descriptor, weights, EmptyOptional(), layerName); layer->Accept(visitor); } @@ -175,12 +175,13 @@ BOOST_AUTO_TEST_CASE(CheckConvolution2dLayerWithBiases) std::vector<float> biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector<unsigned int> biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional<ConstTensor> optionalBiases(biases); - TestConvolution2dLayerVisitor visitor(descriptor, weights, Optional<ConstTensor>(biases)); + TestConvolution2dLayerVisitor visitor(descriptor, weights, optionalBiases); Network net; - IConnectableLayer* const layer = net.AddConvolution2dLayer(descriptor, weights, biases); + IConnectableLayer* const layer = net.AddConvolution2dLayer(descriptor, weights, optionalBiases); layer->Accept(visitor); } @@ -204,12 +205,13 @@ BOOST_AUTO_TEST_CASE(CheckNamedConvolution2dLayerWithBiases) std::vector<float> biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector<unsigned int> biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional<ConstTensor> optionalBiases(biases); - TestConvolution2dLayerVisitor visitor(descriptor, weights, Optional<ConstTensor>(biases), layerName); + TestConvolution2dLayerVisitor visitor(descriptor, weights, optionalBiases, layerName); Network net; - IConnectableLayer* const layer = net.AddConvolution2dLayer(descriptor, weights, biases, layerName); + IConnectableLayer* const layer = net.AddConvolution2dLayer(descriptor, weights, optionalBiases, layerName); layer->Accept(visitor); } @@ -232,7 +234,7 @@ BOOST_AUTO_TEST_CASE(CheckDepthwiseConvolution2dLayer) Network net; - IConnectableLayer* const layer = net.AddDepthwiseConvolution2dLayer(descriptor, weights); + IConnectableLayer* const layer = net.AddDepthwiseConvolution2dLayer(descriptor, weights, EmptyOptional()); layer->Accept(visitor); } @@ -256,7 +258,10 @@ BOOST_AUTO_TEST_CASE(CheckNamedDepthwiseConvolution2dLayer) Network net; - IConnectableLayer* const layer = net.AddDepthwiseConvolution2dLayer(descriptor, weights, layerName); + IConnectableLayer* const layer = net.AddDepthwiseConvolution2dLayer(descriptor, + weights, + EmptyOptional(), + layerName); layer->Accept(visitor); } @@ -279,12 +284,13 @@ BOOST_AUTO_TEST_CASE(CheckDepthwiseConvolution2dLayerWithBiases) std::vector<float> biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector<unsigned int> biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional<ConstTensor> optionalBiases(biases); - TestDepthwiseConvolution2dLayerVisitor visitor(descriptor, weights, Optional<ConstTensor>(biases)); + TestDepthwiseConvolution2dLayerVisitor visitor(descriptor, weights, optionalBiases); Network net; - IConnectableLayer* const layer = net.AddDepthwiseConvolution2dLayer(descriptor, weights, biases); + IConnectableLayer* const layer = net.AddDepthwiseConvolution2dLayer(descriptor, weights, optionalBiases); layer->Accept(visitor); } @@ -308,12 +314,13 @@ BOOST_AUTO_TEST_CASE(CheckNamedDepthwiseConvolution2dLayerWithBiases) std::vector<float> biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector<unsigned int> biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional<ConstTensor> optionalBiases(biases); - TestDepthwiseConvolution2dLayerVisitor visitor(descriptor, weights, Optional<ConstTensor>(biases), layerName); + TestDepthwiseConvolution2dLayerVisitor visitor(descriptor, weights, optionalBiases, layerName); Network net; - IConnectableLayer* const layer = net.AddDepthwiseConvolution2dLayer(descriptor, weights, biases, layerName); + IConnectableLayer* const layer = net.AddDepthwiseConvolution2dLayer(descriptor, weights, optionalBiases, layerName); layer->Accept(visitor); } @@ -330,7 +337,7 @@ BOOST_AUTO_TEST_CASE(CheckFullyConnectedLayer) Network net; - IConnectableLayer* const layer = net.AddFullyConnectedLayer(descriptor, weights); + IConnectableLayer* const layer = net.AddFullyConnectedLayer(descriptor, weights, EmptyOptional()); layer->Accept(visitor); } @@ -348,7 +355,7 @@ BOOST_AUTO_TEST_CASE(CheckNamedFullyConnectedLayer) Network net; - IConnectableLayer* const layer = net.AddFullyConnectedLayer(descriptor, weights, layerName); + IConnectableLayer* const layer = net.AddFullyConnectedLayer(descriptor, weights, EmptyOptional(), layerName); layer->Accept(visitor); } @@ -365,12 +372,13 @@ BOOST_AUTO_TEST_CASE(CheckFullyConnectedLayerWithBiases) std::vector<float> biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector<unsigned int> biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional<ConstTensor> optionalBiases(biases); - TestFullyConnectedLayerVistor visitor(descriptor, weights, Optional<ConstTensor>(biases)); + TestFullyConnectedLayerVistor visitor(descriptor, weights, optionalBiases); Network net; - IConnectableLayer* const layer = net.AddFullyConnectedLayer(descriptor, weights, biases); + IConnectableLayer* const layer = net.AddFullyConnectedLayer(descriptor, weights, optionalBiases); layer->Accept(visitor); } @@ -388,12 +396,13 @@ BOOST_AUTO_TEST_CASE(CheckNamedFullyConnectedLayerWithBiases) std::vector<float> biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector<unsigned int> biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional<ConstTensor> optionalBiases(biases); - TestFullyConnectedLayerVistor visitor(descriptor, weights, Optional<ConstTensor>(biases), layerName); + TestFullyConnectedLayerVistor visitor(descriptor, weights, optionalBiases, layerName); Network net; - IConnectableLayer* const layer = net.AddFullyConnectedLayer(descriptor, weights, biases, layerName); + IConnectableLayer* const layer = net.AddFullyConnectedLayer(descriptor, weights, optionalBiases, layerName); layer->Accept(visitor); } diff --git a/src/armnn/test/CreateWorkload.hpp b/src/armnn/test/CreateWorkload.hpp index a68a6e3f42..1193ab721e 100644 --- a/src/armnn/test/CreateWorkload.hpp +++ b/src/armnn/test/CreateWorkload.hpp @@ -1148,12 +1148,18 @@ std::pair<armnn::IOptimizedNetworkPtr, std::unique_ptr<PreCompiledWorkload>> Cre armnn::ConstTensor biases(biasTensorInfo, biasData); // Create convolution layer with biases - convLayer = net.AddConvolution2dLayer(convDesc2d, weights, biases, convLayerName.c_str()); + convLayer = net.AddConvolution2dLayer(convDesc2d, + weights, + Optional<ConstTensor>(biases), + convLayerName.c_str()); } else { // Create convolution layer without biases - convLayer = net.AddConvolution2dLayer(convDesc2d, weights, convLayerName.c_str()); + convLayer = net.AddConvolution2dLayer(convDesc2d, + weights, + EmptyOptional(), + convLayerName.c_str()); } BOOST_TEST(convLayer); diff --git a/src/armnn/test/NetworkTests.cpp b/src/armnn/test/NetworkTests.cpp index 155304be36..47fd67b8d4 100644 --- a/src/armnn/test/NetworkTests.cpp +++ b/src/armnn/test/NetworkTests.cpp @@ -78,7 +78,10 @@ BOOST_AUTO_TEST_CASE(NetworkModification) armnn::ConstTensor weights(armnn::TensorInfo(4, dims, armnn::DataType::Float32), convWeightsData); armnn::Convolution2dDescriptor convDesc2d; - armnn::IConnectableLayer* const convLayer = net.AddConvolution2dLayer(convDesc2d, weights, "conv layer"); + armnn::IConnectableLayer* const convLayer = net.AddConvolution2dLayer(convDesc2d, + weights, + armnn::EmptyOptional(), + "conv layer"); BOOST_TEST(convLayer); inputLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(0)); @@ -86,6 +89,7 @@ BOOST_AUTO_TEST_CASE(NetworkModification) armnn::FullyConnectedDescriptor fullyConnectedDesc; armnn::IConnectableLayer* const fullyConnectedLayer = net.AddFullyConnectedLayer(fullyConnectedDesc, weights, + armnn::EmptyOptional(), "fully connected"); BOOST_TEST(fullyConnectedLayer); diff --git a/src/armnn/test/QuantizerTest.cpp b/src/armnn/test/QuantizerTest.cpp index 4f22317651..f2c739d274 100644 --- a/src/armnn/test/QuantizerTest.cpp +++ b/src/armnn/test/QuantizerTest.cpp @@ -686,16 +686,14 @@ INetworkPtr CreateNetworkWithFullyConnectedLayer(const bool biasEnabled, // Add the layers IConnectableLayer* input0 = network->AddInputLayer(0); IConnectableLayer* fullyConnected; + Optional<ConstTensor> optionalBias; + std::vector<float> biasData{10.0f, 20.0f, 30.0f}; if (desc.m_BiasEnabled) { - std::vector<float> biasData{10.0f, 20.0f, 30.0f}; ConstTensor bias(info, biasData); - fullyConnected = network->AddFullyConnectedLayer(desc, weights, bias); - } - else - { - fullyConnected = network->AddFullyConnectedLayer(desc, weights); + optionalBias = Optional<ConstTensor>(bias); } + fullyConnected = network->AddFullyConnectedLayer(desc, weights, optionalBias); IConnectableLayer* output = network->AddOutputLayer(1); // Establish connections @@ -814,16 +812,14 @@ void TestQuantizeConvolution2d(bool useBiases) // Add the layers IConnectableLayer* input0 = network->AddInputLayer(0); IConnectableLayer* conv2d; + Optional<ConstTensor> optionalBiases; + std::vector<float> biasesData{-1.0f, 1.5f, 2.0f}; if (useBiases) { - std::vector<float> biasesData{-1.0f, 1.5f, 2.0f}; ConstTensor biases(info, biasesData); - conv2d = network->AddConvolution2dLayer(descriptor, weights, biases); - } - else - { - conv2d = network->AddConvolution2dLayer(descriptor, weights); + optionalBiases = Optional<ConstTensor>(biases); } + conv2d = network->AddConvolution2dLayer(descriptor, weights, optionalBiases); IConnectableLayer* output = network->AddOutputLayer(1); // Establish connections @@ -902,16 +898,14 @@ void TestQuantizeDepthwiseConvolution2d(bool useBiases) // Add the layers IConnectableLayer* input0 = network->AddInputLayer(0); IConnectableLayer* depthwiseConv2d; + Optional<ConstTensor> optionalBiases; + std::vector<float> biasesData{-1.0f, 1.5f, 2.0f}; if (useBiases) { - std::vector<float> biasesData{-1.0f, 1.5f, 2.0f}; ConstTensor biases(info, biasesData); - depthwiseConv2d = network->AddDepthwiseConvolution2dLayer(descriptor, weights, biases); - } - else - { - depthwiseConv2d = network->AddDepthwiseConvolution2dLayer(descriptor, weights); + optionalBiases = Optional<ConstTensor>(biases); } + depthwiseConv2d = network->AddDepthwiseConvolution2dLayer(descriptor, weights, optionalBiases); IConnectableLayer* output = network->AddOutputLayer(1); // Establish connections |