ArmNN
 20.11
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 
13 
14 namespace armnn
15 {
16 
18  const IQuantizationScheme* quantizationScheme,
19  bool preserveType)
20  : m_Ranges(rangeTracker)
21  , m_QuantizedNetwork(INetwork::Create())
22  , m_QuantizationScheme(quantizationScheme)
23  , m_PreserveType(preserveType)
24 {
25 }
26 
27 void QuantizerVisitor::SetQuantizedInputConnections(const IConnectableLayer* srcLayer,
28  IConnectableLayer* quantizedLayer)
29 {
30  ARMNN_ASSERT(srcLayer);
31  for (unsigned int i = 0; i < srcLayer->GetNumInputSlots(); i++)
32  {
33  const IInputSlot& srcInputSlot = srcLayer->GetInputSlot(i);
34  const InputSlot* inputSlot = PolymorphicDowncast<const InputSlot*>(&srcInputSlot);
35  ARMNN_ASSERT(inputSlot);
36  const OutputSlot* outputSlot = inputSlot->GetConnectedOutputSlot();
37 
38  ARMNN_ASSERT(outputSlot);
39  unsigned int slotIdx = outputSlot->CalculateIndexOnOwner();
40  Layer& layerToFind = outputSlot->GetOwningLayer();
41 
42  auto found = m_OriginalToQuantizedGuidMap.find(layerToFind.GetGuid());
43  if (found == m_OriginalToQuantizedGuidMap.end())
44  {
45  // Error in graph traversal order
46  ARMNN_ASSERT_MSG(false, "Error in graph traversal");
47  return;
48  }
49 
50  // Connect the slots in the quantized model
51  IConnectableLayer* prevQuantizedLayer = m_QuantizedGuidToLayerMap[found->second];
52  IInputSlot& newInputSlot = quantizedLayer->GetInputSlot(i);
53  IOutputSlot& newOutputSlot = prevQuantizedLayer->GetOutputSlot(slotIdx);
54  newOutputSlot.Connect(newInputSlot);
55 
56  // Fetch the min/max ranges that were computed earlier
57  auto range = m_Ranges.GetRange(layerToFind.GetGuid(), slotIdx);
58  OffsetScalePair qParams = m_QuantizationScheme->ComputeScheme(range.first, range.second);
59 
60  // Set the quantization params
61  TensorInfo info(outputSlot->GetTensorInfo());
62  info.SetDataType(m_QuantizationScheme->GetDataType());
63  info.SetQuantizationOffset(qParams.second);
64  info.SetQuantizationScale(qParams.first);
65  newOutputSlot.SetTensorInfo(info);
66  }
67 }
68 
69 ConstTensor QuantizerVisitor::CreateQuantizedBias(const IConnectableLayer* srcLayer,
70  const ConstTensor& weights,
71  const Optional<ConstTensor>& biases,
72  std::vector<int32_t>& backing)
73 {
74  ARMNN_ASSERT(srcLayer);
75  const IInputSlot& srcInputSlot = srcLayer->GetInputSlot(0);
76  auto inputSlot = PolymorphicDowncast<const InputSlot*>(&srcInputSlot);
77  ARMNN_ASSERT(inputSlot);
78  const OutputSlot* outputSlot = inputSlot->GetConnectedOutputSlot();
79 
80  ARMNN_ASSERT(outputSlot);
81  unsigned int slotIdx = outputSlot->CalculateIndexOnOwner();
82  Layer& layerToFind = outputSlot->GetOwningLayer();
83 
84  auto found = m_OriginalToQuantizedGuidMap.find(layerToFind.GetGuid());
85  if (found == m_OriginalToQuantizedGuidMap.end())
86  {
87  // Error in graph traversal order
88  ARMNN_ASSERT_MSG(false, "Error in graph traversal");
89  return biases.value();
90  }
91 
92  // Fetch the min/max ranges that were computed earlier
93  auto range = m_Ranges.GetRange(layerToFind.GetGuid(), slotIdx);
94  OffsetScalePair qParams = m_QuantizationScheme->ComputeScheme(range.first, range.second);
95 
96  // Get the quantization scale based on input and weight scale
97  float scale = qParams.first * weights.GetInfo().GetQuantizationScale();
98 
99  // Set up quantized bias tensor info and allocate space
100  TensorInfo qInfo(biases.value().GetInfo().GetShape(), DataType::Signed32, scale, 0);
101  backing.resize(biases.value().GetInfo().GetNumElements());
102 
103  // Convert values to int32
104  for (size_t i = 0; i < backing.size(); ++i)
105  {
106  float fp32Value = static_cast<const float*>(biases.value().GetMemoryArea())[i];
107  backing[i] = armnn::numeric_cast<int32_t>(fp32Value * ( 1 / scale ));
108  }
109 
110  return ConstTensor(qInfo, backing);
111 }
112 
113 void QuantizerVisitor::RecordLayer(const IConnectableLayer* srcLayer, IConnectableLayer* quantizedLayer)
114 {
115  m_OriginalToQuantizedGuidMap.insert(std::make_pair(srcLayer->GetGuid(), quantizedLayer->GetGuid()));
116  m_QuantizedGuidToLayerMap.insert(std::make_pair(quantizedLayer->GetGuid(), quantizedLayer));
117 }
118 
119 void QuantizerVisitor::VisitAbsLayer(const IConnectableLayer* layer, const char* name)
120 {
122 }
123 
125  const ActivationDescriptor& activationDescriptor,
126  const char* name)
127 {
128  IConnectableLayer* newLayer = m_QuantizedNetwork->AddActivationLayer(activationDescriptor, name);
129  RecordLayer(layer, newLayer);
130  SetQuantizedInputConnections(layer, newLayer);
131 }
132 
133 void QuantizerVisitor::VisitAdditionLayer(const IConnectableLayer* layer, const char* name)
134 {
135  IConnectableLayer* newLayer = m_QuantizedNetwork->AddAdditionLayer(name);
136  RecordLayer(layer, newLayer);
137  SetQuantizedInputConnections(layer, newLayer);
138 }
139 
141  const ArgMinMaxDescriptor& argMinMaxDescriptor,
142  const char* name)
143 {
144  IConnectableLayer* newLayer = m_QuantizedNetwork->AddArgMinMaxLayer(argMinMaxDescriptor, name);
145  RecordLayer(layer, newLayer);
146  SetQuantizedInputConnections(layer, newLayer);
147 }
148 
150  const BatchNormalizationDescriptor& desc,
151  const ConstTensor& mean,
152  const ConstTensor& variance,
153  const ConstTensor& beta,
154  const ConstTensor& gamma,
155  const char* name)
156 {
157  std::vector<uint8_t> meanBacking;
158  ConstTensor qMean = CreateQuantizedConst(mean, meanBacking);
159 
160  std::vector<uint8_t> varianceBacking;
161  ConstTensor qVariance = CreateQuantizedConst(variance, varianceBacking);
162 
163  std::vector<uint8_t> betaBacking;
164  ConstTensor qBeta = CreateQuantizedConst(beta, betaBacking);
165 
166  std::vector<uint8_t> gammaBacking;
167  ConstTensor qGamma = CreateQuantizedConst(gamma, gammaBacking);
168 
169  IConnectableLayer* newLayer = m_QuantizedNetwork->AddBatchNormalizationLayer(desc,
170  qMean,
171  qVariance,
172  qBeta,
173  qGamma,
174  name);
175 
176  RecordLayer(layer, newLayer);
177  SetQuantizedInputConnections(layer, newLayer);
178 }
179 
181  const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor,
182  const char* name)
183 {
184  IConnectableLayer* newLayer = m_QuantizedNetwork->AddBatchToSpaceNdLayer(batchToSpaceNdDescriptor, name);
185  RecordLayer(layer, newLayer);
186  SetQuantizedInputConnections(layer, newLayer);
187 }
188 
190  const ComparisonDescriptor& comparisonDescriptor,
191  const char* name)
192 {
193  IConnectableLayer* newLayer = m_QuantizedNetwork->AddComparisonLayer(comparisonDescriptor, name);
194  RecordLayer(layer, newLayer);
195  SetQuantizedInputConnections(layer, newLayer);
196 }
197 
199  const OriginsDescriptor& originsDescriptor,
200  const char* name)
201 {
202  IConnectableLayer* newLayer = m_QuantizedNetwork->AddConcatLayer(originsDescriptor, name);
203  RecordLayer(layer, newLayer);
204  SetQuantizedInputConnections(layer, newLayer);
205 }
206 
208  const ConstTensor& input,
209  const char* name)
210 {
211  std::vector<uint8_t> inputBacking;
212  ConstTensor qInput = CreateQuantizedConst(input, inputBacking);
213 
214  IConnectableLayer* newLayer = m_QuantizedNetwork->AddConstantLayer(qInput, name);
215  RecordLayer(layer, newLayer);
216 }
217 
219  const Convolution2dDescriptor& convolution2dDescriptor,
220  const ConstTensor& weights,
221  const Optional<ConstTensor>& biases,
222  const char* name)
223 {
224  std::vector<uint8_t> weightsBacking;
225  ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking);
226  Optional<ConstTensor> optionalQBiases;
227  std::vector<int32_t> biasesBacking;
228 
229  if (biases.has_value())
230  {
231  ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
232  optionalQBiases = Optional<ConstTensor>(qBiases);
233  }
234 
235  IConnectableLayer* newLayer = m_QuantizedNetwork->AddConvolution2dLayer(convolution2dDescriptor,
236  qWeights,
237  optionalQBiases,
238  name);
239 
240  RecordLayer(layer, newLayer);
241  SetQuantizedInputConnections(layer, newLayer);
242 }
243 
245  const DepthToSpaceDescriptor& descriptor,
246  const char* name)
247 {
248  IConnectableLayer* newLayer = m_QuantizedNetwork->AddDepthToSpaceLayer(descriptor, name);
249  RecordLayer(layer, newLayer);
250  SetQuantizedInputConnections(layer, newLayer);
251 }
252 
255  const ConstTensor& weights,
256  const Optional<ConstTensor>& biases,
257  const char* name)
258 {
259  std::vector<uint8_t> weightsBacking;
260  ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking);
261  Optional<ConstTensor> optionalQBiases;
262  std::vector<int32_t> biasesBacking;
263 
264  if (biases.has_value())
265  {
266  ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
267  optionalQBiases = Optional<ConstTensor>(qBiases);
268  }
269 
270  IConnectableLayer* newLayer = m_QuantizedNetwork->AddDepthwiseConvolution2dLayer(desc,
271  qWeights,
272  optionalQBiases,
273  name);
274 
275  RecordLayer(layer, newLayer);
276  SetQuantizedInputConnections(layer, newLayer);
277 }
278 
280  const ElementwiseUnaryDescriptor& elementwiseUnaryDescriptor,
281  const char* name)
282 {
283  IConnectableLayer* newLayer = m_QuantizedNetwork->AddElementwiseUnaryLayer(elementwiseUnaryDescriptor, name);
284  RecordLayer(layer, newLayer);
285  SetQuantizedInputConnections(layer, newLayer);
286 }
287 
289  const FillDescriptor& desc,
290  const char* name)
291 {
292  IConnectableLayer* newLayer = m_QuantizedNetwork->AddFillLayer(desc, name);
293  RecordLayer(layer, newLayer);
294  SetQuantizedInputConnections(layer, newLayer);
295 }
296 
298  const FullyConnectedDescriptor& desc,
299  const ConstTensor& weights,
300  const Optional<ConstTensor>& biases,
301  const char *name)
302 {
303  std::vector<uint8_t> weightsBacking;
304  ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking);
305  Optional<ConstTensor> optionalQBiases;
306  std::vector<int32_t> biasesBacking;
307 
308  if (biases.has_value())
309  {
310  ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
311  optionalQBiases = Optional<ConstTensor>(qBiases);
312  }
313 
314  IConnectableLayer* newLayer = m_QuantizedNetwork->AddFullyConnectedLayer(desc,
315  qWeights,
316  optionalQBiases,
317  name);
318 
319  RecordLayer(layer, newLayer);
320  SetQuantizedInputConnections(layer, newLayer);
321 }
322 
324 {
325  const DataType dataType = layer->GetOutputSlot(0).GetTensorInfo().GetDataType();
326  IConnectableLayer* inputLayer = m_QuantizedNetwork->AddInputLayer(id, name);
327 
328  if (m_PreserveType && (dataType == DataType::Float32 || dataType == DataType::Float16))
329  {
330  IConnectableLayer* quantizeLayer = m_QuantizedNetwork->AddQuantizeLayer();
331  inputLayer->GetOutputSlot(0).Connect(quantizeLayer->GetInputSlot(0));
332  inputLayer->GetOutputSlot(0).SetTensorInfo(layer->GetOutputSlot(0).GetTensorInfo());
333  RecordLayer(layer, quantizeLayer);
334  }
335  else
336  {
337  RecordLayer(layer, inputLayer);
338  }
339 }
340 
342  const InstanceNormalizationDescriptor& descriptor,
343  const char* name)
344 {
345  IConnectableLayer* newLayer = m_QuantizedNetwork->AddInstanceNormalizationLayer(descriptor, name);
346  RecordLayer(layer, newLayer);
347  SetQuantizedInputConnections(layer, newLayer);
348 }
349 
351  const LogSoftmaxDescriptor& logSoftmaxDescriptor,
352  const char* name)
353 {
354  IConnectableLayer* newLayer = m_QuantizedNetwork->AddLogSoftmaxLayer(logSoftmaxDescriptor, name);
355  RecordLayer(layer, newLayer);
356  SetQuantizedInputConnections(layer, newLayer);
357 }
358 
360  const MeanDescriptor& meanDescriptor,
361  const char* name)
362 {
363  IConnectableLayer* newLayer = m_QuantizedNetwork->AddMeanLayer(meanDescriptor, name);
364  RecordLayer(layer, newLayer);
365  SetQuantizedInputConnections(layer, newLayer);
366 }
367 
369  const char* name)
370 {
371  IConnectableLayer* newLayer = m_QuantizedNetwork->AddMultiplicationLayer(name);
372  RecordLayer(layer, newLayer);
373  SetQuantizedInputConnections(layer, newLayer);
374 }
375 
377  const armnn::NormalizationDescriptor& normalizationDescriptor,
378  const char* name)
379 {
380  IConnectableLayer* newLayer = m_QuantizedNetwork->AddNormalizationLayer(normalizationDescriptor, name);
381  RecordLayer(layer, newLayer);
382  SetQuantizedInputConnections(layer, newLayer);
383 }
384 
386 {
387  const TensorInfo& info = layer->GetInputSlot(0).GetConnection()->GetTensorInfo();
388  const DataType& dataType = info.GetDataType();
389  IConnectableLayer* outputLayer = m_QuantizedNetwork->AddOutputLayer(id, name);
390 
391  if (m_PreserveType && (dataType == DataType::Float32 || dataType == DataType::Float16))
392  {
393  IConnectableLayer* dequantizeLayer = m_QuantizedNetwork->AddDequantizeLayer();
394  RecordLayer(layer, dequantizeLayer);
395  SetQuantizedInputConnections(layer, dequantizeLayer);
396  dequantizeLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
397  dequantizeLayer->GetOutputSlot(0).SetTensorInfo(info);
398  }
399  else
400  {
401  RecordLayer(layer, outputLayer);
402  SetQuantizedInputConnections(layer, outputLayer);
403  }
404 }
405 
407  const PadDescriptor& padDescriptor,
408  const char* name)
409 {
410  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPadLayer(padDescriptor, name);
411  RecordLayer(layer, newLayer);
412  SetQuantizedInputConnections(layer, newLayer);
413 }
414 
416  const PermuteDescriptor& permuteDescriptor,
417  const char* name)
418 {
419  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPermuteLayer(permuteDescriptor, name);
420  RecordLayer(layer, newLayer);
421  SetQuantizedInputConnections(layer, newLayer);
422 }
423 
425  const Pooling2dDescriptor& pooling2dDescriptor,
426  const char* name)
427 {
428  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPooling2dLayer(pooling2dDescriptor, name);
429  RecordLayer(layer, newLayer);
430  SetQuantizedInputConnections(layer, newLayer);
431 }
432 
434  const char* name)
435 {
436  IConnectableLayer* newLayer = m_QuantizedNetwork->AddPreluLayer(name);
437  RecordLayer(layer, newLayer);
438  SetQuantizedInputConnections(layer, newLayer);
439 }
440 
442  const ReshapeDescriptor& reshapeDescriptor,
443  const char* name)
444 {
445  IConnectableLayer* newLayer = m_QuantizedNetwork->AddReshapeLayer(reshapeDescriptor, name);
446  RecordLayer(layer, newLayer);
447  SetQuantizedInputConnections(layer, newLayer);
448 }
449 
451  const ResizeBilinearDescriptor& resizeBilinearDescriptor,
452  const char* name)
453 {
454  ResizeDescriptor resizeDescriptor;
455  resizeDescriptor.m_Method = ResizeMethod::Bilinear;
456  resizeDescriptor.m_TargetWidth = resizeBilinearDescriptor.m_TargetWidth;
457  resizeDescriptor.m_TargetHeight = resizeBilinearDescriptor.m_TargetHeight;
458  resizeDescriptor.m_DataLayout = resizeBilinearDescriptor.m_DataLayout;
459 
460  VisitResizeLayer(layer, resizeDescriptor, name);
461 }
462 
464  const ResizeDescriptor& resizeDescriptor,
465  const char* name)
466 {
467  IConnectableLayer* newLayer = m_QuantizedNetwork->AddResizeLayer(resizeDescriptor, name);
468  RecordLayer(layer, newLayer);
469  SetQuantizedInputConnections(layer, newLayer);
470 }
471 
472 void QuantizerVisitor::VisitRsqrtLayer(const IConnectableLayer* layer, const char* name)
473 {
475 }
476 
478  const SliceDescriptor& sliceDescriptor,
479  const char* name)
480 {
481  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSliceLayer(sliceDescriptor, name);
482  RecordLayer(layer, newLayer);
483  SetQuantizedInputConnections(layer, newLayer);
484 }
485 
487  const SoftmaxDescriptor& softmaxDescriptor,
488  const char* name)
489 {
490  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSoftmaxLayer(softmaxDescriptor, name);
491  RecordLayer(layer, newLayer);
492  SetQuantizedInputConnections(layer, newLayer);
493 }
494 
496  const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor,
497  const char* name)
498 {
499  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSpaceToBatchNdLayer(spaceToBatchNdDescriptor, name);
500  RecordLayer(layer, newLayer);
501  SetQuantizedInputConnections(layer, newLayer);
502 }
503 
505  const SpaceToDepthDescriptor& spaceToDepthDescriptor,
506  const char* name)
507 {
508  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSpaceToDepthLayer(spaceToDepthDescriptor, name);
509  RecordLayer(layer, newLayer);
510  SetQuantizedInputConnections(layer, newLayer);
511 }
512 
514  const SplitterDescriptor& splitterDescriptor,
515  const char* name)
516 {
517  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSplitterLayer(splitterDescriptor, name);
518  RecordLayer(layer, newLayer);
519  SetQuantizedInputConnections(layer, newLayer);
520 }
521 
523  const StackDescriptor& stackDescriptor,
524  const char* name)
525 {
526  IConnectableLayer* newLayer = m_QuantizedNetwork->AddStackLayer(stackDescriptor, name);
527  RecordLayer(layer, newLayer);
528  SetQuantizedInputConnections(layer, newLayer);
529 }
530 
532  const StridedSliceDescriptor& stridedSliceDescriptor,
533  const char* name)
534 {
535  IConnectableLayer* newLayer = m_QuantizedNetwork->AddStridedSliceLayer(stridedSliceDescriptor, name);
536  RecordLayer(layer, newLayer);
537  SetQuantizedInputConnections(layer, newLayer);
538 }
539 
541  const char* name)
542 {
543  IConnectableLayer* newLayer = m_QuantizedNetwork->AddSubtractionLayer(name);
544  RecordLayer(layer, newLayer);
545  SetQuantizedInputConnections(layer, newLayer);
546 }
547 
549  const TransposeConvolution2dDescriptor& descriptor,
550  const ConstTensor& weights,
551  const Optional<ConstTensor>& biases,
552  const char* name)
553 {
554  // quantize weights
555  std::vector<uint8_t> weightsBacking;
556  ConstTensor qWeights = CreateQuantizedConst(weights, weightsBacking);
557 
558  // quantize biases
559  std::vector<int32_t> biasesBacking;
560  Optional<ConstTensor> optionalQBiases;
561  if (biases.has_value())
562  {
563  ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
564  optionalQBiases = Optional<ConstTensor>(qBiases);
565  }
566 
567  IConnectableLayer* newLayer = m_QuantizedNetwork->AddTransposeConvolution2dLayer(descriptor,
568  qWeights,
569  optionalQBiases,
570  name);
571 
572  RecordLayer(layer, newLayer);
573  SetQuantizedInputConnections(layer, newLayer);
574 }
575 
577  const TransposeDescriptor& transposeDescriptor,
578  const char* name)
579 {
580  IConnectableLayer* newLayer = m_QuantizedNetwork->AddTransposeLayer(transposeDescriptor, name);
581  RecordLayer(layer, newLayer);
582  SetQuantizedInputConnections(layer, newLayer);
583 }
584 
585 } //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:73
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:202
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:452
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:314
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
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:282
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:93
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
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
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:319
unsigned int CalculateIndexOnOwner() const override
Definition: Layer.cpp:130