From fc598e15ff30bc375c95c9536d4a56662d867926 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Tue, 14 May 2019 10:36:13 +0100 Subject: 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 --- src/armnn/test/ConstTensorLayerVisitor.cpp | 45 ++++++++++++++++++------------ src/armnn/test/CreateWorkload.hpp | 10 +++++-- src/armnn/test/NetworkTests.cpp | 6 +++- src/armnn/test/QuantizerTest.cpp | 30 ++++++++------------ 4 files changed, 52 insertions(+), 39 deletions(-) (limited to 'src/armnn/test') 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 biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional optionalBiases(biases); - TestConvolution2dLayerVisitor visitor(descriptor, weights, Optional(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 biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional optionalBiases(biases); - TestConvolution2dLayerVisitor visitor(descriptor, weights, Optional(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 biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional optionalBiases(biases); - TestDepthwiseConvolution2dLayerVisitor visitor(descriptor, weights, Optional(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 biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional optionalBiases(biases); - TestDepthwiseConvolution2dLayerVisitor visitor(descriptor, weights, Optional(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 biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional optionalBiases(biases); - TestFullyConnectedLayerVistor visitor(descriptor, weights, Optional(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 biasData = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector biasDimensions = {1, 1, 3, 3}; ConstTensor biases(TensorInfo(4, biasDimensions.data(), DataType::Float32), biasData); + Optional optionalBiases(biases); - TestFullyConnectedLayerVistor visitor(descriptor, weights, Optional(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> 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(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 optionalBias; + std::vector biasData{10.0f, 20.0f, 30.0f}; if (desc.m_BiasEnabled) { - std::vector 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(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 optionalBiases; + std::vector biasesData{-1.0f, 1.5f, 2.0f}; if (useBiases) { - std::vector 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(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 optionalBiases; + std::vector biasesData{-1.0f, 1.5f, 2.0f}; if (useBiases) { - std::vector 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(biases); } + depthwiseConv2d = network->AddDepthwiseConvolution2dLayer(descriptor, weights, optionalBiases); IConnectableLayer* output = network->AddOutputLayer(1); // Establish connections -- cgit v1.2.1