ArmNN
 21.05
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 NetworkImpl::AddAdditionLayer(), NetworkImpl::AddInputLayer(), NetworkImpl::AddOutputLayer(), and IConnectableLayer::GetGuid().

33 {
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 * AddAdditionLayer(const char *name=nullptr)
Definition: Network.cpp:2037
Private implementation of INetwork.
Definition: Network.hpp:31
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:1749
virtual LayerGuid GetGuid() const =0
Returns the unique id of the layer.
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:2047

◆ BOOST_AUTO_TEST_CASE() [2/12]

BOOST_AUTO_TEST_CASE ( NetworkBasic  )

Definition at line 44 of file NetworkTests.cpp.

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

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

◆ BOOST_AUTO_TEST_CASE() [3/12]

BOOST_AUTO_TEST_CASE ( LayerNamesAreOptionalForINetwork  )

Definition at line 50 of file NetworkTests.cpp.

References INetwork::Create().

51 {
53  inet->AddInputLayer(0);
54  inet->AddAdditionLayer();
55  inet->AddActivationLayer(armnn::ActivationDescriptor());
56  inet->AddOutputLayer(0);
57 }
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:25
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:173
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:529

◆ BOOST_AUTO_TEST_CASE() [4/12]

BOOST_AUTO_TEST_CASE ( LayerNamesAreOptionalForNetwork  )

Definition at line 59 of file NetworkTests.cpp.

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

60 {
62  net.AddInputLayer(0);
63  net.AddAdditionLayer();
65  net.AddOutputLayer(0);
66 }
IConnectableLayer * AddAdditionLayer(const char *name=nullptr)
Definition: Network.cpp:2037
IConnectableLayer * AddActivationLayer(const ActivationDescriptor &activationDescriptor, const char *name=nullptr)
Definition: Network.cpp:1980
Private implementation of INetwork.
Definition: Network.hpp:31
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:1749
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:2047
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:25

◆ BOOST_AUTO_TEST_CASE() [5/12]

BOOST_AUTO_TEST_CASE ( NetworkModification  )

Definition at line 68 of file NetworkTests.cpp.

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

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

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

229 {
230  armnn::NetworkImpl net;
231 
232  // Adds an input layer and an input tensor descriptor.
233  armnn::IConnectableLayer* inputLayer = net.AddInputLayer(0, "input layer");
234  BOOST_TEST(inputLayer);
235 
236  // Adds a splitter layer.
237  armnn::ViewsDescriptor splitterDesc(2,4);
238 
239  armnn::IConnectableLayer* splitterLayer = net.AddSplitterLayer(splitterDesc, "splitter layer");
240  BOOST_TEST(splitterLayer);
241 
242  inputLayer->GetOutputSlot(0).Connect(splitterLayer->GetInputSlot(0));
243 
244  // Adds a softmax layer 1.
245  armnn::SoftmaxDescriptor softmaxDescriptor;
246  armnn::IConnectableLayer* softmaxLayer1 = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_1");
247  BOOST_TEST(softmaxLayer1);
248 
249  splitterLayer->GetOutputSlot(0).Connect(softmaxLayer1->GetInputSlot(0));
250 
251  // Adds a softmax layer 2.
252  armnn::IConnectableLayer* softmaxLayer2 = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_2");
253  BOOST_TEST(softmaxLayer2);
254 
255  splitterLayer->GetOutputSlot(1).Connect(softmaxLayer2->GetInputSlot(0));
256 
257  // Adds a concat layer.
258  armnn::OriginsDescriptor concatDesc(2, 4);
259 
260  armnn::IConnectableLayer* concatLayer = net.AddConcatLayer(concatDesc, "concat layer");
261  BOOST_TEST(concatLayer);
262 
263  softmaxLayer1->GetOutputSlot(0).Connect(concatLayer->GetInputSlot(0));
264  softmaxLayer2->GetOutputSlot(0).Connect(concatLayer->GetInputSlot(1));
265 
266  // Adds an output layer.
267  armnn::IConnectableLayer* outputLayer = net.AddOutputLayer(0, "output layer");
268  BOOST_TEST(outputLayer);
269 
270  concatLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
271 
272  BOOST_TEST(splitterLayer->GetNumOutputSlots() == 2);
273  BOOST_TEST(splitterLayer->GetOutputSlot(0).GetConnection(0) == &softmaxLayer1->GetInputSlot(0));
274  BOOST_TEST(&splitterLayer->GetOutputSlot(0) == softmaxLayer1->GetInputSlot(0).GetConnection());
275  BOOST_TEST(splitterLayer->GetOutputSlot(1).GetConnection(0) == &softmaxLayer2->GetInputSlot(0));
276  BOOST_TEST(&splitterLayer->GetOutputSlot(1) == softmaxLayer2->GetInputSlot(0).GetConnection());
277 
278  BOOST_TEST(concatLayer->GetNumInputSlots() == 2);
279  BOOST_TEST(softmaxLayer1->GetOutputSlot(0).GetConnection(0) == &concatLayer->GetInputSlot(0));
280  BOOST_TEST(&softmaxLayer1->GetOutputSlot(0) == concatLayer->GetInputSlot(0).GetConnection());
281  BOOST_TEST(softmaxLayer2->GetOutputSlot(0).GetConnection(0) == &concatLayer->GetInputSlot(1));
282  BOOST_TEST(&softmaxLayer2->GetOutputSlot(0) == concatLayer->GetInputSlot(1).GetConnection());
283 }
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:62
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
virtual const IInputSlot * GetConnection(unsigned int index) const =0
Private implementation of INetwork.
Definition: Network.hpp:31
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:1749
An OriginsDescriptor for the ConcatLayer.
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:2047
IConnectableLayer * AddConcatLayer(const ConcatDescriptor &concatDescriptor, const char *name=nullptr)
Definition: Network.cpp:1848
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr)
Definition: Network.cpp:2004
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 * AddSplitterLayer(const ViewsDescriptor &splitterDescriptor, const char *name=nullptr)
Definition: Network.cpp:2010
A SoftmaxDescriptor for the SoftmaxLayer.

◆ BOOST_AUTO_TEST_CASE() [7/12]

BOOST_AUTO_TEST_CASE ( NetworkModification_SplitterAddition  )

Definition at line 285 of file NetworkTests.cpp.

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

286 {
287  armnn::NetworkImpl net;
288 
289  // Adds an input layer and an input tensor descriptor.
290  armnn::IConnectableLayer* layer = net.AddInputLayer(0, "input layer");
291  BOOST_TEST(layer);
292 
293  // Adds a splitter layer.
294  armnn::ViewsDescriptor splitterDesc(2,4);
295 
296  armnn::IConnectableLayer* const splitterLayer = net.AddSplitterLayer(splitterDesc, "splitter layer");
297  BOOST_TEST(splitterLayer);
298 
299  layer->GetOutputSlot(0).Connect(splitterLayer->GetInputSlot(0));
300 
301  // Adds a softmax layer 1.
302  armnn::SoftmaxDescriptor softmaxDescriptor;
303  armnn::IConnectableLayer* const softmax1Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_1");
304  BOOST_TEST(softmax1Layer);
305 
306  splitterLayer->GetOutputSlot(0).Connect(softmax1Layer->GetInputSlot(0));
307 
308  // Adds a softmax layer 2.
309  armnn::IConnectableLayer* const softmax2Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_2");
310  BOOST_TEST(softmax2Layer);
311 
312  splitterLayer->GetOutputSlot(1).Connect(softmax2Layer->GetInputSlot(0));
313 
314  // Adds addition layer.
315  layer = net.AddAdditionLayer("add layer");
316  BOOST_TEST(layer);
317 
318  softmax1Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
319  softmax2Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
320 
321  // Adds an output layer.
322  armnn::IConnectableLayer* prevLayer = layer;
323  layer = net.AddOutputLayer(0, "output layer");
324 
325  prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
326 
327  BOOST_TEST(layer);
328 }
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:62
IConnectableLayer * AddAdditionLayer(const char *name=nullptr)
Definition: Network.cpp:2037
Private implementation of INetwork.
Definition: Network.hpp:31
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:1749
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:2047
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr)
Definition: Network.cpp:2004
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 * AddSplitterLayer(const ViewsDescriptor &splitterDescriptor, const char *name=nullptr)
Definition: Network.cpp:2010
A SoftmaxDescriptor for the SoftmaxLayer.

◆ BOOST_AUTO_TEST_CASE() [8/12]

BOOST_AUTO_TEST_CASE ( NetworkModification_SplitterMultiplication  )

Definition at line 330 of file NetworkTests.cpp.

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

331 {
332  armnn::NetworkImpl net;
333 
334  // Adds an input layer and an input tensor descriptor.
335  armnn::IConnectableLayer* layer = net.AddInputLayer(0, "input layer");
336  BOOST_TEST(layer);
337 
338  // Adds a splitter layer.
339  armnn::ViewsDescriptor splitterDesc(2,4);
340  armnn::IConnectableLayer* const splitterLayer = net.AddSplitterLayer(splitterDesc, "splitter layer");
341  BOOST_TEST(splitterLayer);
342 
343  layer->GetOutputSlot(0).Connect(splitterLayer->GetInputSlot(0));
344 
345  // Adds a softmax layer 1.
346  armnn::SoftmaxDescriptor softmaxDescriptor;
347  armnn::IConnectableLayer* const softmax1Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_1");
348  BOOST_TEST(softmax1Layer);
349 
350  splitterLayer->GetOutputSlot(0).Connect(softmax1Layer->GetInputSlot(0));
351 
352  // Adds a softmax layer 2.
353  armnn::IConnectableLayer* const softmax2Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_2");
354  BOOST_TEST(softmax2Layer);
355 
356  splitterLayer->GetOutputSlot(1).Connect(softmax2Layer->GetInputSlot(0));
357 
358  // Adds multiplication layer.
359  layer = net.AddMultiplicationLayer("multiplication layer");
360  BOOST_TEST(layer);
361 
362  softmax1Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
363  softmax2Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
364 
365  // Adds an output layer.
366  armnn::IConnectableLayer* prevLayer = layer;
367  layer = net.AddOutputLayer(0, "output layer");
368  BOOST_TEST(layer);
369 
370  prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
371 }
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:62
Private implementation of INetwork.
Definition: Network.hpp:31
IConnectableLayer * AddMultiplicationLayer(const char *name=nullptr)
Definition: Network.cpp:2042
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:1749
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:2047
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr)
Definition: Network.cpp:2004
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 * AddSplitterLayer(const ViewsDescriptor &splitterDescriptor, const char *name=nullptr)
Definition: Network.cpp:2010
A SoftmaxDescriptor for the SoftmaxLayer.

◆ BOOST_AUTO_TEST_CASE() [9/12]

BOOST_AUTO_TEST_CASE ( Network_AddQuantize  )

Definition at line 373 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().

374 {
375  struct Test : public armnn::LayerVisitorBase<armnn::VisitorNoThrowPolicy>
376  {
377  void VisitQuantizeLayer(const armnn::IConnectableLayer* layer, const char* name) override
378  {
379  m_Visited = true;
380 
381  BOOST_TEST(layer);
382 
383  std::string expectedName = std::string("quantize");
384  BOOST_TEST(std::string(layer->GetName()) == expectedName);
385  BOOST_TEST(std::string(name) == expectedName);
386 
387  BOOST_TEST(layer->GetNumInputSlots() == 1);
388  BOOST_TEST(layer->GetNumOutputSlots() == 1);
389 
390  const armnn::TensorInfo& infoIn = layer->GetInputSlot(0).GetConnection()->GetTensorInfo();
391  BOOST_TEST((infoIn.GetDataType() == armnn::DataType::Float32));
392 
393  const armnn::TensorInfo& infoOut = layer->GetOutputSlot(0).GetTensorInfo();
394  BOOST_TEST((infoOut.GetDataType() == armnn::DataType::QAsymmU8));
395  }
396 
397  bool m_Visited = false;
398  };
399 
400 
401  auto graph = armnn::INetwork::Create();
402 
403  auto input = graph->AddInputLayer(0, "input");
404  auto quantize = graph->AddQuantizeLayer("quantize");
405  auto output = graph->AddOutputLayer(1, "output");
406 
407  input->GetOutputSlot(0).Connect(quantize->GetInputSlot(0));
408  quantize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
409 
411  input->GetOutputSlot(0).SetTensorInfo(infoIn);
412 
414  quantize->GetOutputSlot(0).SetTensorInfo(infoOut);
415 
416  Test testQuantize;
417  graph->Accept(testQuantize);
418 
419  BOOST_TEST(testQuantize.m_Visited == true);
420 
421 }
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:62
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:529

◆ BOOST_AUTO_TEST_CASE() [10/12]

BOOST_AUTO_TEST_CASE ( Network_AddMerge  )

Definition at line 423 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().

424 {
425  struct Test : public armnn::LayerVisitorBase<armnn::VisitorNoThrowPolicy>
426  {
427  void VisitMergeLayer(const armnn::IConnectableLayer* layer, const char* name) override
428  {
429  m_Visited = true;
430 
431  BOOST_TEST(layer);
432 
433  std::string expectedName = std::string("merge");
434  BOOST_TEST(std::string(layer->GetName()) == expectedName);
435  BOOST_TEST(std::string(name) == expectedName);
436 
437  BOOST_TEST(layer->GetNumInputSlots() == 2);
438  BOOST_TEST(layer->GetNumOutputSlots() == 1);
439 
440  const armnn::TensorInfo& infoIn0 = layer->GetInputSlot(0).GetConnection()->GetTensorInfo();
441  BOOST_TEST((infoIn0.GetDataType() == armnn::DataType::Float32));
442 
443  const armnn::TensorInfo& infoIn1 = layer->GetInputSlot(1).GetConnection()->GetTensorInfo();
444  BOOST_TEST((infoIn1.GetDataType() == armnn::DataType::Float32));
445 
446  const armnn::TensorInfo& infoOut = layer->GetOutputSlot(0).GetTensorInfo();
447  BOOST_TEST((infoOut.GetDataType() == armnn::DataType::Float32));
448  }
449 
450  bool m_Visited = false;
451  };
452 
454 
455  armnn::IConnectableLayer* input0 = network->AddInputLayer(0);
456  armnn::IConnectableLayer* input1 = network->AddInputLayer(1);
457  armnn::IConnectableLayer* merge = network->AddMergeLayer("merge");
458  armnn::IConnectableLayer* output = network->AddOutputLayer(0);
459 
460  input0->GetOutputSlot(0).Connect(merge->GetInputSlot(0));
461  input1->GetOutputSlot(0).Connect(merge->GetInputSlot(1));
462  merge->GetOutputSlot(0).Connect(output->GetInputSlot(0));
463 
465  input0->GetOutputSlot(0).SetTensorInfo(info);
466  input1->GetOutputSlot(0).SetTensorInfo(info);
467  merge->GetOutputSlot(0).SetTensorInfo(info);
468 
469  Test testMerge;
470  network->Accept(testMerge);
471 
472  BOOST_TEST(testMerge.m_Visited == true);
473 }
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:62
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:173
virtual int Connect(IInputSlot &destination)=0
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:529

◆ BOOST_AUTO_TEST_CASE() [11/12]

BOOST_AUTO_TEST_CASE ( StandInLayerNetworkTest  )

Definition at line 475 of file NetworkTests.cpp.

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

476 {
477  // Create a simple network with a StandIn some place in it.
478  armnn::NetworkImpl net;
479  auto input = net.AddInputLayer(0);
480 
481  // Add some valid layer.
482  auto floor = net.AddFloorLayer("Floor");
483 
484  // Add a standin layer
485  armnn::StandInDescriptor standInDescriptor;
486  standInDescriptor.m_NumInputs = 1;
487  standInDescriptor.m_NumOutputs = 1;
488  auto standIn = net.AddStandInLayer(standInDescriptor, "StandIn");
489 
490  // Finally the output.
491  auto output = net.AddOutputLayer(0);
492 
493  // Connect up the layers
494  input->GetOutputSlot(0).Connect(floor->GetInputSlot(0));
495 
496  floor->GetOutputSlot(0).Connect(standIn->GetInputSlot(0));
497 
498  standIn->GetOutputSlot(0).Connect(output->GetInputSlot(0));
499 
500  // Check that the layer is there.
501  BOOST_TEST(GraphHasNamedLayer(net.GetGraph(), "StandIn"));
502  // Check that it is connected as expected.
503  BOOST_TEST(input->GetOutputSlot(0).GetConnection(0) == &floor->GetInputSlot(0));
504  BOOST_TEST(floor->GetOutputSlot(0).GetConnection(0) == &standIn->GetInputSlot(0));
505  BOOST_TEST(standIn->GetOutputSlot(0).GetConnection(0) == &output->GetInputSlot(0));
506 }
bool GraphHasNamedLayer(const armnn::Graph &graph, const std::string &name)
Definition: GraphUtils.cpp:10
Private implementation of INetwork.
Definition: Network.hpp:31
uint32_t m_NumOutputs
Number of output tensors.
IConnectableLayer * AddFloorLayer(const char *name=nullptr)
Definition: Network.cpp:2144
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:1749
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)
Definition: Network.cpp:2047
A StandInDescriptor for the StandIn layer.
IConnectableLayer * AddStandInLayer(const StandInDescriptor &descriptor, const char *name=nullptr)
Definition: Network.cpp:2403
uint32_t m_NumInputs
Number of input tensors.
const Graph & GetGraph() const
Definition: Network.hpp:37
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 508 of file NetworkTests.cpp.

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

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