15 : m_Ranges(rangeTracker)
16 , m_QuantizedNetwork(
INetwork::Create())
17 , m_QuantizationScheme(quantizationScheme)
18 , m_PreserveType(preserveType)
22 void QuantizerStrategy::SetQuantizedInputConnections(
const IConnectableLayer* srcLayer,
37 auto found = m_OriginalToQuantizedGuidMap.find(layerToFind.
GetGuid());
38 if (found == m_OriginalToQuantizedGuidMap.end())
49 newOutputSlot.
Connect(newInputSlot);
61 info.SetQuantizationOffset(qParams.second);
62 info.SetQuantizationScale(qParams.first);
71 std::vector<int32_t>& backing)
75 auto inputSlot =
static_cast<const InputSlot*
>(&srcInputSlot);
77 const OutputSlot* outputSlot = inputSlot->GetConnectedOutputSlot();
83 auto found = m_OriginalToQuantizedGuidMap.find(layerToFind.
GetGuid());
84 if (found == m_OriginalToQuantizedGuidMap.end())
88 return biases.
value();
100 backing.resize(biases.
value().GetInfo().GetNumElements());
103 for (
size_t i = 0; i < backing.size(); ++i)
105 float fp32Value =
static_cast<const float*
>(biases.
value().GetMemoryArea())[i];
114 m_OriginalToQuantizedGuidMap.insert(std::make_pair(srcLayer->
GetGuid(), quantizedLayer->
GetGuid()));
115 m_QuantizedGuidToLayerMap.insert(std::make_pair(quantizedLayer->
GetGuid(), quantizedLayer));
120 const std::vector<armnn::ConstTensor> &constants,
132 newLayer = m_QuantizedNetwork->AddAdditionLayer(name);
138 newLayer = m_QuantizedNetwork->AddActivationLayer(activationDescriptor, name);
144 newLayer = m_QuantizedNetwork->AddArgMinMaxLayer(argMinMaxDescriptor, name);
152 std::vector<uint8_t> meanBacking;
155 std::vector<uint8_t> varianceBacking;
158 std::vector<uint8_t> betaBacking;
161 std::vector<uint8_t> gammaBacking;
164 newLayer = m_QuantizedNetwork->AddBatchNormalizationLayer(batchNormalizationDescriptor,
177 newLayer = m_QuantizedNetwork->AddBatchToSpaceNdLayer(batchToSpaceNdDescriptor, name);
183 newLayer = m_QuantizedNetwork->AddComparisonLayer(comparisonDescriptor, name);
189 newLayer = m_QuantizedNetwork->AddConcatLayer(originsDescriptor, name);
194 std::vector<uint8_t> inputBacking;
197 newLayer = m_QuantizedNetwork->AddConstantLayer(qInput, name);
206 std::vector<uint8_t> weightsBacking;
209 std::vector<int32_t> biasesBacking;
213 ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
218 newLayer = m_QuantizedNetwork->AddConvolution2dLayer(convolution2dDescriptor,
228 newLayer = m_QuantizedNetwork->AddDepthToSpaceLayer(depthToSpaceDescriptor, name);
240 std::vector<uint8_t> weightsBacking;
243 std::vector<int32_t> biasesBacking;
247 ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
251 newLayer = m_QuantizedNetwork->AddDepthwiseConvolution2dLayer(
252 depthwiseConvolution2dDescriptor,
263 newLayer = m_QuantizedNetwork->AddElementwiseUnaryLayer(elementwiseUnaryDescriptor, name);
270 newLayer = m_QuantizedNetwork->AddFillLayer(fillDescriptor, name);
282 std::vector<uint8_t> weightsBacking;
285 std::vector<int32_t> biasesBacking;
289 ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
293 newLayer = m_QuantizedNetwork->AddFullyConnectedLayer(fullyConnectedDescriptor,
309 RecordLayer(layer, quantizeLayer);
314 RecordLayer(layer, inputLayer);
324 m_QuantizedNetwork->AddInstanceNormalizationLayer(instanceNormalizationDescriptor, name);
331 newLayer = m_QuantizedNetwork->AddLogSoftmaxLayer(logSoftmaxDescriptor, name);
338 newLayer = m_QuantizedNetwork->AddMeanLayer(meanDescriptor, name);
343 newLayer = m_QuantizedNetwork->AddMultiplicationLayer(name);
350 newLayer = m_QuantizedNetwork->AddNormalizationLayer(normalizationDescriptor, name);
357 newLayer = m_QuantizedNetwork->AddOutputLayer(
id, name);
362 RecordLayer(layer, dequantizeLayer);
363 SetQuantizedInputConnections(layer, dequantizeLayer);
377 newLayer = m_QuantizedNetwork->AddPadLayer(padDescriptor, name);
384 newLayer = m_QuantizedNetwork->AddPermuteLayer(permuteDescriptor, name);
391 newLayer = m_QuantizedNetwork->AddPooling2dLayer(pooling2dDescriptor, name);
396 newLayer = m_QuantizedNetwork->AddPreluLayer(name);
403 newLayer = m_QuantizedNetwork->AddReshapeLayer(reshapeDescriptor, name);
418 newLayer = m_QuantizedNetwork->AddResizeLayer(resizeDescriptor, name);
425 newLayer = m_QuantizedNetwork->AddSliceLayer(sliceDescriptor, name);
432 newLayer = m_QuantizedNetwork->AddSoftmaxLayer(softmaxDescriptor, name);
440 newLayer = m_QuantizedNetwork->AddSpaceToBatchNdLayer(spaceToBatchNdDescriptor, name);
446 newLayer = m_QuantizedNetwork->AddSpaceToDepthLayer(spaceToDepthDescriptor, name);
452 newLayer = m_QuantizedNetwork->AddSplitterLayer(splitterDescriptor, name);
459 newLayer = m_QuantizedNetwork->AddStackLayer(stackDescriptor, name);
466 newLayer = m_QuantizedNetwork->AddStridedSliceLayer(stridedSliceDescriptor, name);
471 newLayer = m_QuantizedNetwork->AddSubtractionLayer( name);
481 std::vector<uint8_t> weightsBacking;
485 std::vector<int32_t> biasesBacking;
489 ConstTensor qBiases = CreateQuantizedBias(layer, qWeights, biases, biasesBacking);
496 newLayer = m_QuantizedNetwork->AddTransposeConvolution2dLayer(transposeConvolution2dDescriptor,
506 newLayer = m_QuantizedNetwork->AddTransposeLayer(transposeDescriptor, name);
514 RecordLayer(layer, newLayer);
515 SetQuantizedInputConnections(layer, newLayer);
std::pair< float, int > OffsetScalePair
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.
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
A ReshapeDescriptor for the ReshapeLayer.
A ComparisonDescriptor for the ComparisonLayer.
uint32_t m_TargetWidth
Target width value.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
A Convolution2dDescriptor for the Convolution2dLayer.
Layer & GetOwningLayer() const
ResizeMethod m_Method
The Interpolation method to use (Bilinear, NearestNeighbor).
void ExecuteStrategy(const armnn::IConnectableLayer *layer, const BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id) override
Main network class which provides the interface for building up a neural network. ...
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
virtual OffsetScalePair ComputeScheme(double min, double max) const =0
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
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.
Base class for all descriptors.
A StackDescriptor for the StackLayer.
A PadDescriptor for the PadLayer.
#define ARMNN_ASSERT_MSG(COND, MSG)
An output connection slot for a layer.
QuantizerStrategy(const RangeTracker &rangeTracker, const IQuantizationScheme *quantizationScheme, bool preserveType)
An ArgMinMaxDescriptor for ArgMinMaxLayer.
float GetQuantizationScale() const
DataType GetDataType() const
An OriginsDescriptor for the ConcatLayer.
bool has_value() const noexcept
A FullyConnectedDescriptor for the FullyConnectedLayer.
virtual LayerGuid GetGuid() const =0
Returns the unique id of the layer.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
uint32_t m_TargetWidth
Target width value.
#define ARMNN_ASSERT(COND)
An ActivationDescriptor for the ActivationLayer.
const TensorInfo & GetInfo() const
uint32_t m_TargetHeight
Target height value.
uint32_t m_TargetHeight
Target height value.
A SliceDescriptor for the SliceLayer.
virtual LayerType GetType() const =0
Returns the armnn::LayerType of this layer.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
virtual DataType GetDataType() const =0
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
A MeanDescriptor for the MeanLayer.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
A TransposeDescriptor for the TransposeLayer.
A StridedSliceDescriptor for the StridedSliceLayer.
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
A Pooling2dDescriptor for the Pooling2dLayer.
ConstTensor CreateQuantizedConst(const ConstTensor &tensor, std::vector< uint8_t > &backing)
A NormalizationDescriptor for the NormalizationLayer.
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
A SoftmaxDescriptor for the SoftmaxLayer.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A FillDescriptor for the FillLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
A PermuteDescriptor for the PermuteLayer.
LayerGuid GetGuid() const final
Returns the unique id of the layer.
unsigned int CalculateIndexOnOwner() const override