19 : m_RangeTracker(rangeTracker),
23 void DynamicQuantizationStrategy::SetRange(
const IConnectableLayer* layer,
unsigned int outputIdx,
float min,
float max)
25 m_RangeTracker.
SetRange(layer, outputIdx, min, max);
28 void DynamicQuantizationStrategy::ForwardParentParameters(
const IConnectableLayer* layer)
35 const auto parentRange = m_RangeTracker.
GetRange(previousLayerId, ownerIndex);
36 SetRange(layer, i, parentRange.first, parentRange.second);
40 void DynamicQuantizationStrategy::AddToCalibratedLayers(
const IConnectableLayer* layer)
42 m_LayersToCalibrate.push_back(layer);
45 void DynamicQuantizationStrategy::AddToNonCalibratedLayers(
const IConnectableLayer* layer)
47 m_LayersNotToCalibrate.push_back(layer);
55 m_Graph, *PolymorphicDowncast<Layer*>(const_cast<IConnectableLayer*>(layer)));
57 m_DebugLayers.insert(std::end(m_DebugLayers), std::begin(newDebugLayers), std::end(newDebugLayers));
61 void DynamicQuantizationStrategy::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 const std::vector<armnn::ConstTensor>& constants,
109 SetRange(layer, 0, 0.f, 15.f);
112 SetRange(layer, 0, 0.f, activationDescriptor.
m_A);
115 SetRange(layer, 0, -1.f, 1.f);
118 SetRange(layer, 0, -5.f, 15.f);
121 SetRange(layer, 0, -15.f, 15.f);
128 SetRange(layer, 0, -20.f, 20.f);
129 AddToCalibratedLayers(layer);
134 AddToNonCalibratedLayers(layer);
139 SetRange(layer, 0, -15.0f, 15.0f);
140 AddToCalibratedLayers(layer);
145 SetRange(layer, 0, -15.0f, 15.0f);
146 AddToCalibratedLayers(layer);
151 SetRange(layer, 0, -15.0f, 15.0f);
152 AddToCalibratedLayers(layer);
157 SetRange(layer, 0, -15.0f, 15.0f);
158 AddToCalibratedLayers(layer);
163 SetRange(layer, 0, -15.0f, 15.0f);
164 AddToCalibratedLayers(layer);
169 AddToNonCalibratedLayers(layer);
174 AddToNonCalibratedLayers(layer);
179 AddToNonCalibratedLayers(layer);
184 SetRange(layer, 0, 0.f, 1.f);
185 AddToCalibratedLayers(layer);
196 unsigned int inputNumElements = constants[0].GetNumElements();
197 const float* inputData =
reinterpret_cast<const float*
>(constants[0].GetMemoryArea());
199 float min = std::numeric_limits<float>::max();
200 float max = std::numeric_limits<float>::lowest();
202 for (
unsigned int i = 0; i < inputNumElements; i++)
204 const float inputValue = inputData[i];
206 min = std::min(min, inputValue);
207 max = std::max(max, inputValue);
209 SetRange(layer, 0, min, max);
214 float min = std::numeric_limits<float>::max();
215 float max = std::numeric_limits<float>::lowest();
222 min = std::min(min, range.first);
223 max = std::max(max, range.second);
225 SetRange(layer, 0, min, max);
226 AddToCalibratedLayers(layer);
231 AddToNonCalibratedLayers(layer);
236 AddToNonCalibratedLayers(layer);
241 AddToNonCalibratedLayers(layer);
246 AddToNonCalibratedLayers(layer);
251 AddToNonCalibratedLayers(layer);
256 SetRange(layer, 0, -0.0f, 0.0f);
257 AddToCalibratedLayers(layer);
262 AddToNonCalibratedLayers(layer);
263 m_OutputLayers.push_back(
id);
273 return m_OutputLayers;
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.
int Connect(InputSlot &destination)
void EraseLayer(Iterator pos)
Deletes the layer at the specified position.
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
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.
Base class for all descriptors.
virtual void ExecuteStrategy(const armnn::IConnectableLayer *layer, const armnn::BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id=0) override
void VisitNonCalibratedLayers()
DynamicQuantizationStrategy(RangeTracker &rangeTracker, Graph &graph)
void SetRange(const IConnectableLayer *layer, unsigned int outputIdx, float min, float max)
Set the range for an output slot on a layer.
An output connection slot for a layer.
This layer visualizes the data flowing through the network.
virtual unsigned int CalculateIndexOnOwner() const =0
void FinishStrategy() override
An ActivationDescriptor for the ActivationLayer.
min(a, max(b, input)) ReLu1 & ReLu6.
virtual LayerType GetType() const =0
Returns the armnn::LayerType of this layer.
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH, Elu).
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual LayerGuid GetOwningLayerGuid() const =0
const std::vector< armnn::LayerBindingId > & GetOutputLayers()
std::vector< DebugLayer * > InsertDebugLayerAfter(Graph &graph, Layer &layer)
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square, Elu).