ArmNN
 20.05
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 FullyConnectedDescriptor& desc,
289  const ConstTensor& weights,
290  const Optional<ConstTensor>& biases,
291  const char *name)
292 {
293  std::vector<uint8_t> weightsBacking;
294  ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking);
295  Optional<ConstTensor> optionalQBiases;
296  std::vector<int32_t> biasesBacking;
297 
298  if (biases.has_value())
299  {
300  ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
301  optionalQBiases = Optional<ConstTensor>(qBiases);
302  }
303 
304  IConnectableLayer* newLayer = m_QuantizedNetwork->AddFullyConnectedLayer(desc,
305  qWeights,
306  optionalQBiases,
307  name);
308 
309  RecordLayer(layer, newLayer);
310  SetQuantizedInputConnections(layer, newLayer);
311 }
312 
314 {
315  const DataType dataType = layer->GetOutputSlot(0).GetTensorInfo().GetDataType();
316  IConnectableLayer* inputLayer = m_QuantizedNetwork->AddInputLayer(id, name);
317 
318  if (m_PreserveType && (dataType == DataType::Float32 || dataType == DataType::Float16))
319  {
320  IConnectableLayer* quantizeLayer = m_QuantizedNetwork->AddQuantizeLayer();
321  inputLayer->GetOutputSlot(0).Connect(quantizeLayer->GetInputSlot(0));
322  inputLayer->GetOutputSlot(0).SetTensorInfo(layer->GetOutputSlot(0).GetTensorInfo());
323  RecordLayer(layer, quantizeLayer);
324  }
325  else
326  {
327  RecordLayer(layer, inputLayer);
328  }
329 }
330 
332  const InstanceNormalizationDescriptor& descriptor,
333  const char* name)
334 {
335  IConnectableLayer* newLayer = m_QuantizedNetwork->AddInstanceNormalizationLayer(descriptor, name);
336  RecordLayer(layer, newLayer);
337  SetQuantizedInputConnections(layer, newLayer);
338 }
339 
341  const LogSoftmaxDescriptor& logSoftmaxDescriptor,
342  const char* name)
343 {
344  IConnectableLayer* newLayer = m_QuantizedNetwork->AddLogSoftmaxLayer(logSoftmaxDescriptor, name);
345  RecordLayer(layer, newLayer);
346  SetQuantizedInputConnections(layer, newLayer);
347 }
348 
350  const MeanDescriptor& meanDescriptor,
351  const char* name)
352 {
353  IConnectableLayer* newLayer = m_QuantizedNetwork->AddMeanLayer(meanDescriptor, name);
354  RecordLayer(layer, newLayer);
355  SetQuantizedInputConnections(layer, newLayer);
356 }
357 
359  const char* name)
360 {
361  IConnectableLayer* newLayer = m_QuantizedNetwork->AddMultiplicationLayer(name);
362  RecordLayer(layer, newLayer);
363  SetQuantizedInputConnections(layer, newLayer);
364 }
365 
367  const armnn::NormalizationDescriptor& normalizationDescriptor,
368  const char* name)
369 {
370  IConnectableLayer* newLayer = m_QuantizedNetwork->AddNormalizationLayer(normalizationDescriptor, name);
371  RecordLayer(layer, newLayer);
372  SetQuantizedInputConnections(layer, newLayer);
373 }
374 
376 {
377  const TensorInfo& info = layer->GetInputSlot(0).GetConnection()->GetTensorInfo();
378  const DataType& dataType = info.GetDataType();
379  IConnectableLayer* outputLayer = m_QuantizedNetwork->AddOutputLayer(id, name);
380 
381  if (m_PreserveType && (dataType == DataType::Float32 || dataType == DataType::Float16))
382  {
383  IConnectableLayer* dequantizeLayer = m_QuantizedNetwork->AddDequantizeLayer();
384  RecordLayer(layer, dequantizeLayer);
385  SetQuantizedInputConnections(layer, dequantizeLayer);
386  dequantizeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
387  dequantizeLayer->GetOutputSlot(0).SetTensorInfo(info);
388  }
389  else
390  {
391  RecordLayer(layer, outputLayer);
392  SetQuantizedInputConnections(layer, outputLayer);
393  }
394 }
395 
397  const PadDescriptor& padDescriptor,
398  const char* name)
399 {
400  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPadLayer(padDescriptor, name);
401  RecordLayer(layer, newLayer);
402  SetQuantizedInputConnections(layer, newLayer);
403 }
404 
406  const PermuteDescriptor& permuteDescriptor,
407  const char* name)
408 {
409  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPermuteLayer(permuteDescriptor, name);
410  RecordLayer(layer, newLayer);
411  SetQuantizedInputConnections(layer, newLayer);
412 }
413 
415  const Pooling2dDescriptor& pooling2dDescriptor,
416  const char* name)
417 {
418  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPooling2dLayer(pooling2dDescriptor, name);
419  RecordLayer(layer, newLayer);
420  SetQuantizedInputConnections(layer, newLayer);
421 }
422 
424  const char* name)
425 {
426  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPreluLayer(name);
427  RecordLayer(layer, newLayer);
428  SetQuantizedInputConnections(layer, newLayer);
429 }
430 
432  const ReshapeDescriptor& reshapeDescriptor,
433  const char* name)
434 {
435  IConnectableLayer* newLayer = m_QuantizedNetwork->AddReshapeLayer(reshapeDescriptor, name);
436  RecordLayer(layer, newLayer);
437  SetQuantizedInputConnections(layer, newLayer);
438 }
439 
441  const ResizeBilinearDescriptor& resizeBilinearDescriptor,
442  const char* name)
443 {
444  ResizeDescriptor resizeDescriptor;
445  resizeDescriptor.m_Method = ResizeMethod::Bilinear;
446  resizeDescriptor.m_TargetWidth = resizeBilinearDescriptor.m_TargetWidth;
447  resizeDescriptor.m_TargetHeight = resizeBilinearDescriptor.m_TargetHeight;
448  resizeDescriptor.m_DataLayout = resizeBilinearDescriptor.m_DataLayout;
449 
450  VisitResizeLayer(layer, resizeDescriptor, name);
451 }
452 
454  const ResizeDescriptor& resizeDescriptor,
455  const char* name)
456 {
457  IConnectableLayer* newLayer = m_QuantizedNetwork->AddResizeLayer(resizeDescriptor, name);
458  RecordLayer(layer, newLayer);
459  SetQuantizedInputConnections(layer, newLayer);
460 }
461 
462 void QuantizerVisitor::VisitRsqrtLayer(const IConnectableLayer* layer, const char* name)
463 {
465 }
466 
468  const SliceDescriptor& sliceDescriptor,
469  const char* name)
470 {
471  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSliceLayer(sliceDescriptor, name);
472  RecordLayer(layer, newLayer);
473  SetQuantizedInputConnections(layer, newLayer);
474 }
475 
477  const SoftmaxDescriptor& softmaxDescriptor,
478  const char* name)
479 {
480  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSoftmaxLayer(softmaxDescriptor, name);
481  RecordLayer(layer, newLayer);
482  SetQuantizedInputConnections(layer, newLayer);
483 }
484 
486  const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor,
487  const char* name)
488 {
489  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSpaceToBatchNdLayer(spaceToBatchNdDescriptor, name);
490  RecordLayer(layer, newLayer);
491  SetQuantizedInputConnections(layer, newLayer);
492 }
493 
495  const SpaceToDepthDescriptor& spaceToDepthDescriptor,
496  const char* name)
497 {
498  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSpaceToDepthLayer(spaceToDepthDescriptor, name);
499  RecordLayer(layer, newLayer);
500  SetQuantizedInputConnections(layer, newLayer);
501 }
502 
504  const SplitterDescriptor& splitterDescriptor,
505  const char* name)
506 {
507  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSplitterLayer(splitterDescriptor, name);
508  RecordLayer(layer, newLayer);
509  SetQuantizedInputConnections(layer, newLayer);
510 }
511 
513  const StackDescriptor& stackDescriptor,
514  const char* name)
515 {
516  IConnectableLayer* newLayer = m_QuantizedNetwork->AddStackLayer(stackDescriptor, name);
517  RecordLayer(layer, newLayer);
518  SetQuantizedInputConnections(layer, newLayer);
519 }
520 
522  const StridedSliceDescriptor& stridedSliceDescriptor,
523  const char* name)
524 {
525  IConnectableLayer* newLayer = m_QuantizedNetwork->AddStridedSliceLayer(stridedSliceDescriptor, name);
526  RecordLayer(layer, newLayer);
527  SetQuantizedInputConnections(layer, newLayer);
528 }
529 
531  const char* name)
532 {
533  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSubtractionLayer(name);
534  RecordLayer(layer, newLayer);
535  SetQuantizedInputConnections(layer, newLayer);
536 }
537 
539  const TransposeConvolution2dDescriptor& descriptor,
540  const ConstTensor& weights,
541  const Optional<ConstTensor>& biases,
542  const char* name)
543 {
544  // quantize weights
545  std::vector<uint8_t> weightsBacking;
546  ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking);
547 
548  // quantize biases
549  std::vector<int32_t> biasesBacking;
550  Optional<ConstTensor> optionalQBiases;
551  if (biases.has_value())
552  {
553  ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
554  optionalQBiases = Optional<ConstTensor>(qBiases);
555  }
556 
557  IConnectableLayer* newLayer = m_QuantizedNetwork->AddTransposeConvolution2dLayer(descriptor,
558  qWeights,
559  optionalQBiases,
560  name);
561 
562  RecordLayer(layer, newLayer);
563  SetQuantizedInputConnections(layer, newLayer);
564 }
565 
567  const TransposeDescriptor& transposeDescriptor,
568  const char* name)
569 {
570  IConnectableLayer* newLayer = m_QuantizedNetwork->AddTransposeLayer(transposeDescriptor, name);
571  RecordLayer(layer, newLayer);
572  SetQuantizedInputConnections(layer, newLayer);
573 }
574 
575 } //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:171
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:248
DataType GetDataType() const
Definition: Tensor.hpp:95
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:199
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:167
uint32_t m_TargetHeight
Target height value.
uint32_t m_TargetHeight
Target height value.
A SliceDescriptor for the SliceLayer.
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 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:316
unsigned int CalculateIndexOnOwner() const override
Definition: Layer.cpp:126