19 : m_RangeTracker(rangeTracker),
23 void DynamicQuantizationVisitor::SetRange(
const IConnectableLayer* layer,
unsigned int outputIdx,
float min,
float max)
25 m_RangeTracker.
SetRange(layer, outputIdx, min, max);
28 void DynamicQuantizationVisitor::ForwardParentParameters(
const IConnectableLayer* layer)
35 const auto parentRange = m_RangeTracker.
GetRange(previousLayerId, ownerIndex);
36 SetRange(layer, i, parentRange.first, parentRange.second);
40 void DynamicQuantizationVisitor::AddToCalibratedLayers(
const IConnectableLayer* layer)
42 m_LayersToCalibrate.push_back(layer);
45 void DynamicQuantizationVisitor::AddToNonCalibratedLayers(
const IConnectableLayer* layer)
47 m_LayersNotToCalibrate.push_back(layer);
55 m_Graph, *boost::polymorphic_downcast<Layer*>(const_cast<IConnectableLayer*>(layer)));
57 m_DebugLayers.insert(std::end(m_DebugLayers), std::begin(newDebugLayers), std::end(newDebugLayers));
61 void DynamicQuantizationVisitor::RemoveDebugLayers()
65 OutputSlot& proceedingOutputSlot = *debugLayer->GetInputSlot(0).GetConnectedOutputSlot();
66 proceedingOutputSlot.
Disconnect(debugLayer->GetInputSlot(0));
68 for (
InputSlot* succeedingInputSlot : debugLayer->GetOutputSlot(0).GetConnections())
70 debugLayer->GetOutputSlot(0).Disconnect(*succeedingInputSlot);
71 proceedingOutputSlot.
Connect(*succeedingInputSlot);
75 m_DebugLayers.clear();
82 ForwardParentParameters(layer);
89 SetRange(layer, 0, -20.f, 20.f);
90 AddToCalibratedLayers(layer);
107 SetRange(layer, 0, -15.0f, 15.0f);
108 AddToCalibratedLayers(layer);
121 SetRange(layer, 0, -15.0f, 15.0f);
122 AddToCalibratedLayers(layer);
135 SetRange(layer, 0, -15.0f, 15.0f);
136 AddToCalibratedLayers(layer);
151 SetRange(layer, 0, 0.f, 15.f);
154 SetRange(layer, 0, 0.f, activationDescriptor.
m_A);
157 SetRange(layer, 0, -1.f, 1.f);
160 SetRange(layer, 0, -5.f, 15.f);
163 SetRange(layer, 0, -15.f, 15.f);
166 AddToCalibratedLayers(layer);
179 SetRange(layer, 0, -15.0f, 15.0f);
180 AddToCalibratedLayers(layer);
189 AddToNonCalibratedLayers(layer);
198 AddToNonCalibratedLayers(layer);
207 AddToNonCalibratedLayers(layer);
216 SetRange(layer, 0, 0.f, 1.f);
217 AddToCalibratedLayers(layer);
233 const float* inputData =
reinterpret_cast<const float*
>(input.
GetMemoryArea());
235 float min = std::numeric_limits<float>::max();
236 float max = std::numeric_limits<float>::lowest();
238 for (
unsigned int i = 0; i < inputNumElements; i++)
240 const float inputValue = inputData[i];
242 min = std::min(min, inputValue);
243 max = std::max(max, inputValue);
245 SetRange(layer, 0, min, max);
254 float min = std::numeric_limits<float>::max();
255 float max = std::numeric_limits<float>::lowest();
262 min = std::min(min, range.first);
263 max = std::max(max, range.second);
265 SetRange(layer, 0, min, max);
266 AddToCalibratedLayers(layer);
275 AddToNonCalibratedLayers(layer);
284 AddToNonCalibratedLayers(layer);
293 AddToNonCalibratedLayers(layer);
302 AddToNonCalibratedLayers(layer);
311 AddToNonCalibratedLayers(layer);
318 SetRange(layer, 0, -0.0f, 0.0f);
319 AddToCalibratedLayers(layer);
326 AddToNonCalibratedLayers(layer);
327 m_OutputLayers.push_back(
id);
332 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 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
Functions to set the Range on a per-layer-type basis.
An output connection slot for a layer.
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
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).
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...
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).
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
A PermuteDescriptor for the PermuteLayer.