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