ArmNN
 20.08
QuantizerVisitor.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "Network.hpp"
8 #include "QuantizerVisitor.hpp"
9 #include "StaticRangeVisitor.hpp"
10 
12 
13 namespace armnn
14 {
15 
17  const IQuantizationScheme* quantizationScheme,
18  bool preserveType)
19  : m_Ranges(rangeTracker)
20  , m_QuantizedNetwork(INetwork::Create())
21  , m_QuantizationScheme(quantizationScheme)
22  , m_PreserveType(preserveType)
23 {
24 }
25 
26 void QuantizerVisitor::SetQuantizedInputConnections(const IConnectableLayer* srcLayer,
27  IConnectableLayer* quantizedLayer)
28 {
29  ARMNN_ASSERT(srcLayer);
30  for (unsigned int i = 0; i < srcLayer->GetNumInputSlots(); i++)
31  {
32  const IInputSlot& srcInputSlot = srcLayer->GetInputSlot(i);
33  const InputSlot* inputSlot = PolymorphicDowncast<const InputSlot*>(&srcInputSlot);
34  ARMNN_ASSERT(inputSlot);
35  const OutputSlot* outputSlot = inputSlot->GetConnectedOutputSlot();
36 
37  ARMNN_ASSERT(outputSlot);
38  unsigned int slotIdx = outputSlot->CalculateIndexOnOwner();
39  Layer& layerToFind = outputSlot->GetOwningLayer();
40 
41  auto found = m_OriginalToQuantizedGuidMap.find(layerToFind.GetGuid());
42  if (found == m_OriginalToQuantizedGuidMap.end())
43  {
44  // Error in graph traversal order
45  ARMNN_ASSERT_MSG(false, "Error in graph traversal");
46  return;
47  }
48 
49  // Connect the slots in the quantized model
50  IConnectableLayer* prevQuantizedLayer = m_QuantizedGuidToLayerMap[found->second];
51  IInputSlot& newInputSlot = quantizedLayer->GetInputSlot(i);
52  IOutputSlot& newOutputSlot = prevQuantizedLayer->GetOutputSlot(slotIdx);
53  newOutputSlot.Connect(newInputSlot);
54 
55  // Fetch the min/max ranges that were computed earlier
56  auto range = m_Ranges.GetRange(layerToFind.GetGuid(), slotIdx);
57  OffsetScalePair qParams = m_QuantizationScheme->ComputeScheme(range.first, range.second);
58 
59  // Set the quantization params
60  TensorInfo info(outputSlot->GetTensorInfo());
61  info.SetDataType(m_QuantizationScheme->GetDataType());
62  info.SetQuantizationOffset(qParams.second);
63  info.SetQuantizationScale(qParams.first);
64  newOutputSlot.SetTensorInfo(info);
65  }
66 }
67 
68 ConstTensor QuantizerVisitor::CreateQuantizedBias(const IConnectableLayer* srcLayer,
69  const ConstTensor& weights,
70  const Optional<ConstTensor>& biases,
71  std::vector<int32_t>& backing)
72 {
73  ARMNN_ASSERT(srcLayer);
74  const IInputSlot& srcInputSlot = srcLayer->GetInputSlot(0);
75  auto inputSlot = PolymorphicDowncast<const InputSlot*>(&srcInputSlot);
76  ARMNN_ASSERT(inputSlot);
77  const OutputSlot* outputSlot = inputSlot->GetConnectedOutputSlot();
78 
79  ARMNN_ASSERT(outputSlot);
80  unsigned int slotIdx = outputSlot->CalculateIndexOnOwner();
81  Layer& layerToFind = outputSlot->GetOwningLayer();
82 
83  auto found = m_OriginalToQuantizedGuidMap.find(layerToFind.GetGuid());
84  if (found == m_OriginalToQuantizedGuidMap.end())
85  {
86  // Error in graph traversal order
87  ARMNN_ASSERT_MSG(false, "Error in graph traversal");
88  return biases.value();
89  }
90 
91  // Fetch the min/max ranges that were computed earlier
92  auto range = m_Ranges.GetRange(layerToFind.GetGuid(), slotIdx);
93  OffsetScalePair qParams = m_QuantizationScheme->ComputeScheme(range.first, range.second);
94 
95  // Get the quantization scale based on input and weight scale
96  float scale = qParams.first * weights.GetInfo().GetQuantizationScale();
97 
98  // Set up quantized bias tensor info and allocate space
99  TensorInfo qInfo(biases.value().GetInfo().GetShape(), DataType::Signed32, scale, 0);
100  backing.resize(biases.value().GetInfo().GetNumElements());
101 
102  // Convert values to int32
103  for (size_t i = 0; i < backing.size(); ++i)
104  {
105  float fp32Value = static_cast<const float*>(biases.value().GetMemoryArea())[i];
106  backing[i] = boost::numeric_cast<int32_t>(fp32Value * ( 1 / scale ));
107  }
108 
109  return ConstTensor(qInfo, backing);
110 }
111 
112 void QuantizerVisitor::RecordLayer(const IConnectableLayer* srcLayer, IConnectableLayer* quantizedLayer)
113 {
114  m_OriginalToQuantizedGuidMap.insert(std::make_pair(srcLayer->GetGuid(), quantizedLayer->GetGuid()));
115  m_QuantizedGuidToLayerMap.insert(std::make_pair(quantizedLayer->GetGuid(), quantizedLayer));
116 }
117 
118 void QuantizerVisitor::VisitAbsLayer(const IConnectableLayer* layer, const char* name)
119 {
121 }
122 
124  const ActivationDescriptor& activationDescriptor,
125  const char* name)
126 {
127  IConnectableLayer* newLayer = m_QuantizedNetwork->AddActivationLayer(activationDescriptor, name);
128  RecordLayer(layer, newLayer);
129  SetQuantizedInputConnections(layer, newLayer);
130 }
131 
132 void QuantizerVisitor::VisitAdditionLayer(const IConnectableLayer* layer, const char* name)
133 {
134  IConnectableLayer* newLayer = m_QuantizedNetwork->AddAdditionLayer(name);
135  RecordLayer(layer, newLayer);
136  SetQuantizedInputConnections(layer, newLayer);
137 }
138 
140  const ArgMinMaxDescriptor& argMinMaxDescriptor,
141  const char* name)
142 {
143  IConnectableLayer* newLayer = m_QuantizedNetwork->AddArgMinMaxLayer(argMinMaxDescriptor, name);
144  RecordLayer(layer, newLayer);
145  SetQuantizedInputConnections(layer, newLayer);
146 }
147 
149  const BatchNormalizationDescriptor& desc,
150  const ConstTensor& mean,
151  const ConstTensor& variance,
152  const ConstTensor& beta,
153  const ConstTensor& gamma,
154  const char* name)
155 {
156  std::vector<uint8_t> meanBacking;
157  ConstTensor qMean = CreateQuantizedConst(mean, meanBacking);
158 
159  std::vector<uint8_t> varianceBacking;
160  ConstTensor qVariance = CreateQuantizedConst(variance, varianceBacking);
161 
162  std::vector<uint8_t> betaBacking;
163  ConstTensor qBeta = CreateQuantizedConst(beta, betaBacking);
164 
165  std::vector<uint8_t> gammaBacking;
166  ConstTensor qGamma = CreateQuantizedConst(gamma, gammaBacking);
167 
168  IConnectableLayer* newLayer = m_QuantizedNetwork->AddBatchNormalizationLayer(desc,
169  qMean,
170  qVariance,
171  qBeta,
172  qGamma,
173  name);
174 
175  RecordLayer(layer, newLayer);
176  SetQuantizedInputConnections(layer, newLayer);
177 }
178 
180  const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor,
181  const char* name)
182 {
183  IConnectableLayer* newLayer = m_QuantizedNetwork->AddBatchToSpaceNdLayer(batchToSpaceNdDescriptor, name);
184  RecordLayer(layer, newLayer);
185  SetQuantizedInputConnections(layer, newLayer);
186 }
187 
189  const ComparisonDescriptor& comparisonDescriptor,
190  const char* name)
191 {
192  IConnectableLayer* newLayer = m_QuantizedNetwork->AddComparisonLayer(comparisonDescriptor, name);
193  RecordLayer(layer, newLayer);
194  SetQuantizedInputConnections(layer, newLayer);
195 }
196 
198  const OriginsDescriptor& originsDescriptor,
199  const char* name)
200 {
201  IConnectableLayer* newLayer = m_QuantizedNetwork->AddConcatLayer(originsDescriptor, name);
202  RecordLayer(layer, newLayer);
203  SetQuantizedInputConnections(layer, newLayer);
204 }
205 
207  const ConstTensor& input,
208  const char* name)
209 {
210  std::vector<uint8_t> inputBacking;
211  ConstTensor qInput = CreateQuantizedConst(input, inputBacking);
212 
213  IConnectableLayer* newLayer = m_QuantizedNetwork->AddConstantLayer(qInput, name);
214  RecordLayer(layer, newLayer);
215 }
216 
218  const Convolution2dDescriptor& convolution2dDescriptor,
219  const ConstTensor& weights,
220  const Optional<ConstTensor>& biases,
221  const char* name)
222 {
223  std::vector<uint8_t> weightsBacking;
224  ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking);
225  Optional<ConstTensor> optionalQBiases;
226  std::vector<int32_t> biasesBacking;
227 
228  if (biases.has_value())
229  {
230  ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
231  optionalQBiases = Optional<ConstTensor>(qBiases);
232  }
233 
234  IConnectableLayer* newLayer = m_QuantizedNetwork->AddConvolution2dLayer(convolution2dDescriptor,
235  qWeights,
236  optionalQBiases,
237  name);
238 
239  RecordLayer(layer, newLayer);
240  SetQuantizedInputConnections(layer, newLayer);
241 }
242 
244  const DepthToSpaceDescriptor& descriptor,
245  const char* name)
246 {
247  IConnectableLayer* newLayer = m_QuantizedNetwork->AddDepthToSpaceLayer(descriptor, name);
248  RecordLayer(layer, newLayer);
249  SetQuantizedInputConnections(layer, newLayer);
250 }
251 
254  const ConstTensor& weights,
255  const Optional<ConstTensor>& biases,
256  const char* name)
257 {
258  std::vector<uint8_t> weightsBacking;
259  ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking);
260  Optional<ConstTensor> optionalQBiases;
261  std::vector<int32_t> biasesBacking;
262 
263  if (biases.has_value())
264  {
265  ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
266  optionalQBiases = Optional<ConstTensor>(qBiases);
267  }
268 
269  IConnectableLayer* newLayer = m_QuantizedNetwork->AddDepthwiseConvolution2dLayer(desc,
270  qWeights,
271  optionalQBiases,
272  name);
273 
274  RecordLayer(layer, newLayer);
275  SetQuantizedInputConnections(layer, newLayer);
276 }
277 
279  const ElementwiseUnaryDescriptor& elementwiseUnaryDescriptor,
280  const char* name)
281 {
282  IConnectableLayer* newLayer = m_QuantizedNetwork->AddElementwiseUnaryLayer(elementwiseUnaryDescriptor, name);
283  RecordLayer(layer, newLayer);
284  SetQuantizedInputConnections(layer, newLayer);
285 }
286 
288  const FillDescriptor& desc,
289  const char* name)
290 {
291  IConnectableLayer* newLayer = m_QuantizedNetwork->AddFillLayer(desc, name);
292  RecordLayer(layer, newLayer);
293  SetQuantizedInputConnections(layer, newLayer);
294 }
295 
297  const FullyConnectedDescriptor& desc,
298  const ConstTensor& weights,
299  const Optional<ConstTensor>& biases,
300  const char *name)
301 {
302  std::vector<uint8_t> weightsBacking;
303  ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking);
304  Optional<ConstTensor> optionalQBiases;
305  std::vector<int32_t> biasesBacking;
306 
307  if (biases.has_value())
308  {
309  ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
310  optionalQBiases = Optional<ConstTensor>(qBiases);
311  }
312 
313  IConnectableLayer* newLayer = m_QuantizedNetwork->AddFullyConnectedLayer(desc,
314  qWeights,
315  optionalQBiases,
316  name);
317 
318  RecordLayer(layer, newLayer);
319  SetQuantizedInputConnections(layer, newLayer);
320 }
321 
323 {
324  const DataType dataType = layer->GetOutputSlot(0).GetTensorInfo().GetDataType();
325  IConnectableLayer* inputLayer = m_QuantizedNetwork->AddInputLayer(id, name);
326 
327  if (m_PreserveType && (dataType == DataType::Float32 || dataType == DataType::Float16))
328  {
329  IConnectableLayer* quantizeLayer = m_QuantizedNetwork->AddQuantizeLayer();
330  inputLayer->GetOutputSlot(0).Connect(quantizeLayer->GetInputSlot(0));
331  inputLayer->GetOutputSlot(0).SetTensorInfo(layer->GetOutputSlot(0).GetTensorInfo());
332  RecordLayer(layer, quantizeLayer);
333  }
334  else
335  {
336  RecordLayer(layer, inputLayer);
337  }
338 }
339 
341  const InstanceNormalizationDescriptor& descriptor,
342  const char* name)
343 {
344  IConnectableLayer* newLayer = m_QuantizedNetwork->AddInstanceNormalizationLayer(descriptor, name);
345  RecordLayer(layer, newLayer);
346  SetQuantizedInputConnections(layer, newLayer);
347 }
348 
350  const LogSoftmaxDescriptor& logSoftmaxDescriptor,
351  const char* name)
352 {
353  IConnectableLayer* newLayer = m_QuantizedNetwork->AddLogSoftmaxLayer(logSoftmaxDescriptor, name);
354  RecordLayer(layer, newLayer);
355  SetQuantizedInputConnections(layer, newLayer);
356 }
357 
359  const MeanDescriptor& meanDescriptor,
360  const char* name)
361 {
362  IConnectableLayer* newLayer = m_QuantizedNetwork->AddMeanLayer(meanDescriptor, name);
363  RecordLayer(layer, newLayer);
364  SetQuantizedInputConnections(layer, newLayer);
365 }
366 
368  const char* name)
369 {
370  IConnectableLayer* newLayer = m_QuantizedNetwork->AddMultiplicationLayer(name);
371  RecordLayer(layer, newLayer);
372  SetQuantizedInputConnections(layer, newLayer);
373 }
374 
376  const armnn::NormalizationDescriptor& normalizationDescriptor,
377  const char* name)
378 {
379  IConnectableLayer* newLayer = m_QuantizedNetwork->AddNormalizationLayer(normalizationDescriptor, name);
380  RecordLayer(layer, newLayer);
381  SetQuantizedInputConnections(layer, newLayer);
382 }
383 
385 {
386  const TensorInfo& info = layer->GetInputSlot(0).GetConnection()->GetTensorInfo();
387  const DataType& dataType = info.GetDataType();
388  IConnectableLayer* outputLayer = m_QuantizedNetwork->AddOutputLayer(id, name);
389 
390  if (m_PreserveType && (dataType == DataType::Float32 || dataType == DataType::Float16))
391  {
392  IConnectableLayer* dequantizeLayer = m_QuantizedNetwork->AddDequantizeLayer();
393  RecordLayer(layer, dequantizeLayer);
394  SetQuantizedInputConnections(layer, dequantizeLayer);
395  dequantizeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
396  dequantizeLayer->GetOutputSlot(0).SetTensorInfo(info);
397  }
398  else
399  {
400  RecordLayer(layer, outputLayer);
401  SetQuantizedInputConnections(layer, outputLayer);
402  }
403 }
404 
406  const PadDescriptor& padDescriptor,
407  const char* name)
408 {
409  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPadLayer(padDescriptor, name);
410  RecordLayer(layer, newLayer);
411  SetQuantizedInputConnections(layer, newLayer);
412 }
413 
415  const PermuteDescriptor& permuteDescriptor,
416  const char* name)
417 {
418  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPermuteLayer(permuteDescriptor, name);
419  RecordLayer(layer, newLayer);
420  SetQuantizedInputConnections(layer, newLayer);
421 }
422 
424  const Pooling2dDescriptor& pooling2dDescriptor,
425  const char* name)
426 {
427  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPooling2dLayer(pooling2dDescriptor, name);
428  RecordLayer(layer, newLayer);
429  SetQuantizedInputConnections(layer, newLayer);
430 }
431 
433  const char* name)
434 {
435  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPreluLayer(name);
436  RecordLayer(layer, newLayer);
437  SetQuantizedInputConnections(layer, newLayer);
438 }
439 
441  const ReshapeDescriptor& reshapeDescriptor,
442  const char* name)
443 {
444  IConnectableLayer* newLayer = m_QuantizedNetwork->AddReshapeLayer(reshapeDescriptor, name);
445  RecordLayer(layer, newLayer);
446  SetQuantizedInputConnections(layer, newLayer);
447 }
448 
450  const ResizeBilinearDescriptor& resizeBilinearDescriptor,
451  const char* name)
452 {
453  ResizeDescriptor resizeDescriptor;
454  resizeDescriptor.m_Method = ResizeMethod::Bilinear;
455  resizeDescriptor.m_TargetWidth = resizeBilinearDescriptor.m_TargetWidth;
456  resizeDescriptor.m_TargetHeight = resizeBilinearDescriptor.m_TargetHeight;
457  resizeDescriptor.m_DataLayout = resizeBilinearDescriptor.m_DataLayout;
458 
459  VisitResizeLayer(layer, resizeDescriptor, name);
460 }
461 
463  const ResizeDescriptor& resizeDescriptor,
464  const char* name)
465 {
466  IConnectableLayer* newLayer = m_QuantizedNetwork->AddResizeLayer(resizeDescriptor, name);
467  RecordLayer(layer, newLayer);
468  SetQuantizedInputConnections(layer, newLayer);
469 }
470 
471 void QuantizerVisitor::VisitRsqrtLayer(const IConnectableLayer* layer, const char* name)
472 {
474 }
475 
477  const SliceDescriptor& sliceDescriptor,
478  const char* name)
479 {
480  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSliceLayer(sliceDescriptor, name);
481  RecordLayer(layer, newLayer);
482  SetQuantizedInputConnections(layer, newLayer);
483 }
484 
486  const SoftmaxDescriptor& softmaxDescriptor,
487  const char* name)
488 {
489  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSoftmaxLayer(softmaxDescriptor, name);
490  RecordLayer(layer, newLayer);
491  SetQuantizedInputConnections(layer, newLayer);
492 }
493 
495  const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor,
496  const char* name)
497 {
498  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSpaceToBatchNdLayer(spaceToBatchNdDescriptor, name);
499  RecordLayer(layer, newLayer);
500  SetQuantizedInputConnections(layer, newLayer);
501 }
502 
504  const SpaceToDepthDescriptor& spaceToDepthDescriptor,
505  const char* name)
506 {
507  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSpaceToDepthLayer(spaceToDepthDescriptor, name);
508  RecordLayer(layer, newLayer);
509  SetQuantizedInputConnections(layer, newLayer);
510 }
511 
513  const SplitterDescriptor& splitterDescriptor,
514  const char* name)
515 {
516  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSplitterLayer(splitterDescriptor, name);
517  RecordLayer(layer, newLayer);
518  SetQuantizedInputConnections(layer, newLayer);
519 }
520 
522  const StackDescriptor& stackDescriptor,
523  const char* name)
524 {
525  IConnectableLayer* newLayer = m_QuantizedNetwork->AddStackLayer(stackDescriptor, name);
526  RecordLayer(layer, newLayer);
527  SetQuantizedInputConnections(layer, newLayer);
528 }
529 
531  const StridedSliceDescriptor& stridedSliceDescriptor,
532  const char* name)
533 {
534  IConnectableLayer* newLayer = m_QuantizedNetwork->AddStridedSliceLayer(stridedSliceDescriptor, name);
535  RecordLayer(layer, newLayer);
536  SetQuantizedInputConnections(layer, newLayer);
537 }
538 
540  const char* name)
541 {
542  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSubtractionLayer(name);
543  RecordLayer(layer, newLayer);
544  SetQuantizedInputConnections(layer, newLayer);
545 }
546 
548  const TransposeConvolution2dDescriptor& descriptor,
549  const ConstTensor& weights,
550  const Optional<ConstTensor>& biases,
551  const char* name)
552 {
553  // quantize weights
554  std::vector<uint8_t> weightsBacking;
555  ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking);
556 
557  // quantize biases
558  std::vector<int32_t> biasesBacking;
559  Optional<ConstTensor> optionalQBiases;
560  if (biases.has_value())
561  {
562  ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
563  optionalQBiases = Optional<ConstTensor>(qBiases);
564  }
565 
566  IConnectableLayer* newLayer = m_QuantizedNetwork->AddTransposeConvolution2dLayer(descriptor,
567  qWeights,
568  optionalQBiases,
569  name);
570 
571  RecordLayer(layer, newLayer);
572  SetQuantizedInputConnections(layer, newLayer);
573 }
574 
576  const TransposeDescriptor& transposeDescriptor,
577  const char* name)
578 {
579  IConnectableLayer* newLayer = m_QuantizedNetwork->AddTransposeLayer(transposeDescriptor, name);
580  RecordLayer(layer, newLayer);
581  SetQuantizedInputConnections(layer, newLayer);
582 }
583 
584 } //namespace armnn
void VisitInputLayer(const IConnectableLayer *layer, LayerBindingId id, const char *name=nullptr) override
Function that an InputLayer should call back to when its Accept(ILayerVisitor&) function is invoked...
std::pair< float, int > OffsetScalePair
void VisitTransposeConvolution2dLayer(const IConnectableLayer *layer, const TransposeConvolution2dDescriptor &descriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr) override
Function that a 2D transpose convolution layer should call back to when its Accept(ILayerVisitor&) fu...
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
QuantizerVisitor(const RangeTracker &rangeTracker, const IQuantizationScheme *quantizationScheme, bool preserveType=false)
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
void VisitRsqrtLayer(const IConnectableLayer *, const char *name=nullptr) override
Function a Reciprocal of square root layer should call back to when its Accept(ILayerVisitor&) functi...
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
A ReshapeDescriptor for the ReshapeLayer.
void VisitPadLayer(const IConnectableLayer *, const PadDescriptor &, const char *name=nullptr) override
Function a pad layer should call back to when its Accept(ILayerVisitor&) function is invoked...
void VisitMultiplicationLayer(const IConnectableLayer *layer, const char *name=nullptr) override
Function that a multiplication layer should call back to when its Accept(ILayerVisitor&) function is ...
A ComparisonDescriptor for the ComparisonLayer.
Definition: Descriptors.hpp:70
uint32_t m_TargetWidth
Target width value.
void VisitInstanceNormalizationLayer(const IConnectableLayer *layer, const InstanceNormalizationDescriptor &instanceNormalizationDescriptor, const char *name=nullptr) override
Function that an instance normalization layer should call back to when its Accept(ILayerVisitor&) fun...
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
A Convolution2dDescriptor for the Convolution2dLayer.
Layer & GetOwningLayer() const
Definition: Layer.hpp:115
void VisitReshapeLayer(const IConnectableLayer *layer, const ReshapeDescriptor &reshapeDescriptor, const char *name=nullptr) override
Function a reshape layer should call back to when its Accept(ILayerVisitor&) function is invoked...
ResizeMethod m_Method
The Interpolation method to use (Bilinear, NearestNeighbor).
void VisitAdditionLayer(const IConnectableLayer *layer, const char *name=nullptr) override
Function that an addition layer should call back to when its Accept(ILayerVisitor&) function is invok...
void VisitLogSoftmaxLayer(const IConnectableLayer *layer, const LogSoftmaxDescriptor &logSoftmaxDescriptor, const char *name=nullptr) override
Function that a log softmax layer should call back to when its Accept(ILayerVisitor&) function is inv...
Main network class which provides the interface for building up a neural network. ...
Definition: INetwork.hpp:105
void VisitResizeBilinearLayer(const IConnectableLayer *layer, const ResizeBilinearDescriptor &resizeDesc, const char *name=nullptr) override
Function that a resize bilinear layer should call back to when its Accept(ILayerVisitor&) function is...
void VisitStridedSliceLayer(const IConnectableLayer *layer, const StridedSliceDescriptor &stridedSliceDescriptor, const char *name=nullptr) override
Function a strided slice layer should call back to when its Accept(ILayerVisitor&) function is invoke...
Copyright (c) 2020 ARM Limited.
void VisitStackLayer(const IConnectableLayer *layer, const StackDescriptor &stackDescriptor, const char *name=nullptr) override
Function a stack layer should call back to when its Accept(ILayerVisitor&) function is invoked...
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
virtual OffsetScalePair ComputeScheme(double min, double max) const =0
void VisitBatchNormalizationLayer(const IConnectableLayer *layer, const BatchNormalizationDescriptor &desc, const ConstTensor &mean, const ConstTensor &variance, const ConstTensor &beta, const ConstTensor &gamma, const char *name=nullptr) override
Function that a batch normalization layer should call back to when its Accept(ILayerVisitor&) functio...
void VisitSubtractionLayer(const IConnectableLayer *layer, const char *name=nullptr) override
Function a subtraction layer should call back to when its Accept(ILayerVisitor&) function is invoked...
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:194
void VisitSpaceToBatchNdLayer(const IConnectableLayer *layer, const SpaceToBatchNdDescriptor &spaceToBatchNdDescriptor, const char *name=nullptr) override
Function a space to batch layer should call back to when its Accept(ILayerVisitor&) function is invok...
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
void VisitAbsLayer(const IConnectableLayer *layer, const char *name=nullptr) override
Functions to quantize the individual layers, overridden from ILayerVisitor.
A ResizeDescriptor for the ResizeLayer.
MinMaxRange GetRange(LayerGuid guid, unsigned int idx) const
Retrieve the Range for a particular output slot on a particular layer.
A StackDescriptor for the StackLayer.
void VisitDepthwiseConvolution2dLayer(const IConnectableLayer *layer, const DepthwiseConvolution2dDescriptor &desc, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr) override
Function that a 2D depthwise convolution layer with biases should call back to when its Accept(ILayer...
void VisitResizeLayer(const IConnectableLayer *layer, const ResizeDescriptor &resizeDescriptor, const char *name=nullptr) override
Function that a resize layer should call back to when its Accept(ILayerVisitor&) function is invoked...
A PadDescriptor for the PadLayer.
DataType
Definition: Types.hpp:32
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
An output connection slot for a layer.
Definition: INetwork.hpp:37
An ArgMinMaxDescriptor for ArgMinMaxLayer.
Definition: Descriptors.hpp:51
float GetQuantizationScale() const
Definition: Tensor.cpp:453
DataType GetDataType() const
Definition: Tensor.hpp:194
An OriginsDescriptor for the ConcatLayer.
bool has_value() const noexcept
Definition: Optional.hpp:53
A FullyConnectedDescriptor for the FullyConnectedLayer.
virtual LayerGuid GetGuid() const =0
Returns the unique id of the layer.
void VisitTransposeLayer(const IConnectableLayer *layer, const TransposeDescriptor &descriptor, const char *name=nullptr) override
Function that a transpose layer should call back to when its Accept(ILayerVisitor&) function is invok...
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:298
void VisitDepthToSpaceLayer(const IConnectableLayer *layer, const DepthToSpaceDescriptor &depthToSpaceDescriptor, const char *name=nullptr) override
Function a depth to space layer should call back to when its Accept(ILayerVisitor&) function is invok...
uint32_t m_TargetWidth
Target width value.
void VisitConcatLayer(const IConnectableLayer *layer, const OriginsDescriptor &originsDescriptor, const char *name=nullptr) override
Function that a concat layer should call back to when its Accept(ILayerVisitor&) function is invoked...
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
const OutputSlot * GetConnectedOutputSlot() const
Definition: Layer.hpp:55
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:33
void VisitConvolution2dLayer(const IConnectableLayer *layer, const Convolution2dDescriptor &convolution2dDescriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr) override
Function that a 2D convolution layer should call back to when its Accept(ILayerVisitor&) function is ...
void VisitPermuteLayer(const IConnectableLayer *layer, const PermuteDescriptor &permuteDescriptor, const char *name=nullptr) override
Function that a permute layer should call back to when its Accept(ILayerVisitor&) function is invoked...
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:20
const TensorInfo & GetInfo() const
Definition: Tensor.hpp:266
uint32_t m_TargetHeight
Target height value.
uint32_t m_TargetHeight
Target height value.
A SliceDescriptor for the SliceLayer.
void VisitFillLayer(const IConnectableLayer *layer, const FillDescriptor &desc, const char *name) override
Function a fill layer should call back to when its Accept(ILayerVisitor&) function is invoked...
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
void VisitActivationLayer(const IConnectableLayer *layer, const ActivationDescriptor &activationDescriptor, const char *name=nullptr) override
Function that an activation layer should call back to when its Accept(ILayerVisitor&) function is inv...
void VisitComparisonLayer(const IConnectableLayer *layer, const ComparisonDescriptor &comparisonDescriptor, const char *name=nullptr) override
Function a Comparison layer should call back to when its Accept(ILayerVisitor&) function is invoked...
virtual DataType GetDataType() const =0
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
Definition: Descriptors.hpp:90
void VisitSoftmaxLayer(const IConnectableLayer *layer, const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr) override
Function that a softmax layer should call back to when its Accept(ILayerVisitor&) function is invoked...
void VisitMeanLayer(const IConnectableLayer *layer, const MeanDescriptor &meanDescriptor, const char *name=nullptr) override
Function a Mean layer should call back to when its Accept(ILayerVisitor&) function is invoked...
void VisitArgMinMaxLayer(const IConnectableLayer *layer, const ArgMinMaxDescriptor &argMinMaxDescriptor, const char *name=nullptr) override
Function that an arg min max layer should call back to when its Accept(ILayerVisitor&) function is in...
void VisitElementwiseUnaryLayer(const IConnectableLayer *layer, const ElementwiseUnaryDescriptor &elementwiseUnaryDescriptor, const char *name=nullptr) override
Function a ElementwiseUnary layer should call back to when its Accept(ILayerVisitor&) function is inv...
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
A MeanDescriptor for the MeanLayer.
virtual const IOutputSlot * GetConnection() const =0
A TransposeDescriptor for the TransposeLayer.
A StridedSliceDescriptor for the StridedSliceLayer.
void VisitConstantLayer(const IConnectableLayer *layer, const ConstTensor &input, const char *name=nullptr) override
Function a layer with no inputs and a single output, which always corresponds to the passed in consta...
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 int Connect(IInputSlot &destination)=0
void VisitSpaceToDepthLayer(const IConnectableLayer *layer, const SpaceToDepthDescriptor &spaceToDepthDescriptor, const char *name=nullptr) override
Function a space to depth layer should call back to when its Accept(ILayerVisitor&) function is invok...
void VisitBatchToSpaceNdLayer(const IConnectableLayer *layer, const BatchToSpaceNdDescriptor &batchToSpaceNdDescriptor, const char *name=nullptr) override
Function that a batch to space ND layer should call back to when its Accept(ILayerVisitor&) function ...
A Pooling2dDescriptor for the Pooling2dLayer.
ConstTensor CreateQuantizedConst(const ConstTensor &tensor, std::vector< uint8_t > &backing)
A NormalizationDescriptor for the NormalizationLayer.
void VisitSliceLayer(const IConnectableLayer *layer, const SliceDescriptor &sliceDescriptor, const char *name=nullptr) override
Function that a slice layer should call back to when its Accept(ILayerVisitor&) function is invoked...
void VisitOutputLayer(const IConnectableLayer *layer, LayerBindingId id, const char *name=nullptr) override
Function an output layer should call back to when its Accept(ILayerVisitor&) function is invoked...
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
A ResizeBilinearDescriptor for the ResizeBilinearLayer.
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:63
A SoftmaxDescriptor for the SoftmaxLayer.
void VisitPreluLayer(const IConnectableLayer *layer, const char *name=nullptr) override
Function that a PReLU activation layer should call back to when its Accept(ILayerVisitor&) function i...
void VisitNormalizationLayer(const IConnectableLayer *layer, const NormalizationDescriptor &normalizationDescriptor, const char *name=nullptr) override
Function that a normalization layer should call back to when its Accept(ILayerVisitor&) function is i...
An input connection slot for a layer.
Definition: INetwork.hpp:24
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A FillDescriptor for the FillLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
void VisitPooling2dLayer(const IConnectableLayer *layer, const Pooling2dDescriptor &pooling2dDescriptor, const char *name=nullptr) override
Function that a pooling layer should call back to when its Accept(ILayerVisitor&) function is invoked...
A PermuteDescriptor for the PermuteLayer.
void VisitFullyConnectedLayer(const IConnectableLayer *layer, const FullyConnectedDescriptor &desc, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr) override
Function that a fully connected layer should call back to when its Accept(ILayerVisitor&) function is...
void VisitSplitterLayer(const IConnectableLayer *layer, const SplitterDescriptor &splitterDescriptor, const char *name=nullptr) override
Function that a splitter layer should call back to when its Accept(ILayerVisitor&) function is invoke...
LayerGuid GetGuid() const final
Returns the unique id of the layer.
Definition: Layer.hpp:318
unsigned int CalculateIndexOnOwner() const override
Definition: Layer.cpp:130