20 : m_RangeTracker(rangeTracker),
24 void DynamicQuantizationVisitor::SetRange(
const IConnectableLayer* layer,
unsigned int outputIdx,
float min,
float max)
26 m_RangeTracker.
SetRange(layer, outputIdx, min, max);
29 void DynamicQuantizationVisitor::ForwardParentParameters(
const IConnectableLayer* layer)
36 const auto parentRange = m_RangeTracker.
GetRange(previousLayerId, ownerIndex);
37 SetRange(layer, i, parentRange.first, parentRange.second);
41 void DynamicQuantizationVisitor::AddToCalibratedLayers(
const IConnectableLayer* layer)
43 m_LayersToCalibrate.push_back(layer);
46 void DynamicQuantizationVisitor::AddToNonCalibratedLayers(
const IConnectableLayer* layer)
48 m_LayersNotToCalibrate.push_back(layer);
56 m_Graph, *PolymorphicDowncast<Layer*>(const_cast<IConnectableLayer*>(layer)));
58 m_DebugLayers.insert(std::end(m_DebugLayers), std::begin(newDebugLayers), std::end(newDebugLayers));
62 void DynamicQuantizationVisitor::RemoveDebugLayers()
66 OutputSlot& proceedingOutputSlot = *debugLayer->GetInputSlot(0).GetConnectedOutputSlot();
67 proceedingOutputSlot.
Disconnect(debugLayer->GetInputSlot(0));
69 for (
InputSlot* succeedingInputSlot : debugLayer->GetOutputSlot(0).GetConnections())
71 debugLayer->GetOutputSlot(0).Disconnect(*succeedingInputSlot);
72 proceedingOutputSlot.
Connect(*succeedingInputSlot);
76 m_DebugLayers.clear();
83 ForwardParentParameters(layer);
91 SetRange(layer, 0, -20.f, 20.f);
92 AddToCalibratedLayers(layer);
99 SetRange(layer, 0, -20.f, 20.f);
100 AddToCalibratedLayers(layer);
109 SetRange(layer, 0, -20.f, 20.f);
110 AddToCalibratedLayers(layer);
127 SetRange(layer, 0, -15.0f, 15.0f);
128 AddToCalibratedLayers(layer);
137 SetRange(layer, 0, -15.0f, 15.0f);
138 AddToCalibratedLayers(layer);
151 SetRange(layer, 0, -15.0f, 15.0f);
152 AddToCalibratedLayers(layer);
165 SetRange(layer, 0, -15.0f, 15.0f);
166 AddToCalibratedLayers(layer);
181 SetRange(layer, 0, 0.f, 15.f);
184 SetRange(layer, 0, 0.f, activationDescriptor.
m_A);
187 SetRange(layer, 0, -1.f, 1.f);
190 SetRange(layer, 0, -5.f, 15.f);
193 SetRange(layer, 0, -15.f, 15.f);
196 AddToCalibratedLayers(layer);
209 SetRange(layer, 0, -15.0f, 15.0f);
210 AddToCalibratedLayers(layer);
219 AddToNonCalibratedLayers(layer);
228 AddToNonCalibratedLayers(layer);
237 AddToNonCalibratedLayers(layer);
246 SetRange(layer, 0, 0.f, 1.f);
247 AddToCalibratedLayers(layer);
263 const float* inputData =
reinterpret_cast<const float*
>(input.
GetMemoryArea());
265 float min = std::numeric_limits<float>::max();
266 float max = std::numeric_limits<float>::lowest();
268 for (
unsigned int i = 0; i < inputNumElements; i++)
270 const float inputValue = inputData[i];
272 min = std::min(min, inputValue);
273 max = std::max(max, inputValue);
275 SetRange(layer, 0, min, max);
284 float min = std::numeric_limits<float>::max();
285 float max = std::numeric_limits<float>::lowest();
292 min = std::min(min, range.first);
293 max = std::max(max, range.second);
295 SetRange(layer, 0, min, max);
296 AddToCalibratedLayers(layer);
305 AddToNonCalibratedLayers(layer);
314 AddToNonCalibratedLayers(layer);
323 AddToNonCalibratedLayers(layer);
332 AddToNonCalibratedLayers(layer);
341 AddToNonCalibratedLayers(layer);
348 SetRange(layer, 0, -0.0f, 0.0f);
349 AddToCalibratedLayers(layer);
356 AddToNonCalibratedLayers(layer);
357 m_OutputLayers.push_back(
id);
362 return m_OutputLayers;
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...
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 VisitNormalizationLayer(const IConnectableLayer *layer, const NormalizationDescriptor &desc, const char *name=nullptr) override
Function that a normalization layer should call back to when its Accept(ILayerVisitor&) function is i...
void VisitPermuteLayer(const IConnectableLayer *layer, const PermuteDescriptor &permuteDescriptor, const char *name) override
Function that a permute layer should call back to when its Accept(ILayerVisitor&) function is invoked...
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
void VisitNonCalibratedLayers()
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...
A ReshapeDescriptor for the ReshapeLayer.
void VisitConcatLayer(const IConnectableLayer *layer, const ConcatDescriptor &originsDescriptor, const char *name=nullptr) override
Function that a concat layer should call back to when its Accept(ILayerVisitor&) function is invoked...
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...
A Convolution2dDescriptor for the Convolution2dLayer.
int Connect(InputSlot &destination)
void EraseLayer(Iterator pos)
Deletes the layer at the specified position.
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 ...
unsigned int GetNumElements() const
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...
MemoryType GetMemoryArea() const
Copyright (c) 2020 ARM Limited.
void IgnoreUnused(Ts &&...)
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 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...
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
void VisitFullyConnectedLayer(const IConnectableLayer *layer, const FullyConnectedDescriptor &desc, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name) override
Function that a fully connected layer should call back to when its Accept(ILayerVisitor&) function is...
std::pair< float, float > MinMaxRange
void Disconnect(InputSlot &slot)
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
MinMaxRange GetRange(LayerGuid guid, unsigned int idx) const
Retrieve the Range for a particular output slot on a particular layer.
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...
DynamicQuantizationVisitor(RangeTracker &rangeTracker, Graph &graph)
void FinishVisit() override
void SetRange(const IConnectableLayer *layer, unsigned int outputIdx, float min, float max)
Set the range for an output slot on a layer.
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 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...
An output connection slot for a layer.
An ArgMinMaxDescriptor for ArgMinMaxLayer.
An OriginsDescriptor for the ConcatLayer.
A FullyConnectedDescriptor for the FullyConnectedLayer.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
This layer visualizes the data flowing through the network.
virtual unsigned int CalculateIndexOnOwner() const =0
void VisitArgMinMaxLayer(const IConnectableLayer *layer, const ArgMinMaxDescriptor &desc, const char *name=nullptr) override
Function that an arg min max layer should call back to when its Accept(ILayerVisitor&) function is in...
An ActivationDescriptor for the ActivationLayer.
min(a, max(b, input)) ReLu1 & ReLu6.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH, Elu).
void VisitAbsLayer(const IConnectableLayer *layer, const char *name=nullptr) override
Functions to set the Range on a per-layer-type basis.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
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...
A StridedSliceDescriptor for the StridedSliceLayer.
DataType GetDataType() const
virtual LayerGuid GetOwningLayerGuid() const =0
A Pooling2dDescriptor for the Pooling2dLayer.
void VisitPooling2dLayer(const IConnectableLayer *layer, const Pooling2dDescriptor &pooling2dDescriptor, const char *name) override
Function that a pooling layer should call back to when its Accept(ILayerVisitor&) function is invoked...
A NormalizationDescriptor for the NormalizationLayer.
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...
std::vector< DebugLayer * > InsertDebugLayerAfter(Graph &graph, Layer &layer)
A ResizeBilinearDescriptor for the ResizeBilinearLayer.
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...
A SoftmaxDescriptor for the SoftmaxLayer.
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...
const std::vector< armnn::LayerBindingId > & GetOutputLayers()
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
A PermuteDescriptor for the PermuteLayer.