9 #include <boost/core/ignore_unused.hpp> 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);
88 boost::ignore_unused(name);
89 SetRange(layer, 0, -20.f, 20.f);
90 AddToCalibratedLayers(layer);
101 boost::ignore_unused(desc);
102 boost::ignore_unused(mean);
103 boost::ignore_unused(variance);
104 boost::ignore_unused(beta);
105 boost::ignore_unused(gamma);
106 boost::ignore_unused(name);
107 SetRange(layer, 0, -15.0f, 15.0f);
108 AddToCalibratedLayers(layer);
117 boost::ignore_unused(convolution2dDescriptor);
118 boost::ignore_unused(weights);
119 boost::ignore_unused(biases);
120 boost::ignore_unused(name);
121 SetRange(layer, 0, -15.0f, 15.0f);
122 AddToCalibratedLayers(layer);
131 boost::ignore_unused(desc);
132 boost::ignore_unused(weights);
133 boost::ignore_unused(biases);
134 boost::ignore_unused(name);
135 SetRange(layer, 0, -15.0f, 15.0f);
136 AddToCalibratedLayers(layer);
143 boost::ignore_unused(name, activationDescriptor);
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);
175 boost::ignore_unused(desc);
176 boost::ignore_unused(weights);
177 boost::ignore_unused(biases);
178 boost::ignore_unused(name);
179 SetRange(layer, 0, -15.0f, 15.0f);
180 AddToCalibratedLayers(layer);
187 boost::ignore_unused(permuteDescriptor);
188 boost::ignore_unused(name);
189 AddToNonCalibratedLayers(layer);
196 boost::ignore_unused(spaceToBatchNdDescriptor);
197 boost::ignore_unused(name);
198 AddToNonCalibratedLayers(layer);
205 boost::ignore_unused(pooling2dDescriptor);
206 boost::ignore_unused(name);
207 AddToNonCalibratedLayers(layer);
214 boost::ignore_unused(softmaxDescriptor);
215 boost::ignore_unused(name);
216 SetRange(layer, 0, 0.f, 1.f);
217 AddToCalibratedLayers(layer);
224 boost::ignore_unused(name);
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);
252 boost::ignore_unused(name);
253 boost::ignore_unused(originsDescriptor);
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);
273 boost::ignore_unused(reshapeDescriptor);
274 boost::ignore_unused(name);
275 AddToNonCalibratedLayers(layer);
282 boost::ignore_unused(splitterDescriptor);
283 boost::ignore_unused(name);
284 AddToNonCalibratedLayers(layer);
291 boost::ignore_unused(resizeDesc);
292 boost::ignore_unused(name);
293 AddToNonCalibratedLayers(layer);
300 boost::ignore_unused(stridedSliceDescriptor);
301 boost::ignore_unused(name);
302 AddToNonCalibratedLayers(layer);
309 boost::ignore_unused(batchToSpaceNdDescriptor);
310 boost::ignore_unused(name);
311 AddToNonCalibratedLayers(layer);
316 boost::ignore_unused(
id);
317 boost::ignore_unused(name);
318 SetRange(layer, 0, -0.0f, 0.0f);
319 AddToCalibratedLayers(layer);
324 boost::ignore_unused(
id);
325 boost::ignore_unused(name);
326 AddToNonCalibratedLayers(layer);
327 m_OutputLayers.push_back(
id);
332 return m_OutputLayers;
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH).
void VisitSoftmaxLayer(const IConnectableLayer *layer, const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr) override
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
DataType GetDataType() const
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
void VisitNonCalibratedLayers()
unsigned int GetNumElements() const
void VisitConvolution2dLayer(const IConnectableLayer *layer, const Convolution2dDescriptor &convolution2dDescriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr) override
An ActivationDescriptor for the ActivationLayer.
std::pair< float, float > MinMaxRange
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
int Connect(InputSlot &destination)
void VisitSpaceToBatchNdLayer(const IConnectableLayer *layer, const SpaceToBatchNdDescriptor &spaceToBatchNdDescriptor, const char *name=nullptr) override
A ViewsDescriptor for the SplitterLayer. Descriptor to configure the splitting process. Number of Views must be equal to the number of outputs, and their order must match - e.g. first view corresponds to the first output, second view to the second output, etc.
void VisitPooling2dLayer(const IConnectableLayer *layer, const Pooling2dDescriptor &pooling2dDescriptor, const char *name) override
void VisitBatchToSpaceNdLayer(const IConnectableLayer *layer, const BatchToSpaceNdDescriptor &batchToSpaceNdDescriptor, const char *name=nullptr) override
virtual LayerGuid GetOwningLayerGuid() const =0
A ReshapeDescriptor for the ReshapeLayer.
void VisitConstantLayer(const IConnectableLayer *layer, const ConstTensor &input, const char *name=nullptr) override
void VisitPermuteLayer(const IConnectableLayer *layer, const PermuteDescriptor &permuteDescriptor, const char *name) override
DynamicQuantizationVisitor(RangeTracker &rangeTracker, Graph &graph)
void VisitStridedSliceLayer(const IConnectableLayer *layer, const StridedSliceDescriptor &stridedSliceDescriptor, const char *name=nullptr) override
void FinishVisit() override
A FullyConnectedDescriptor for the FullyConnectedLayer.
const std::vector< armnn::LayerBindingId > & GetOutputLayers()
void Disconnect(InputSlot &slot)
void VisitReshapeLayer(const IConnectableLayer *layer, const ReshapeDescriptor &reshapeDescriptor, const char *name=nullptr) override
A ResizeBilinearDescriptor for the ResizeBilinearLayer.
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square).
A SoftmaxDescriptor for the SoftmaxLayer.
An output connection slot for a layer. The output slot may be connected to 1 or more input slots of s...
void VisitOutputLayer(const IConnectableLayer *layer, LayerBindingId id, const char *name=nullptr) override
void VisitAdditionLayer(const IConnectableLayer *layer, const char *name=nullptr) override
Functions to set the Range on a per-layer-type basis.
This layer visualizes the data flowing through the network.
void SetRange(const IConnectableLayer *layer, unsigned int outputIdx, float min, float max)
Set the range for an output slot on a layer.
MinMaxRange GetRange(LayerGuid guid, unsigned int idx) const
Retrieve the Range for a particular output slot on a particular layer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
MemoryType GetMemoryArea() const
A Pooling2dDescriptor for the Pooling2dLayer.
virtual unsigned int GetNumInputSlots() const =0
void VisitFullyConnectedLayer(const IConnectableLayer *layer, const FullyConnectedDescriptor &desc, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name) override
void EraseLayer(Iterator pos)
Deletes the layer at the specified position.
virtual unsigned int CalculateIndexOnOwner() const =0
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
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
std::vector< DebugLayer * > InsertDebugLayerAfter(Graph &graph, Layer &layer)
A PermuteDescriptor for the PermuteLayer.
A Convolution2dDescriptor for the Convolution2dLayer.
void VisitDepthwiseConvolution2dLayer(const IConnectableLayer *layer, const DepthwiseConvolution2dDescriptor &desc, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr) override
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
void VisitConcatLayer(const IConnectableLayer *layer, const ConcatDescriptor &originsDescriptor, const char *name=nullptr) override
void VisitInputLayer(const IConnectableLayer *layer, LayerBindingId id, const char *name=nullptr) override
void VisitSplitterLayer(const IConnectableLayer *layer, const SplitterDescriptor &splitterDescriptor, const char *name=nullptr) override
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
void VisitActivationLayer(const IConnectableLayer *layer, const ActivationDescriptor &activationDescriptor, const char *name=nullptr) override
An OriginsDescriptor for the ConcatLayer. Descriptor to configure the concatenation process...
void VisitResizeBilinearLayer(const IConnectableLayer *layer, const ResizeBilinearDescriptor &resizeDesc, const char *name=nullptr) override
A StridedSliceDescriptor for the StridedSliceLayer.