24.08
|
Go to the documentation of this file.
23 bool checkDataTypeInputandOutput(
const Layer& layer)
25 auto inputInfo = layer.GetInputSlot(0).GetTensorInfo();
26 auto outputInfo = layer.GetOutputSlot(0).GetTensorInfo();
27 bool sameDataType = (inputInfo.GetDataType() == outputInfo.GetDataType());
34 bool sameScale = (inputInfo.GetQuantizationScale() == outputInfo.GetQuantizationScale());
35 bool sameOffset = (inputInfo.GetQuantizationOffset() == outputInfo.GetQuantizationOffset());
37 return (sameScale && sameOffset);
52 template<
typename LayerType>
59 replacementLayer->SetAdditionalInfoForObject(
60 std::make_shared<ActivationDescriptor>(activationDesc));
62 SubgraphView substitutionSubgraph({baseLayer, activationLayer},
63 CreateIInputsFrom({baseLayer}),
64 CreateIOutputsFrom({activationLayer}));
67 optimizationViews.
AddSubstitution({substitutionSubgraph, replacementSubgraph});
69 return replacementLayer;
72 template<
typename LayerType>
82 LayerType* replacementLayer = PolymorphicDowncast<LayerType*>(replacement);
90 return replacementLayer;
93 template<
typename LayerType>
103 LayerType* replacementLayer = PolymorphicDowncast<LayerType*>(replacement);
111 return replacementLayer;
114 template<
typename LayerType>
124 LayerType* replacementLayer = PolymorphicDowncast<LayerType*>(replacement);
132 return replacementLayer;
135 template<
typename LayerType>
145 LayerType* replacementLayer = PolymorphicDowncast<LayerType*>(replacement);
153 return replacementLayer;
156 template<
typename LayerType>
166 LayerType* replacementLayer = PolymorphicDowncast<LayerType*>(replacement);
174 return replacementLayer;
177 template<
typename LayerType>
191 LayerType* replacementLayer = PolymorphicDowncast<LayerType*>(replacement);
199 SubgraphView substitutionSubgraph({baseLayer, activationLayer},
200 CreateIInputsFrom({baseLayer}),
201 CreateIOutputsFrom({activationLayer}));
204 return replacementLayer;
207 template<
typename LayerType>
217 LayerType* replacementLayer = PolymorphicDowncast<LayerType*>(replacement);
226 return replacementLayer;
229 template<
typename LayerType>
239 LayerType* replacementLayer = PolymorphicDowncast<LayerType*>(replacement);
248 return replacementLayer;
251 template<
typename LayerType>
261 LayerType* replacementLayer = PolymorphicDowncast<LayerType*>(replacement);
270 return replacementLayer;
277 template<
typename LayerType>
283 std::vector<IConnectableLayer*> layers;
286 std::vector<uint32_t> axes;
287 unsigned int recalulatedAxis = 0;
289 for (
unsigned int i = 0; i != desc.
m_vAxis.size(); ++i)
292 TensorInfo layerInfo = baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo();
294 axes.emplace_back(desc.
m_vAxis[i]);
302 std::vector<uint32_t> singleAxis(1, desc.
m_vAxis[i] - recalulatedAxis);
306 newReduceDescriptor.
m_vAxis.assign(singleAxis.begin(), singleAxis.end());
309 std::string layerName =
"reduce_layer_" + std::to_string(i);
311 Layer* replacementLayer = PolymorphicDowncast<Layer*>(
319 layers[i - 1]->GetOutputSlot(0).Connect(replacementLayer->
GetInputSlot(0));
330 layers.emplace_back(replacementLayer);
338 template<
typename LayerType>
341 std::vector<IConnectableLayer*>& layers)
343 std::list<IConnectableLayer*> replacementLayers(layers.begin(), layers.end());
346 SubgraphView replacementSubgraph(std::move(replacementLayers),
347 CreateIInputsFrom({replacementLayers.front()}),
348 CreateIOutputsFrom({replacementLayers.back()}));
350 optimizationViews.
AddSubstitution({substitutionSubgraph, replacementSubgraph});
356 template<
typename LayerType>
358 std::vector<IConnectableLayer*>& originalLayers,
360 const std::vector<SlotList> inputLayersSlotLists,
361 const std::vector<SlotList> outputLayersSlotLists)
363 std::list<IConnectableLayer*> originalLayerList(originalLayers.begin(), originalLayers.end());
366 std::move(originalLayerList),
367 CreateIInputsFromSlotLists<armnn::IConnectableLayer>(originalLayers, inputLayersSlotLists),
368 CreateIOutputsFromSlotLists<armnn::IConnectableLayer>(originalLayers, outputLayersSlotLists));
371 optimizationViews.
AddSubstitution({substitutionSubgraph, replacementSubgraph});
std::vector< IConnectableLayer * > ChainReduceLayers(OptimizationViews &optimizationViews, LayerType *baseLayer, ReduceDescriptor &desc)
An ActivationDescriptor for the ActivationLayer.
IConnectableLayer * AddReduceLayer(const ReduceDescriptor &reduceDescriptor, const char *name=nullptr)
Adds a reduce layer to the network.
LayerType * FuseDepthwiseConvolution2dLayer(OptimizationViews &optimizationViews, LayerType *baseLayer, ActivationLayer *activationLayer, ActivationDescriptor &activationDesc, std::string name)
IConnectableLayer * AddAdditionLayer(const char *name=nullptr)
Adds an addition layer to the network.
void SetTensorInfo(const TensorInfo &tensorInfo) override
IConnectableLayer * AddFullyConnectedLayer(const FullyConnectedDescriptor &fullyConnectedDescriptor, const char *name=nullptr)
Adds a fully connected layer to the network.
LayerType * FuseConvolution2dLayer(OptimizationViews &optimizationViews, LayerType *baseLayer, ActivationLayer *activationLayer, ActivationDescriptor &activationDesc, std::string name)
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
void ReplaceLayers(OptimizationViews &optimizationViews, LayerType *baseLayer, std::vector< IConnectableLayer * > &layers)
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
LayerType * FuseAdditionLayer(OptimizationViews &optimizationViews, LayerType *baseLayer, ActivationLayer *activationLayer, ActivationDescriptor &activationDesc, std::string name)
LayerType * FuseMultiplicationLayer(OptimizationViews &optimizationViews, LayerType *baseLayer, ActivationLayer *activationLayer, ActivationDescriptor &activationDesc, std::string name)
IConnectableLayer * AddBatchNormalizationLayer(const BatchNormalizationDescriptor &desc, const ConstTensor &mean, const ConstTensor &variance, const ConstTensor &beta, const ConstTensor &gamma, const char *name=nullptr)
Adds a batch normalization layer to the network.
LayerType * FuseBatchNormalizationLayer(OptimizationViews &optimizationViews, LayerType *baseLayer, ActivationLayer *activationLayer, ActivationDescriptor &activationDesc, std::string name)
IConnectableLayer * AddConvolution2dLayer(const Convolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
Adds a 2D convolution layer to the network.
LayerType * FuseDivisionLayer(OptimizationViews &optimizationViews, LayerType *baseLayer, ActivationLayer *activationLayer, ActivationDescriptor &activationDesc, std::string name)
The SubgraphView class represents a subgraph of a Graph.
IConnectableLayer * AddDivisionLayer(const char *name=nullptr)
Adds a division layer to the network.
LayerType * FuseFullyConnectedLayer(OptimizationViews &optimizationViews, LayerType *baseLayer, ActivationLayer *activationLayer, ActivationDescriptor &activationDesc, std::string name)
void AddSubstitution(SubstitutionPair &&substitution)
LayerType * FuseElementwiseBinaryLayer(OptimizationViews &optimizationViews, LayerType *baseLayer, ActivationLayer *activationLayer, ActivationDescriptor &activationDesc, BinaryOperation operation, std::string name)
IConnectableLayer * AddElementwiseBinaryLayer(const ElementwiseBinaryDescriptor &elementwiseBinaryDescriptor, const char *name=nullptr)
Add an ElementwiseBinary layer to the network.
bool m_KeepDims
if true then output shape has no change.
IConnectableLayer * AddSubtractionLayer(const char *name=nullptr)
Adds a subtraction layer to the network.
This layer represents an activation operation with the specified activation function.
#define ARMNN_NO_DEPRECATE_WARN_END
IConnectableLayer * AddDepthwiseConvolution2dLayer(const DepthwiseConvolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
Adds a 2D depthwise convolution layer to the network.
std::vector< uint32_t > m_vAxis
The indices of the dimensions to reduce.
LayerType * FuseSubtractionLayer(OptimizationViews &optimizationViews, LayerType *baseLayer, ActivationLayer *activationLayer, ActivationDescriptor &activationDesc, std::string name)
constexpr bool IsQuantizedType()
Copyright (c) 2021 ARM Limited and Contributors.
IConnectableLayer * AddMultiplicationLayer(const char *name=nullptr)
Adds a multiplication layer to the network.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
const TensorInfo ComputeReductionTensorShape(const armnn::TensorInfo &input, const std::vector< uint32_t > &vAxis, const bool keepDims)
Function to compute the output tensor shape based on the axes and if keepDims is set.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
LayerType * FuseLayer(OptimizationViews &optimizationViews, LayerType *baseLayer, LayerType *replacementLayer, ActivationLayer *activationLayer, ActivationDescriptor &activationDesc)
A ReduceDescriptor for the REDUCE operators.
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
void ReplaceMultipleLayers(OptimizationViews &optimizationViews, std::vector< IConnectableLayer * > &originalLayers, LayerType *baseLayer, const std::vector< SlotList > inputLayersSlotLists, const std::vector< SlotList > outputLayersSlotLists)