ArmNN
 20.11
NetworkTests.cpp File Reference
#include "GraphUtils.hpp"
#include <armnn/LayerVisitorBase.hpp>
#include <Network.hpp>
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (LayerGuids)
 
 BOOST_AUTO_TEST_CASE (NetworkBasic)
 
 BOOST_AUTO_TEST_CASE (LayerNamesAreOptionalForINetwork)
 
 BOOST_AUTO_TEST_CASE (LayerNamesAreOptionalForNetwork)
 
 BOOST_AUTO_TEST_CASE (NetworkModification)
 
 BOOST_AUTO_TEST_CASE (NetworkModification_SplitterConcat)
 
 BOOST_AUTO_TEST_CASE (NetworkModification_SplitterAddition)
 
 BOOST_AUTO_TEST_CASE (NetworkModification_SplitterMultiplication)
 
 BOOST_AUTO_TEST_CASE (Network_AddQuantize)
 
 BOOST_AUTO_TEST_CASE (Network_AddMerge)
 
 BOOST_AUTO_TEST_CASE (StandInLayerNetworkTest)
 
 BOOST_AUTO_TEST_CASE (StandInLayerSingleInputMultipleOutputsNetworkTest)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/12]

BOOST_AUTO_TEST_CASE ( LayerGuids  )

Definition at line 32 of file NetworkTests.cpp.

References Network::AddAdditionLayer(), Network::AddInputLayer(), Network::AddOutputLayer(), and IConnectableLayer::GetGuid().

33 {
34  armnn::Network net;
35  armnn::LayerGuid inputId = net.AddInputLayer(0)->GetGuid();
36  armnn::LayerGuid addId = net.AddAdditionLayer()->GetGuid();
37  armnn::LayerGuid outputId = net.AddOutputLayer(0)->GetGuid();
38 
39  BOOST_TEST(inputId != addId);
40  BOOST_TEST(addId != outputId);
41  BOOST_TEST(inputId != outputId);
42 }
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an output layer to the network.
Definition: Network.cpp:1467
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an input layer to the network.
Definition: Network.cpp:1192
virtual LayerGuid GetGuid() const =0
Returns the unique id of the layer.
Private implementation of INetwork.
Definition: Network.hpp:28
IConnectableLayer * AddAdditionLayer(const char *name=nullptr) override
Adds an addition layer to the network.
Definition: Network.cpp:1457

◆ BOOST_AUTO_TEST_CASE() [2/12]

BOOST_AUTO_TEST_CASE ( NetworkBasic  )

Definition at line 44 of file NetworkTests.cpp.

References Network::PrintGraph(), and armnn::Success.

45 {
46  armnn::Network net;
47  BOOST_TEST(net.PrintGraph() == armnn::Status::Success);
48 }
Status PrintGraph() override
Definition: Network.cpp:1186
Private implementation of INetwork.
Definition: Network.hpp:28

◆ BOOST_AUTO_TEST_CASE() [3/12]

BOOST_AUTO_TEST_CASE ( LayerNamesAreOptionalForINetwork  )

Definition at line 50 of file NetworkTests.cpp.

References INetwork::AddActivationLayer(), INetwork::AddAdditionLayer(), INetwork::AddInputLayer(), and INetwork::AddOutputLayer().

51 {
52  armnn::Network net;
53  armnn::INetwork& inet = net;
54  inet.AddInputLayer(0);
55  inet.AddAdditionLayer();
57  inet.AddOutputLayer(0);
58 }
virtual IConnectableLayer * AddActivationLayer(const ActivationDescriptor &activationDescriptor, const char *name=nullptr)=0
Adds an activation layer to the network.
Main network class which provides the interface for building up a neural network. ...
Definition: INetwork.hpp:105
virtual IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)=0
Adds an output layer to the network.
virtual IConnectableLayer * AddAdditionLayer(const char *name=nullptr)=0
Adds an addition layer to the network.
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:20
Private implementation of INetwork.
Definition: Network.hpp:28
virtual IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)=0
Adds an input layer to the network.

◆ BOOST_AUTO_TEST_CASE() [4/12]

BOOST_AUTO_TEST_CASE ( LayerNamesAreOptionalForNetwork  )

Definition at line 60 of file NetworkTests.cpp.

References Network::AddActivationLayer(), Network::AddAdditionLayer(), Network::AddInputLayer(), and Network::AddOutputLayer().

61 {
62  armnn::Network net;
63  net.AddInputLayer(0);
64  net.AddAdditionLayer();
66  net.AddOutputLayer(0);
67 }
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an output layer to the network.
Definition: Network.cpp:1467
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an input layer to the network.
Definition: Network.cpp:1192
IConnectableLayer * AddActivationLayer(const ActivationDescriptor &activationDescriptor, const char *name=nullptr) override
Adds an activation layer to the network.
Definition: Network.cpp:1400
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:20
Private implementation of INetwork.
Definition: Network.hpp:28
IConnectableLayer * AddAdditionLayer(const char *name=nullptr) override
Adds an addition layer to the network.
Definition: Network.cpp:1457

◆ BOOST_AUTO_TEST_CASE() [5/12]

BOOST_AUTO_TEST_CASE ( NetworkModification  )

Definition at line 69 of file NetworkTests.cpp.

References Network::AddActivationLayer(), Network::AddAdditionLayer(), Network::AddBatchNormalizationLayer(), Network::AddConvolution2dLayer(), Network::AddFullyConnectedLayer(), Network::AddInputLayer(), Network::AddMultiplicationLayer(), Network::AddNormalizationLayer(), Network::AddOutputLayer(), Network::AddPooling2dLayer(), Network::AddSoftmaxLayer(), IOutputSlot::Connect(), armnn::Float32, IOutputSlot::GetConnection(), Network::GetGraph(), IConnectableLayer::GetInputSlot(), IOutputSlot::GetNumConnections(), IConnectableLayer::GetNumInputSlots(), Graph::GetNumLayers(), IConnectableLayer::GetNumOutputSlots(), IConnectableLayer::GetOutputSlot(), and GraphHasNamedLayer().

70 {
71  armnn::Network net;
72 
73  armnn::IConnectableLayer* const inputLayer = net.AddInputLayer(0, "input layer");
74  BOOST_TEST(inputLayer);
75 
76  unsigned int dims[] = { 10,1,1,1 };
77  std::vector<float> convWeightsData(10);
78  armnn::ConstTensor weights(armnn::TensorInfo(4, dims, armnn::DataType::Float32), convWeightsData);
79 
81  armnn::IConnectableLayer* const convLayer = net.AddConvolution2dLayer(convDesc2d,
82  weights,
84  "conv layer");
85  BOOST_TEST(convLayer);
86 
87  inputLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(0));
88 
89  armnn::FullyConnectedDescriptor fullyConnectedDesc;
90  armnn::IConnectableLayer* const fullyConnectedLayer = net.AddFullyConnectedLayer(fullyConnectedDesc,
91  weights,
93  "fully connected");
94  BOOST_TEST(fullyConnectedLayer);
95 
96  convLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(0));
97 
98  armnn::Pooling2dDescriptor pooling2dDesc;
99  armnn::IConnectableLayer* const poolingLayer = net.AddPooling2dLayer(pooling2dDesc, "pooling2d");
100  BOOST_TEST(poolingLayer);
101 
102  fullyConnectedLayer->GetOutputSlot(0).Connect(poolingLayer->GetInputSlot(0));
103 
104  armnn::ActivationDescriptor activationDesc;
105  armnn::IConnectableLayer* const activationLayer = net.AddActivationLayer(activationDesc, "activation");
106  BOOST_TEST(activationLayer);
107 
108  poolingLayer->GetOutputSlot(0).Connect(activationLayer->GetInputSlot(0));
109 
110  armnn::NormalizationDescriptor normalizationDesc;
111  armnn::IConnectableLayer* const normalizationLayer = net.AddNormalizationLayer(normalizationDesc, "normalization");
112  BOOST_TEST(normalizationLayer);
113 
114  activationLayer->GetOutputSlot(0).Connect(normalizationLayer->GetInputSlot(0));
115 
116  armnn::SoftmaxDescriptor softmaxDesc;
117  armnn::IConnectableLayer* const softmaxLayer = net.AddSoftmaxLayer(softmaxDesc, "softmax");
118  BOOST_TEST(softmaxLayer);
119 
120  normalizationLayer->GetOutputSlot(0).Connect(softmaxLayer->GetInputSlot(0));
121 
123 
124  armnn::TensorInfo tensorInfo({ 1 }, armnn::DataType::Float32);
125  std::vector<float> data(tensorInfo.GetNumBytes() / sizeof(float));
126  armnn::ConstTensor invalidTensor(tensorInfo, data);
127 
128  armnn::IConnectableLayer* const batchNormalizationLayer = net.AddBatchNormalizationLayer(batchNormDesc,
129  invalidTensor,
130  invalidTensor,
131  invalidTensor,
132  invalidTensor,
133  "batch norm");
134  BOOST_TEST(batchNormalizationLayer);
135 
136  softmaxLayer->GetOutputSlot(0).Connect(batchNormalizationLayer->GetInputSlot(0));
137 
138  armnn::IConnectableLayer* const additionLayer = net.AddAdditionLayer("addition");
139  BOOST_TEST(additionLayer);
140 
141  batchNormalizationLayer->GetOutputSlot(0).Connect(additionLayer->GetInputSlot(0));
142  batchNormalizationLayer->GetOutputSlot(0).Connect(additionLayer->GetInputSlot(1));
143 
144  armnn::IConnectableLayer* const multiplicationLayer = net.AddMultiplicationLayer("multiplication");
145  BOOST_TEST(multiplicationLayer);
146 
147  additionLayer->GetOutputSlot(0).Connect(multiplicationLayer->GetInputSlot(0));
148  additionLayer->GetOutputSlot(0).Connect(multiplicationLayer->GetInputSlot(1));
149 
150  armnn::IConnectableLayer* const outputLayer = net.AddOutputLayer(0, "output layer");
151  BOOST_TEST(outputLayer);
152 
153  multiplicationLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
154 
155  //Tests that all layers are present in the graph.
156  BOOST_TEST(net.GetGraph().GetNumLayers() == 11);
157 
158  //Tests that the vertices exist and have correct names.
159  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "input layer"));
160  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "conv layer"));
161  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "fully connected"));
162  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "pooling2d"));
163  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "activation"));
164  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "normalization"));
165  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "softmax"));
166  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "batch norm"));
167  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "addition"));
168  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "multiplication"));
169  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "output layer"));
170 
171  auto checkOneOutputToOneInputConnection = []
172  (const armnn::IConnectableLayer* const srcLayer,
173  const armnn::IConnectableLayer* const tgtLayer,
174  int expectedSrcNumInputs = 1,
175  int expectedDstNumOutputs = 1)
176  {
177  BOOST_TEST(srcLayer->GetNumInputSlots() == expectedSrcNumInputs);
178  BOOST_TEST(srcLayer->GetNumOutputSlots() == 1);
179  BOOST_TEST(tgtLayer->GetNumInputSlots() == 1);
180  BOOST_TEST(tgtLayer->GetNumOutputSlots() == expectedDstNumOutputs);
181 
182  BOOST_TEST(srcLayer->GetOutputSlot(0).GetNumConnections() == 1);
183  BOOST_TEST(srcLayer->GetOutputSlot(0).GetConnection(0) == &tgtLayer->GetInputSlot(0));
184  BOOST_TEST(&srcLayer->GetOutputSlot(0) == tgtLayer->GetInputSlot(0).GetConnection());
185  };
186  auto checkOneOutputToTwoInputsConnections = []
187  (const armnn::IConnectableLayer* const srcLayer,
188  const armnn::IConnectableLayer* const tgtLayer,
189  int expectedSrcNumInputs,
190  int expectedDstNumOutputs = 1)
191  {
192  BOOST_TEST(srcLayer->GetNumInputSlots() == expectedSrcNumInputs);
193  BOOST_TEST(srcLayer->GetNumOutputSlots() == 1);
194  BOOST_TEST(tgtLayer->GetNumInputSlots() == 2);
195  BOOST_TEST(tgtLayer->GetNumOutputSlots() == expectedDstNumOutputs);
196 
197  BOOST_TEST(srcLayer->GetOutputSlot(0).GetNumConnections() == 2);
198  for (unsigned int i = 0; i < srcLayer->GetOutputSlot(0).GetNumConnections(); ++i)
199  {
200  BOOST_TEST(srcLayer->GetOutputSlot(0).GetConnection(i) == &tgtLayer->GetInputSlot(i));
201  BOOST_TEST(&srcLayer->GetOutputSlot(0) == tgtLayer->GetInputSlot(i).GetConnection());
202  }
203  };
204 
205  BOOST_TEST(AreAllLayerInputSlotsConnected(*convLayer));
206  BOOST_TEST(AreAllLayerInputSlotsConnected(*fullyConnectedLayer));
207  BOOST_TEST(AreAllLayerInputSlotsConnected(*poolingLayer));
208  BOOST_TEST(AreAllLayerInputSlotsConnected(*activationLayer));
209  BOOST_TEST(AreAllLayerInputSlotsConnected(*normalizationLayer));
210  BOOST_TEST(AreAllLayerInputSlotsConnected(*softmaxLayer));
211  BOOST_TEST(AreAllLayerInputSlotsConnected(*batchNormalizationLayer));
212  BOOST_TEST(AreAllLayerInputSlotsConnected(*additionLayer));
213  BOOST_TEST(AreAllLayerInputSlotsConnected(*multiplicationLayer));
214  BOOST_TEST(AreAllLayerInputSlotsConnected(*outputLayer));
215 
216  // Checks connectivity.
217  checkOneOutputToOneInputConnection(inputLayer, convLayer, 0);
218  checkOneOutputToOneInputConnection(convLayer, fullyConnectedLayer);
219  checkOneOutputToOneInputConnection(fullyConnectedLayer, poolingLayer);
220  checkOneOutputToOneInputConnection(poolingLayer, activationLayer);
221  checkOneOutputToOneInputConnection(activationLayer, normalizationLayer);
222  checkOneOutputToOneInputConnection(normalizationLayer, softmaxLayer);
223  checkOneOutputToOneInputConnection(softmaxLayer, batchNormalizationLayer);
224  checkOneOutputToTwoInputsConnections(batchNormalizationLayer, additionLayer, 1);
225  checkOneOutputToTwoInputsConnections(additionLayer, multiplicationLayer, 2);
226  checkOneOutputToOneInputConnection(multiplicationLayer, outputLayer, 2, 0);
227 }
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
IConnectableLayer * AddPooling2dLayer(const Pooling2dDescriptor &pooling2dDescriptor, const char *name=nullptr) override
Adds a pooling layer to the network.
Definition: Network.cpp:1394
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an output layer to the network.
Definition: Network.cpp:1467
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
A Convolution2dDescriptor for the Convolution2dLayer.
const Graph & GetGraph() const
Definition: Network.hpp:34
bool GraphHasNamedLayer(const armnn::Graph &graph, const std::string &name)
Definition: GraphUtils.cpp:10
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an input layer to the network.
Definition: Network.cpp:1192
virtual const IInputSlot * GetConnection(unsigned int index) const =0
IConnectableLayer * AddFullyConnectedLayer(const FullyConnectedDescriptor &fullyConnectedDescriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr) override
Adds a fully connected layer to the network.
Definition: Network.cpp:1243
IConnectableLayer * AddConvolution2dLayer(const Convolution2dDescriptor &convolution2dDescriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr) override
Adds a 2D convolution layer to the network.
Definition: Network.cpp:1296
A FullyConnectedDescriptor for the FullyConnectedLayer.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:314
IConnectableLayer * AddActivationLayer(const ActivationDescriptor &activationDescriptor, const char *name=nullptr) override
Adds an activation layer to the network.
Definition: Network.cpp:1400
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:20
Private implementation of INetwork.
Definition: Network.hpp:28
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition: Optional.hpp:32
IConnectableLayer * AddBatchNormalizationLayer(const BatchNormalizationDescriptor &desc, const ConstTensor &mean, const ConstTensor &variance, const ConstTensor &beta, const ConstTensor &gamma, const char *name=nullptr) override
Adds a batch normalization layer to the network.
Definition: Network.cpp:1472
IConnectableLayer * AddAdditionLayer(const char *name=nullptr) override
Adds an addition layer to the network.
Definition: Network.cpp:1457
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
IConnectableLayer * AddMultiplicationLayer(const char *name=nullptr) override
Adds a multiplication layer to the network.
Definition: Network.cpp:1462
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual unsigned int GetNumConnections() const =0
IConnectableLayer * AddNormalizationLayer(const NormalizationDescriptor &normalizationDescriptor, const char *name=nullptr) override
Adds a normalization layer to the network.
Definition: Network.cpp:1412
virtual int Connect(IInputSlot &destination)=0
A Pooling2dDescriptor for the Pooling2dLayer.
A NormalizationDescriptor for the NormalizationLayer.
size_t GetNumLayers() const
Definition: Graph.hpp:191
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr) override
Adds a softmax layer to the network.
Definition: Network.cpp:1424
A SoftmaxDescriptor for the SoftmaxLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.

◆ BOOST_AUTO_TEST_CASE() [6/12]

BOOST_AUTO_TEST_CASE ( NetworkModification_SplitterConcat  )

Definition at line 229 of file NetworkTests.cpp.

References Network::AddConcatLayer(), Network::AddInputLayer(), Network::AddOutputLayer(), Network::AddSoftmaxLayer(), Network::AddSplitterLayer(), IOutputSlot::Connect(), IInputSlot::GetConnection(), IOutputSlot::GetConnection(), IConnectableLayer::GetInputSlot(), IConnectableLayer::GetNumInputSlots(), IConnectableLayer::GetNumOutputSlots(), and IConnectableLayer::GetOutputSlot().

230 {
231  armnn::Network net;
232 
233  // Adds an input layer and an input tensor descriptor.
234  armnn::IConnectableLayer* inputLayer = net.AddInputLayer(0, "input layer");
235  BOOST_TEST(inputLayer);
236 
237  // Adds a splitter layer.
238  armnn::ViewsDescriptor splitterDesc(2,4);
239 
240  armnn::IConnectableLayer* splitterLayer = net.AddSplitterLayer(splitterDesc, "splitter layer");
241  BOOST_TEST(splitterLayer);
242 
243  inputLayer->GetOutputSlot(0).Connect(splitterLayer->GetInputSlot(0));
244 
245  // Adds a softmax layer 1.
246  armnn::SoftmaxDescriptor softmaxDescriptor;
247  armnn::IConnectableLayer* softmaxLayer1 = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_1");
248  BOOST_TEST(softmaxLayer1);
249 
250  splitterLayer->GetOutputSlot(0).Connect(softmaxLayer1->GetInputSlot(0));
251 
252  // Adds a softmax layer 2.
253  armnn::IConnectableLayer* softmaxLayer2 = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_2");
254  BOOST_TEST(softmaxLayer2);
255 
256  splitterLayer->GetOutputSlot(1).Connect(softmaxLayer2->GetInputSlot(0));
257 
258  // Adds a concat layer.
259  armnn::OriginsDescriptor concatDesc(2, 4);
260 
261  armnn::IConnectableLayer* concatLayer = net.AddConcatLayer(concatDesc, "concat layer");
262  BOOST_TEST(concatLayer);
263 
264  softmaxLayer1->GetOutputSlot(0).Connect(concatLayer->GetInputSlot(0));
265  softmaxLayer2->GetOutputSlot(0).Connect(concatLayer->GetInputSlot(1));
266 
267  // Adds an output layer.
268  armnn::IConnectableLayer* outputLayer = net.AddOutputLayer(0, "output layer");
269  BOOST_TEST(outputLayer);
270 
271  concatLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
272 
273  BOOST_TEST(splitterLayer->GetNumOutputSlots() == 2);
274  BOOST_TEST(splitterLayer->GetOutputSlot(0).GetConnection(0) == &softmaxLayer1->GetInputSlot(0));
275  BOOST_TEST(&splitterLayer->GetOutputSlot(0) == softmaxLayer1->GetInputSlot(0).GetConnection());
276  BOOST_TEST(splitterLayer->GetOutputSlot(1).GetConnection(0) == &softmaxLayer2->GetInputSlot(0));
277  BOOST_TEST(&splitterLayer->GetOutputSlot(1) == softmaxLayer2->GetInputSlot(0).GetConnection());
278 
279  BOOST_TEST(concatLayer->GetNumInputSlots() == 2);
280  BOOST_TEST(softmaxLayer1->GetOutputSlot(0).GetConnection(0) == &concatLayer->GetInputSlot(0));
281  BOOST_TEST(&softmaxLayer1->GetOutputSlot(0) == concatLayer->GetInputSlot(0).GetConnection());
282  BOOST_TEST(softmaxLayer2->GetOutputSlot(0).GetConnection(0) == &concatLayer->GetInputSlot(1));
283  BOOST_TEST(&softmaxLayer2->GetOutputSlot(0) == concatLayer->GetInputSlot(1).GetConnection());
284 }
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an output layer to the network.
Definition: Network.cpp:1467
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an input layer to the network.
Definition: Network.cpp:1192
virtual const IInputSlot * GetConnection(unsigned int index) const =0
An OriginsDescriptor for the ConcatLayer.
IConnectableLayer * AddConcatLayer(const ConcatDescriptor &concatDescriptor, const char *name=nullptr) override
Adds a concatenation layer to the network.
Definition: Network.cpp:1268
IConnectableLayer * AddSplitterLayer(const ViewsDescriptor &splitterDescriptor, const char *name=nullptr) override
Adds a splitter layer to the network.
Definition: Network.cpp:1430
Private implementation of INetwork.
Definition: Network.hpp:28
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const IOutputSlot * GetConnection() const =0
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual int Connect(IInputSlot &destination)=0
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr) override
Adds a softmax layer to the network.
Definition: Network.cpp:1424
A SoftmaxDescriptor for the SoftmaxLayer.

◆ BOOST_AUTO_TEST_CASE() [7/12]

BOOST_AUTO_TEST_CASE ( NetworkModification_SplitterAddition  )

Definition at line 286 of file NetworkTests.cpp.

References Network::AddAdditionLayer(), Network::AddInputLayer(), Network::AddOutputLayer(), Network::AddSoftmaxLayer(), Network::AddSplitterLayer(), IOutputSlot::Connect(), IConnectableLayer::GetInputSlot(), and IConnectableLayer::GetOutputSlot().

287 {
288  armnn::Network net;
289 
290  // Adds an input layer and an input tensor descriptor.
291  armnn::IConnectableLayer* layer = net.AddInputLayer(0, "input layer");
292  BOOST_TEST(layer);
293 
294  // Adds a splitter layer.
295  armnn::ViewsDescriptor splitterDesc(2,4);
296 
297  armnn::IConnectableLayer* const splitterLayer = net.AddSplitterLayer(splitterDesc, "splitter layer");
298  BOOST_TEST(splitterLayer);
299 
300  layer->GetOutputSlot(0).Connect(splitterLayer->GetInputSlot(0));
301 
302  // Adds a softmax layer 1.
303  armnn::SoftmaxDescriptor softmaxDescriptor;
304  armnn::IConnectableLayer* const softmax1Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_1");
305  BOOST_TEST(softmax1Layer);
306 
307  splitterLayer->GetOutputSlot(0).Connect(softmax1Layer->GetInputSlot(0));
308 
309  // Adds a softmax layer 2.
310  armnn::IConnectableLayer* const softmax2Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_2");
311  BOOST_TEST(softmax2Layer);
312 
313  splitterLayer->GetOutputSlot(1).Connect(softmax2Layer->GetInputSlot(0));
314 
315  // Adds addition layer.
316  layer = net.AddAdditionLayer("add layer");
317  BOOST_TEST(layer);
318 
319  softmax1Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
320  softmax2Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
321 
322  // Adds an output layer.
323  armnn::IConnectableLayer* prevLayer = layer;
324  layer = net.AddOutputLayer(0, "output layer");
325 
326  prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
327 
328  BOOST_TEST(layer);
329 }
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an output layer to the network.
Definition: Network.cpp:1467
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an input layer to the network.
Definition: Network.cpp:1192
IConnectableLayer * AddSplitterLayer(const ViewsDescriptor &splitterDescriptor, const char *name=nullptr) override
Adds a splitter layer to the network.
Definition: Network.cpp:1430
Private implementation of INetwork.
Definition: Network.hpp:28
IConnectableLayer * AddAdditionLayer(const char *name=nullptr) override
Adds an addition layer to the network.
Definition: Network.cpp:1457
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual int Connect(IInputSlot &destination)=0
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr) override
Adds a softmax layer to the network.
Definition: Network.cpp:1424
A SoftmaxDescriptor for the SoftmaxLayer.

◆ BOOST_AUTO_TEST_CASE() [8/12]

BOOST_AUTO_TEST_CASE ( NetworkModification_SplitterMultiplication  )

Definition at line 331 of file NetworkTests.cpp.

References Network::AddInputLayer(), Network::AddMultiplicationLayer(), Network::AddOutputLayer(), Network::AddSoftmaxLayer(), Network::AddSplitterLayer(), IOutputSlot::Connect(), IConnectableLayer::GetInputSlot(), and IConnectableLayer::GetOutputSlot().

332 {
333  armnn::Network net;
334 
335  // Adds an input layer and an input tensor descriptor.
336  armnn::IConnectableLayer* layer = net.AddInputLayer(0, "input layer");
337  BOOST_TEST(layer);
338 
339  // Adds a splitter layer.
340  armnn::ViewsDescriptor splitterDesc(2,4);
341  armnn::IConnectableLayer* const splitterLayer = net.AddSplitterLayer(splitterDesc, "splitter layer");
342  BOOST_TEST(splitterLayer);
343 
344  layer->GetOutputSlot(0).Connect(splitterLayer->GetInputSlot(0));
345 
346  // Adds a softmax layer 1.
347  armnn::SoftmaxDescriptor softmaxDescriptor;
348  armnn::IConnectableLayer* const softmax1Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_1");
349  BOOST_TEST(softmax1Layer);
350 
351  splitterLayer->GetOutputSlot(0).Connect(softmax1Layer->GetInputSlot(0));
352 
353  // Adds a softmax layer 2.
354  armnn::IConnectableLayer* const softmax2Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_2");
355  BOOST_TEST(softmax2Layer);
356 
357  splitterLayer->GetOutputSlot(1).Connect(softmax2Layer->GetInputSlot(0));
358 
359  // Adds multiplication layer.
360  layer = net.AddMultiplicationLayer("multiplication layer");
361  BOOST_TEST(layer);
362 
363  softmax1Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
364  softmax2Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
365 
366  // Adds an output layer.
367  armnn::IConnectableLayer* prevLayer = layer;
368  layer = net.AddOutputLayer(0, "output layer");
369  BOOST_TEST(layer);
370 
371  prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
372 }
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an output layer to the network.
Definition: Network.cpp:1467
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an input layer to the network.
Definition: Network.cpp:1192
IConnectableLayer * AddSplitterLayer(const ViewsDescriptor &splitterDescriptor, const char *name=nullptr) override
Adds a splitter layer to the network.
Definition: Network.cpp:1430
Private implementation of INetwork.
Definition: Network.hpp:28
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
IConnectableLayer * AddMultiplicationLayer(const char *name=nullptr) override
Adds a multiplication layer to the network.
Definition: Network.cpp:1462
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual int Connect(IInputSlot &destination)=0
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr) override
Adds a softmax layer to the network.
Definition: Network.cpp:1424
A SoftmaxDescriptor for the SoftmaxLayer.

◆ BOOST_AUTO_TEST_CASE() [9/12]

BOOST_AUTO_TEST_CASE ( Network_AddQuantize  )

Definition at line 374 of file NetworkTests.cpp.

References INetwork::Create(), armnn::Float32, IInputSlot::GetConnection(), TensorInfo::GetDataType(), IConnectableLayer::GetInputSlot(), IConnectableLayer::GetName(), IConnectableLayer::GetNumInputSlots(), IConnectableLayer::GetNumOutputSlots(), IConnectableLayer::GetOutputSlot(), IOutputSlot::GetTensorInfo(), armnn::QAsymmU8, and LayerVisitorBase< DefaultPolicy >::VisitQuantizeLayer().

375 {
376  struct Test : public armnn::LayerVisitorBase<armnn::VisitorNoThrowPolicy>
377  {
378  void VisitQuantizeLayer(const armnn::IConnectableLayer* layer, const char* name) override
379  {
380  m_Visited = true;
381 
382  BOOST_TEST(layer);
383 
384  std::string expectedName = std::string("quantize");
385  BOOST_TEST(std::string(layer->GetName()) == expectedName);
386  BOOST_TEST(std::string(name) == expectedName);
387 
388  BOOST_TEST(layer->GetNumInputSlots() == 1);
389  BOOST_TEST(layer->GetNumOutputSlots() == 1);
390 
391  const armnn::TensorInfo& infoIn = layer->GetInputSlot(0).GetConnection()->GetTensorInfo();
392  BOOST_TEST((infoIn.GetDataType() == armnn::DataType::Float32));
393 
394  const armnn::TensorInfo& infoOut = layer->GetOutputSlot(0).GetTensorInfo();
395  BOOST_TEST((infoOut.GetDataType() == armnn::DataType::QAsymmU8));
396  }
397 
398  bool m_Visited = false;
399  };
400 
401 
402  auto graph = armnn::INetwork::Create();
403 
404  auto input = graph->AddInputLayer(0, "input");
405  auto quantize = graph->AddQuantizeLayer("quantize");
406  auto output = graph->AddOutputLayer(1, "output");
407 
408  input->GetOutputSlot(0).Connect(quantize->GetInputSlot(0));
409  quantize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
410 
412  input->GetOutputSlot(0).SetTensorInfo(infoIn);
413 
415  quantize->GetOutputSlot(0).SetTensorInfo(infoOut);
416 
417  Test testQuantize;
418  graph->Accept(testQuantize);
419 
420  BOOST_TEST(testQuantize.m_Visited == true);
421 
422 }
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
void VisitQuantizeLayer(const IConnectableLayer *, const char *) override
Function a quantize layer should call back to when its Accept(ILayerVisitor&) function is invoked...
DataType GetDataType() const
Definition: Tensor.hpp:194
Visitor base class with empty implementations.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const IOutputSlot * GetConnection() const =0
virtual const TensorInfo & GetTensorInfo() const =0
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual const char * GetName() const =0
Returns the name of the layer.
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:46

◆ BOOST_AUTO_TEST_CASE() [10/12]

BOOST_AUTO_TEST_CASE ( Network_AddMerge  )

Definition at line 424 of file NetworkTests.cpp.

References IOutputSlot::Connect(), INetwork::Create(), armnn::Float32, IInputSlot::GetConnection(), TensorInfo::GetDataType(), IConnectableLayer::GetInputSlot(), IConnectableLayer::GetName(), IConnectableLayer::GetNumInputSlots(), IConnectableLayer::GetNumOutputSlots(), IConnectableLayer::GetOutputSlot(), IOutputSlot::GetTensorInfo(), armnn::info, IOutputSlot::SetTensorInfo(), and LayerVisitorBase< DefaultPolicy >::VisitMergeLayer().

425 {
426  struct Test : public armnn::LayerVisitorBase<armnn::VisitorNoThrowPolicy>
427  {
428  void VisitMergeLayer(const armnn::IConnectableLayer* layer, const char* name) override
429  {
430  m_Visited = true;
431 
432  BOOST_TEST(layer);
433 
434  std::string expectedName = std::string("merge");
435  BOOST_TEST(std::string(layer->GetName()) == expectedName);
436  BOOST_TEST(std::string(name) == expectedName);
437 
438  BOOST_TEST(layer->GetNumInputSlots() == 2);
439  BOOST_TEST(layer->GetNumOutputSlots() == 1);
440 
441  const armnn::TensorInfo& infoIn0 = layer->GetInputSlot(0).GetConnection()->GetTensorInfo();
442  BOOST_TEST((infoIn0.GetDataType() == armnn::DataType::Float32));
443 
444  const armnn::TensorInfo& infoIn1 = layer->GetInputSlot(1).GetConnection()->GetTensorInfo();
445  BOOST_TEST((infoIn1.GetDataType() == armnn::DataType::Float32));
446 
447  const armnn::TensorInfo& infoOut = layer->GetOutputSlot(0).GetTensorInfo();
448  BOOST_TEST((infoOut.GetDataType() == armnn::DataType::Float32));
449  }
450 
451  bool m_Visited = false;
452  };
453 
455 
456  armnn::IConnectableLayer* input0 = network->AddInputLayer(0);
457  armnn::IConnectableLayer* input1 = network->AddInputLayer(1);
458  armnn::IConnectableLayer* merge = network->AddMergeLayer("merge");
459  armnn::IConnectableLayer* output = network->AddOutputLayer(0);
460 
461  input0->GetOutputSlot(0).Connect(merge->GetInputSlot(0));
462  input1->GetOutputSlot(0).Connect(merge->GetInputSlot(1));
463  merge->GetOutputSlot(0).Connect(output->GetInputSlot(0));
464 
466  input0->GetOutputSlot(0).SetTensorInfo(info);
467  input1->GetOutputSlot(0).SetTensorInfo(info);
468  merge->GetOutputSlot(0).SetTensorInfo(info);
469 
470  Test testMerge;
471  network->Accept(testMerge);
472 
473  BOOST_TEST(testMerge.m_Visited == true);
474 }
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
void VisitMergeLayer(const IConnectableLayer *, const char *) override
Function that a merge layer should call back to when its Accept(ILayerVisitor&) function is invoked...
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
DataType GetDataType() const
Definition: Tensor.hpp:194
Visitor base class with empty implementations.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const IOutputSlot * GetConnection() const =0
virtual const TensorInfo & GetTensorInfo() const =0
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual const char * GetName() const =0
Returns the name of the layer.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:101
virtual int Connect(IInputSlot &destination)=0
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:46

◆ BOOST_AUTO_TEST_CASE() [11/12]

BOOST_AUTO_TEST_CASE ( StandInLayerNetworkTest  )

Definition at line 476 of file NetworkTests.cpp.

References Network::AddFloorLayer(), Network::AddInputLayer(), Network::AddOutputLayer(), Network::AddStandInLayer(), IOutputSlot::Connect(), Network::GetGraph(), IConnectableLayer::GetOutputSlot(), GraphHasNamedLayer(), StandInDescriptor::m_NumInputs, and StandInDescriptor::m_NumOutputs.

477 {
478  // Create a simple network with a StandIn some place in it.
479  armnn::Network net;
480  auto input = net.AddInputLayer(0);
481 
482  // Add some valid layer.
483  auto floor = net.AddFloorLayer("Floor");
484 
485  // Add a standin layer
486  armnn::StandInDescriptor standInDescriptor;
487  standInDescriptor.m_NumInputs = 1;
488  standInDescriptor.m_NumOutputs = 1;
489  auto standIn = net.AddStandInLayer(standInDescriptor, "StandIn");
490 
491  // Finally the output.
492  auto output = net.AddOutputLayer(0);
493 
494  // Connect up the layers
495  input->GetOutputSlot(0).Connect(floor->GetInputSlot(0));
496 
497  floor->GetOutputSlot(0).Connect(standIn->GetInputSlot(0));
498 
499  standIn->GetOutputSlot(0).Connect(output->GetInputSlot(0));
500 
501  // Check that the layer is there.
502  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "StandIn"));
503  // Check that it is connected as expected.
504  BOOST_TEST(input->GetOutputSlot(0).GetConnection(0) == &floor->GetInputSlot(0));
505  BOOST_TEST(floor->GetOutputSlot(0).GetConnection(0) == &standIn->GetInputSlot(0));
506  BOOST_TEST(standIn->GetOutputSlot(0).GetConnection(0) == &output->GetInputSlot(0));
507 }
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an output layer to the network.
Definition: Network.cpp:1467
const Graph & GetGraph() const
Definition: Network.hpp:34
IConnectableLayer * AddFloorLayer(const char *name=nullptr) override
Adds a floor layer to the network.
Definition: Network.cpp:1559
bool GraphHasNamedLayer(const armnn::Graph &graph, const std::string &name)
Definition: GraphUtils.cpp:10
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an input layer to the network.
Definition: Network.cpp:1192
uint32_t m_NumOutputs
Number of output tensors.
IConnectableLayer * AddStandInLayer(const StandInDescriptor &descriptor, const char *name=nullptr) override
Add a stand-in layer for a type unknown to the Arm NN framework.
Definition: Network.cpp:1818
A StandInDescriptor for the StandIn layer.
Private implementation of INetwork.
Definition: Network.hpp:28
uint32_t m_NumInputs
Number of input tensors.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual int Connect(IInputSlot &destination)=0

◆ BOOST_AUTO_TEST_CASE() [12/12]

BOOST_AUTO_TEST_CASE ( StandInLayerSingleInputMultipleOutputsNetworkTest  )

Definition at line 509 of file NetworkTests.cpp.

References Network::AddInputLayer(), Network::AddOutputLayer(), Network::AddStandInLayer(), BOOST_AUTO_TEST_SUITE_END(), IOutputSlot::Connect(), Network::GetGraph(), IConnectableLayer::GetOutputSlot(), GraphHasNamedLayer(), StandInDescriptor::m_NumInputs, and StandInDescriptor::m_NumOutputs.

510 {
511  // Another test with one input and two outputs on the StandIn layer.
512  armnn::Network net;
513 
514  // Create the input.
515  auto input = net.AddInputLayer(0);
516 
517  // Add a standin layer
518  armnn::StandInDescriptor standInDescriptor;
519  standInDescriptor.m_NumInputs = 1;
520  standInDescriptor.m_NumOutputs = 2;
521  auto standIn = net.AddStandInLayer(standInDescriptor, "StandIn");
522 
523  // Add two outputs.
524  auto output0 = net.AddOutputLayer(0);
525  auto output1 = net.AddOutputLayer(1);
526 
527  // Connect up the layers
528  input->GetOutputSlot(0).Connect(standIn->GetInputSlot(0));
529 
530  // Connect the two outputs of the Standin to the two outputs.
531  standIn->GetOutputSlot(0).Connect(output0->GetInputSlot(0));
532  standIn->GetOutputSlot(1).Connect(output1->GetInputSlot(0));
533 
534  // Check that the layer is there.
535  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "StandIn"));
536  // Check that it is connected as expected.
537  BOOST_TEST(input->GetOutputSlot(0).GetConnection(0) == &standIn->GetInputSlot(0));
538  BOOST_TEST(standIn->GetOutputSlot(0).GetConnection(0) == &output0->GetInputSlot(0));
539  BOOST_TEST(standIn->GetOutputSlot(1).GetConnection(0) == &output1->GetInputSlot(0));
540 }
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an output layer to the network.
Definition: Network.cpp:1467
const Graph & GetGraph() const
Definition: Network.hpp:34
bool GraphHasNamedLayer(const armnn::Graph &graph, const std::string &name)
Definition: GraphUtils.cpp:10
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr) override
Adds an input layer to the network.
Definition: Network.cpp:1192
uint32_t m_NumOutputs
Number of output tensors.
IConnectableLayer * AddStandInLayer(const StandInDescriptor &descriptor, const char *name=nullptr) override
Add a stand-in layer for a type unknown to the Arm NN framework.
Definition: Network.cpp:1818
A StandInDescriptor for the StandIn layer.
Private implementation of INetwork.
Definition: Network.hpp:28
uint32_t m_NumInputs
Number of input tensors.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual int Connect(IInputSlot &destination)=0