19 #include <boost/filesystem.hpp> 20 #include <boost/format.hpp> 21 #include <boost/core/ignore_unused.hpp> 22 #include <boost/assert.hpp> 23 #include <boost/format.hpp> 24 #include <boost/format.hpp> 25 #include <boost/numeric/conversion/cast.hpp> 26 #include <boost/polymorphic_cast.hpp> 34 using namespace armnn;
43 const uint32_t VIRTUAL_LAYER_ID = std::numeric_limits<uint32_t>::max();
45 void CheckGraph(
const Deserializer::GraphPtr& graph,
46 unsigned int layersIndex,
49 if (graph->layers() ==
nullptr)
53 boost::format(
"%1% was called with invalid (null) graph. " 54 "Possible reason is that the graph is not yet loaded and Unpack(ed). " 55 "layers:%2% at %3%") %
60 else if (layersIndex >= graph->layers()->size())
64 boost::format(
"%1% was called with an invalid layers index. " 65 "layers:%2% at %3%") %
72 void CheckLayers(
const Deserializer::GraphPtr& graph,
73 unsigned int layersIndex,
74 unsigned int layerIndex,
77 if (graph->layers() ==
nullptr)
81 boost::format(
"%1% was called with invalid (null) graph. " 82 "Possible reason is that the graph is not yet loaded and Unpack(ed). " 83 "layers:%2% at %3%") %
88 else if (layersIndex >= graph->layers()->size())
92 boost::format(
"%1% was called with an invalid layers index. " 93 "layers:%2% at %3%") %
98 else if (layerIndex >= graph->layers()[layersIndex].size()
99 && layerIndex != VIRTUAL_LAYER_ID)
103 boost::format(
"%1% was called with an invalid layer index. " 104 "layers:%2% layer:%3% at %4%") %
115 if (rawPtr ==
nullptr)
119 boost::format(
"%1% was called with a null tensor pointer. " 127 void CheckConstTensorPtr(Deserializer::ConstTensorRawPtr rawPtr,
130 if (rawPtr ==
nullptr)
132 throw ParseException(boost::str(boost::format(
"%1% was called with a null const tensor pointer. at %2%") %
138 void CheckConstTensorSize(
const unsigned int constTensorSize,
139 const unsigned int tensorSize,
142 if (constTensorSize != tensorSize)
144 throw ParseException(boost::str(boost::format(
"%1% wrong number of components supplied to tensor. at:%2%") %
150 #define CHECK_TENSOR_PTR(TENSOR_PTR) \ 151 CheckTensorPtr(TENSOR_PTR, CHECK_LOCATION()) 153 #define CHECK_CONST_TENSOR_SIZE(CONST_TENSOR_SIZE, TENSOR_SIZE) \ 154 CheckConstTensorSize(CONST_TENSOR_SIZE, TENSOR_SIZE, CHECK_LOCATION()) 156 #define CHECK_CONST_TENSOR_PTR(TENSOR_PTR) \ 157 CheckConstTensorPtr(TENSOR_PTR, CHECK_LOCATION()) 159 #define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX) \ 160 CheckLayers(GRAPH, LAYERS_INDEX, LAYER_INDEX, CHECK_LOCATION()) 162 #define CHECK_GRAPH(GRAPH, LAYERS_INDEX) \ 163 CheckGraph(GRAPH, LAYERS_INDEX, CHECK_LOCATION()) 169 if (actualSize != expected.size())
174 for (
unsigned int i = 0u; i < actualSize; i++)
176 if (actual[i] != static_cast<unsigned int>(expected[i]))
185 Deserializer::Deserializer()
186 : m_Network(nullptr, nullptr),
188 m_ParserFunctions(Layer_MAX+1, &
Deserializer::ParseUnsupportedLayer)
191 m_ParserFunctions[Layer_AbsLayer] = &Deserializer::ParseAbs;
192 m_ParserFunctions[Layer_ActivationLayer] = &Deserializer::ParseActivation;
193 m_ParserFunctions[Layer_AdditionLayer] = &Deserializer::ParseAdd;
194 m_ParserFunctions[Layer_ArgMinMaxLayer] = &Deserializer::ParseArgMinMax;
195 m_ParserFunctions[Layer_BatchToSpaceNdLayer] = &Deserializer::ParseBatchToSpaceNd;
196 m_ParserFunctions[Layer_BatchNormalizationLayer] = &Deserializer::ParseBatchNormalization;
197 m_ParserFunctions[Layer_ComparisonLayer] = &Deserializer::ParseComparison;
198 m_ParserFunctions[Layer_ConcatLayer] = &Deserializer::ParseConcat;
199 m_ParserFunctions[Layer_ConstantLayer] = &Deserializer::ParseConstant;
200 m_ParserFunctions[Layer_Convolution2dLayer] = &Deserializer::ParseConvolution2d;
201 m_ParserFunctions[Layer_DepthToSpaceLayer] = &Deserializer::ParseDepthToSpace;
202 m_ParserFunctions[Layer_DepthwiseConvolution2dLayer] = &Deserializer::ParseDepthwiseConvolution2d;
203 m_ParserFunctions[Layer_DequantizeLayer] = &Deserializer::ParseDequantize;
204 m_ParserFunctions[Layer_DetectionPostProcessLayer] = &Deserializer::ParseDetectionPostProcess;
205 m_ParserFunctions[Layer_DivisionLayer] = &Deserializer::ParseDivision;
206 m_ParserFunctions[Layer_ElementwiseUnaryLayer] = &Deserializer::ParseElementwiseUnary;
207 m_ParserFunctions[Layer_EqualLayer] = &Deserializer::ParseEqual;
208 m_ParserFunctions[Layer_FullyConnectedLayer] = &Deserializer::ParseFullyConnected;
209 m_ParserFunctions[Layer_FloorLayer] = &Deserializer::ParseFloor;
210 m_ParserFunctions[Layer_GatherLayer] = &Deserializer::ParseGather;
211 m_ParserFunctions[Layer_GreaterLayer] = &Deserializer::ParseGreater;
212 m_ParserFunctions[Layer_InstanceNormalizationLayer] = &Deserializer::ParseInstanceNormalization;
213 m_ParserFunctions[Layer_L2NormalizationLayer] = &Deserializer::ParseL2Normalization;
214 m_ParserFunctions[Layer_LogSoftmaxLayer] = &Deserializer::ParseLogSoftmax;
215 m_ParserFunctions[Layer_LstmLayer] = &Deserializer::ParseLstm;
216 m_ParserFunctions[Layer_MaximumLayer] = &Deserializer::ParseMaximum;
217 m_ParserFunctions[Layer_MeanLayer] = &Deserializer::ParseMean;
218 m_ParserFunctions[Layer_MinimumLayer] = &Deserializer::ParseMinimum;
219 m_ParserFunctions[Layer_MergeLayer] = &Deserializer::ParseMerge;
220 m_ParserFunctions[Layer_MergerLayer] = &Deserializer::ParseConcat;
221 m_ParserFunctions[Layer_MultiplicationLayer] = &Deserializer::ParseMultiplication;
222 m_ParserFunctions[Layer_NormalizationLayer] = &Deserializer::ParseNormalization;
223 m_ParserFunctions[Layer_PadLayer] = &Deserializer::ParsePad;
224 m_ParserFunctions[Layer_PermuteLayer] = &Deserializer::ParsePermute;
225 m_ParserFunctions[Layer_Pooling2dLayer] = &Deserializer::ParsePooling2d;
226 m_ParserFunctions[Layer_PreluLayer] = &Deserializer::ParsePrelu;
227 m_ParserFunctions[Layer_QuantizeLayer] = &Deserializer::ParseQuantize;
228 m_ParserFunctions[Layer_QuantizedLstmLayer] = &Deserializer::ParseQuantizedLstm;
229 m_ParserFunctions[Layer_ReshapeLayer] = &Deserializer::ParseReshape;
230 m_ParserFunctions[Layer_ResizeBilinearLayer] = &Deserializer::ParseResizeBilinear;
231 m_ParserFunctions[Layer_ResizeLayer] = &Deserializer::ParseResize;
232 m_ParserFunctions[Layer_RsqrtLayer] = &Deserializer::ParseRsqrt;
233 m_ParserFunctions[Layer_SliceLayer] = &Deserializer::ParseSlice;
234 m_ParserFunctions[Layer_SoftmaxLayer] = &Deserializer::ParseSoftmax;
235 m_ParserFunctions[Layer_SpaceToBatchNdLayer] = &Deserializer::ParseSpaceToBatchNd;
236 m_ParserFunctions[Layer_SpaceToDepthLayer] = &Deserializer::ParseSpaceToDepth;
237 m_ParserFunctions[Layer_SplitterLayer] = &Deserializer::ParseSplitter;
238 m_ParserFunctions[Layer_StackLayer] = &Deserializer::ParseStack;
239 m_ParserFunctions[Layer_StandInLayer] = &Deserializer::ParseStandIn;
240 m_ParserFunctions[Layer_StridedSliceLayer] = &Deserializer::ParseStridedSlice;
241 m_ParserFunctions[Layer_SubtractionLayer] = &Deserializer::ParseSubtraction;
242 m_ParserFunctions[Layer_SwitchLayer] = &Deserializer::ParseSwitch;
243 m_ParserFunctions[Layer_TransposeConvolution2dLayer] = &Deserializer::ParseTransposeConvolution2d;
248 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
252 case Layer::Layer_AbsLayer:
253 return graphPtr->layers()->Get(layerIndex)->layer_as_AbsLayer()->base();
254 case Layer::Layer_ActivationLayer:
255 return graphPtr->layers()->Get(layerIndex)->layer_as_ActivationLayer()->base();
256 case Layer::Layer_AdditionLayer:
257 return graphPtr->layers()->Get(layerIndex)->layer_as_AdditionLayer()->base();
258 case Layer::Layer_ArgMinMaxLayer:
259 return graphPtr->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer()->base();
260 case Layer::Layer_BatchToSpaceNdLayer:
261 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->base();
262 case Layer::Layer_BatchNormalizationLayer:
263 return graphPtr->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer()->base();
264 case Layer::Layer_ComparisonLayer:
265 return graphPtr->layers()->Get(layerIndex)->layer_as_ComparisonLayer()->base();
266 case Layer::Layer_ConcatLayer:
267 return graphPtr->layers()->Get(layerIndex)->layer_as_ConcatLayer()->base();
268 case Layer::Layer_ConstantLayer:
269 return graphPtr->layers()->Get(layerIndex)->layer_as_ConstantLayer()->base();
270 case Layer::Layer_Convolution2dLayer:
271 return graphPtr->layers()->Get(layerIndex)->layer_as_Convolution2dLayer()->base();
272 case Layer::Layer_DepthToSpaceLayer:
273 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->base();
274 case Layer::Layer_DepthwiseConvolution2dLayer:
275 return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base();
276 case Layer::Layer_DequantizeLayer:
277 return graphPtr->layers()->Get(layerIndex)->layer_as_DequantizeLayer()->base();
278 case Layer::Layer_DetectionPostProcessLayer:
279 return graphPtr->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer()->base();
280 case Layer::Layer_DivisionLayer:
281 return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base();
282 case Layer::Layer_EqualLayer:
283 return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base();
284 case Layer::Layer_FullyConnectedLayer:
285 return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base();
286 case Layer::Layer_FloorLayer:
287 return graphPtr->layers()->Get(layerIndex)->layer_as_FloorLayer()->base();
288 case Layer::Layer_GatherLayer:
289 return graphPtr->layers()->Get(layerIndex)->layer_as_GatherLayer()->base();
290 case Layer::Layer_GreaterLayer:
291 return graphPtr->layers()->Get(layerIndex)->layer_as_GreaterLayer()->base();
292 case Layer::Layer_InputLayer:
293 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->base();
294 case Layer::Layer_InstanceNormalizationLayer:
295 return graphPtr->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer()->base();
296 case Layer::Layer_L2NormalizationLayer:
297 return graphPtr->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer()->base();
298 case Layer::Layer_LogSoftmaxLayer:
299 return graphPtr->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->base();
300 case Layer::Layer_LstmLayer:
301 return graphPtr->layers()->Get(layerIndex)->layer_as_LstmLayer()->base();
302 case Layer::Layer_MeanLayer:
303 return graphPtr->layers()->Get(layerIndex)->layer_as_MeanLayer()->base();
304 case Layer::Layer_MinimumLayer:
305 return graphPtr->layers()->Get(layerIndex)->layer_as_MinimumLayer()->base();
306 case Layer::Layer_MaximumLayer:
307 return graphPtr->layers()->Get(layerIndex)->layer_as_MaximumLayer()->base();
308 case Layer::Layer_MergeLayer:
309 return graphPtr->layers()->Get(layerIndex)->layer_as_MergeLayer()->base();
310 case Layer::Layer_MergerLayer:
311 return graphPtr->layers()->Get(layerIndex)->layer_as_MergerLayer()->base();
312 case Layer::Layer_MultiplicationLayer:
313 return graphPtr->layers()->Get(layerIndex)->layer_as_MultiplicationLayer()->base();
314 case Layer::Layer_NormalizationLayer:
315 return graphPtr->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->base();
316 case Layer::Layer_OutputLayer:
317 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->base();
318 case Layer::Layer_PadLayer:
319 return graphPtr->layers()->Get(layerIndex)->layer_as_PadLayer()->base();
320 case Layer::Layer_PermuteLayer:
321 return graphPtr->layers()->Get(layerIndex)->layer_as_PermuteLayer()->base();
322 case Layer::Layer_Pooling2dLayer:
323 return graphPtr->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->base();
324 case Layer::Layer_PreluLayer:
325 return graphPtr->layers()->Get(layerIndex)->layer_as_PreluLayer()->base();
326 case Layer::Layer_QuantizeLayer:
327 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizeLayer()->base();
328 case Layer::Layer_QuantizedLstmLayer:
329 return graphPtr->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer()->base();
330 case Layer::Layer_ReshapeLayer:
331 return graphPtr->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->base();
332 case Layer::Layer_ResizeBilinearLayer:
333 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->base();
334 case Layer::Layer_ResizeLayer:
335 return graphPtr->layers()->Get(layerIndex)->layer_as_ResizeLayer()->base();
336 case Layer::Layer_RsqrtLayer:
337 return graphPtr->layers()->Get(layerIndex)->layer_as_RsqrtLayer()->base();
338 case Layer::Layer_SliceLayer:
339 return graphPtr->layers()->Get(layerIndex)->layer_as_SliceLayer()->base();
340 case Layer::Layer_SoftmaxLayer:
341 return graphPtr->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->base();
342 case Layer::Layer_SpaceToBatchNdLayer:
343 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->base();
344 case Layer::Layer_SpaceToDepthLayer:
345 return graphPtr->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->base();
346 case Layer::Layer_SplitterLayer:
347 return graphPtr->layers()->Get(layerIndex)->layer_as_SplitterLayer()->base();
348 case Layer::Layer_StackLayer:
349 return graphPtr->layers()->Get(layerIndex)->layer_as_StackLayer()->base();
350 case Layer::Layer_StandInLayer:
351 return graphPtr->layers()->Get(layerIndex)->layer_as_StandInLayer()->base();
352 case Layer::Layer_StridedSliceLayer:
353 return graphPtr->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->base();
354 case Layer::Layer_SubtractionLayer:
355 return graphPtr->layers()->Get(layerIndex)->layer_as_SubtractionLayer()->base();
356 case Layer::Layer_SwitchLayer:
357 return graphPtr->layers()->Get(layerIndex)->layer_as_SwitchLayer()->base();
358 case Layer::Layer_TransposeConvolution2dLayer:
359 return graphPtr->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer()->base();
360 case Layer::Layer_NONE:
363 boost::format(
"Layer type %1% not recognized") %
372 return layer->layerName()->str();
377 auto layerType = graphPtr->layers()->Get(layerIndex)->layer_type();
379 if (layerType == Layer::Layer_InputLayer)
381 return graphPtr->layers()->Get(layerIndex)->layer_as_InputLayer()->base()->layerBindingId();
383 else if ( layerType == Layer::Layer_OutputLayer )
385 return graphPtr->layers()->Get(layerIndex)->layer_as_OutputLayer()->base()->layerBindingId();
394 case armnnSerializer::DataLayout::DataLayout_NHWC:
396 case armnnSerializer::DataLayout::DataLayout_NCHW:
406 case armnnSerializer::ActivationFunction_Sigmoid:
408 case armnnSerializer::ActivationFunction_TanH:
410 case armnnSerializer::ActivationFunction_Linear:
412 case armnnSerializer::ActivationFunction_ReLu:
414 case armnnSerializer::ActivationFunction_BoundedReLu:
416 case armnnSerializer::ActivationFunction_LeakyReLu:
418 case armnnSerializer::ActivationFunction_Abs:
420 case armnnSerializer::ActivationFunction_Sqrt:
422 case armnnSerializer::ActivationFunction_Square:
433 case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Max:
435 case armnnSerializer::ArgMinMaxFunction::ArgMinMaxFunction_Min:
445 case armnnSerializer::ComparisonOperation::ComparisonOperation_Equal:
447 case armnnSerializer::ComparisonOperation::ComparisonOperation_Greater:
449 case armnnSerializer::ComparisonOperation::ComparisonOperation_GreaterOrEqual:
451 case armnnSerializer::ComparisonOperation::ComparisonOperation_Less:
453 case armnnSerializer::ComparisonOperation::ComparisonOperation_LessOrEqual:
455 case armnnSerializer::ComparisonOperation::ComparisonOperation_NotEqual:
465 case armnnSerializer::UnaryOperation::UnaryOperation_Abs:
467 case armnnSerializer::UnaryOperation::UnaryOperation_Rsqrt:
469 case armnnSerializer::UnaryOperation::UnaryOperation_Sqrt:
471 case armnnSerializer::UnaryOperation::UnaryOperation_Exp:
473 case armnnSerializer::UnaryOperation::UnaryOperation_Neg:
484 case armnnSerializer::ResizeMethod_NearestNeighbor:
486 case armnnSerializer::ResizeMethod_Bilinear:
498 switch (tensorPtr->dataType())
500 case DataType_QuantisedAsymm8:
501 case DataType_QAsymmU8:
504 case DataType_QSymmS16:
505 case DataType_QuantisedSymm16:
508 case DataType_Signed32:
511 case DataType_Float32:
514 case DataType_Float16:
517 case DataType_Boolean:
525 boost::format(
"Unsupported data type %1% = %2%. %3%") %
526 tensorPtr->dataType() %
527 EnumNameDataType(tensorPtr->dataType()) %
531 float quantizationScale = tensorPtr->quantizationScale();
532 int32_t quantizationOffset = tensorPtr->quantizationOffset();
534 auto dimensions = tensorPtr->dimensions();
535 unsigned int size = dimensions->size();
536 std::vector<unsigned int> outputDims(dimensions->begin(), dimensions->begin() + size);
552 switch (constTensorPtr->data_type())
554 case ConstTensorData_ByteData:
556 auto byteData = constTensorPtr->data_as_ByteData()->data();
560 case ConstTensorData_ShortData:
562 auto shortData = constTensorPtr->data_as_ShortData()->data();
566 case ConstTensorData_IntData:
568 auto intData = constTensorPtr->data_as_IntData()->data();
572 case ConstTensorData_LongData:
574 auto longData = constTensorPtr->data_as_LongData()->data();
582 boost::str(boost::format(
"Unsupported data type %1% = %2%. %3%") %
583 constTensorPtr->data_type() %
584 EnumNameConstTensorData(constTensorPtr->data_type()) %
591 unsigned int layerIndex)
595 const auto& numInputs = layer->inputSlots()->size();
599 for (
unsigned int i=0; i<numInputs; ++i)
602 (layer->inputSlots()->Get(i)->connection()->sourceLayerIndex()));
603 result[i] =
GetBaseLayer(graphPtr, inputId)->outputSlots()->Get(0)->tensorInfo();
609 unsigned int layerIndex)
613 const auto& numOutputs = layer->outputSlots()->size();
617 for (
unsigned int i=0; i<numOutputs; ++i)
619 result[i] = layer->outputSlots()->Get(i)->tensorInfo();
624 void Deserializer::ParseUnsupportedLayer(
GraphPtr graph,
unsigned int layerIndex)
627 const auto layerName =
GetBaseLayer(graph, layerIndex)->layerName()->c_str();
630 boost::format(
"Layer not supported. " 632 "layerName: %2% / %3%") %
638 void Deserializer::ResetParser()
641 m_InputBindings.clear();
642 m_OutputBindings.clear();
664 return CreateNetworkFromGraph(graph);
670 std::vector<uint8_t> content((std::istreambuf_iterator<char>(binaryContent)), std::istreambuf_iterator<char>());
672 return CreateNetworkFromGraph(graph);
677 if (binaryContent ==
nullptr)
682 flatbuffers::Verifier verifier(binaryContent, len);
683 if (verifier.VerifyBuffer<SerializedGraph>() ==
false)
686 boost::str(boost::format(
"Buffer doesn't conform to the expected Armnn " 687 "flatbuffers format. size:%1% %2%") %
691 return GetSerializedGraph(binaryContent);
696 m_Network = INetwork::Create();
697 BOOST_ASSERT(graph !=
nullptr);
698 unsigned int layerIndex = 0;
699 for (AnyLayer
const* layer : *graph->layers())
701 if (layer->layer_type() != Layer_InputLayer &&
702 layer->layer_type() != Layer_OutputLayer)
705 auto& parserFunction = m_ParserFunctions[layer->layer_type()];
706 (this->*parserFunction)(graph, layerIndex);
711 SetupInputLayers(graph);
712 SetupOutputLayers(graph);
715 for (
auto&& graphIt : m_GraphConnections)
717 Connections& connections = graphIt.second;
718 for (
auto&& outputIt : connections.outputSlots)
720 const unsigned int outputSlotIndex = outputIt.first;
722 if (connections.inputSlots.find(outputSlotIndex) != connections.inputSlots.end())
724 for (
IInputSlot* inputSlot : connections.inputSlots[outputSlotIndex])
726 outputSlot->
Connect(*inputSlot);
732 return std::move(m_Network);
736 const std::string& name)
const 738 boost::ignore_unused(layerIndex);
739 for (
auto inputBinding : m_InputBindings)
741 if (inputBinding.first == name)
743 return inputBinding.second;
748 boost::format(
"No input binding found for layer:%1% / %2%") %
754 const std::string& name)
const 756 boost::ignore_unused(layerIndex);
757 for (
auto outputBinding : m_OutputBindings)
759 if (outputBinding.first == name)
761 return outputBinding.second;
766 boost::format(
"No output binding found for layer:%1% / %2%") %
771 unsigned int Deserializer::GetInputLayerInVector(
GraphPtr graph,
int targetId)
773 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
775 auto layer = graph->layers()->Get(i);
776 if (layer->layer_type() == Layer::Layer_InputLayer)
778 auto layerBindingId = layer->layer_as_InputLayer()->base()->layerBindingId();
779 if (layerBindingId == targetId)
785 throw ParseException(
"Input layer with given layerBindingId not found");
788 unsigned int Deserializer::GetOutputLayerInVector(
GraphPtr graph,
int targetId)
790 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
792 auto layer = graph->layers()->Get(i);
793 if (layer->layer_type() == Layer::Layer_OutputLayer)
795 auto layerBindingId = layer->layer_as_OutputLayer()->base()->layerBindingId();
796 if (layerBindingId == targetId)
802 throw ParseException(
"Output layer with given layerBindingId not found");
805 unsigned int Deserializer::GetLayerIndexInVector(
GraphPtr graph,
unsigned int targetIndex)
807 for (
unsigned int i = 0; i < graph->layers()->size(); i++)
810 if (layer->index() == targetIndex)
818 Deserializer::FeatureVersions Deserializer::GetFeatureVersions(
GraphPtr graph)
820 Deserializer::FeatureVersions versions;
822 if (graph->featureVersions())
824 versions.m_BindingIdScheme = graph->featureVersions()->bindingIdsScheme();
830 void Deserializer::SetupInputLayers(
GraphPtr graph)
833 const unsigned int numInputs = graph->inputIds()->size();
834 m_InputBindings.clear();
835 m_InputBindings.reserve(numInputs);
837 for (
unsigned int i = 0; i < numInputs; i++)
839 unsigned int inputLayerIndex = 0xFFFFFFFF;
840 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
842 const unsigned int inputId = boost::numeric_cast<
unsigned int>(graph->inputIds()->Get(i));
843 inputLayerIndex = GetLayerIndexInVector(graph, inputId);
847 const int inputId = graph->inputIds()->Get(i);
848 inputLayerIndex = GetInputLayerInVector(graph, inputId);
855 BOOST_ASSERT_MSG(baseLayer->layerName()->c_str(),
"Input has no name.");
858 m_Network->AddInputLayer(bindingId, baseLayer->layerName()->c_str());
861 inputLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
862 RegisterOutputSlots(graph, inputLayerIndex, inputLayer);
865 m_InputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
869 void Deserializer::SetupOutputLayers(
GraphPtr graph)
872 const unsigned int numOutputs = graph->outputIds()->size();
873 m_OutputBindings.clear();
874 m_OutputBindings.reserve(numOutputs);
876 for (
unsigned int i = 0; i < numOutputs; i++)
878 unsigned int outputLayerIndex = 0xFFFFFFFF;
879 if (GetFeatureVersions(graph).m_BindingIdScheme == 0)
881 const unsigned int outputId = boost::numeric_cast<
unsigned int>(graph->outputIds()->Get(i));
882 outputLayerIndex = GetLayerIndexInVector(graph, outputId);
886 const int outputId = graph->outputIds()->Get(i);
887 outputLayerIndex = GetOutputLayerInVector(graph, outputId);
894 BOOST_ASSERT_MSG(baseLayer->layerName()->c_str(),
"Input has no name.");
897 m_Network->AddOutputLayer(bindingId, baseLayer->layerName()->c_str());
899 RegisterInputSlots(graph, outputLayerIndex, outputLayer);
901 unsigned int sourceLayerIndex =
902 GetLayerIndexInVector(graph, baseLayer->inputSlots()->Get(0)->connection()->sourceLayerIndex());
907 m_OutputBindings.push_back(std::make_pair(baseLayer->layerName()->c_str(), bindingInfo));
911 void Deserializer::RegisterOutputSlots(
GraphPtr graph,
916 BOOST_ASSERT(layer !=
nullptr);
921 boost::str(boost::format(
"The number of outputslots (%1%) does not match the number expected (%2%)" 922 " for layer index: %3% %4%") %
923 baseLayer->outputSlots()->size() %
931 const unsigned int slotIndex = baseLayer->outputSlots()->Get(i)->index();
934 RegisterOutputSlotOfConnection(baseLayer->index(), slotIndex, outputSlot);
938 void Deserializer::RegisterInputSlots(
GraphPtr graph,
943 BOOST_ASSERT(layer !=
nullptr);
948 boost::str(boost::format(
"The number of inputslots (%1%) does not match the number expected (%2%)" 949 " for layer index:%3% %4%") %
950 baseLayer->inputSlots()->size() %
958 auto fbInputSlot = baseLayer->inputSlots()->Get(i);
959 auto fbConnection = fbInputSlot->connection();
961 RegisterInputSlotOfConnection(fbConnection->sourceLayerIndex(), fbConnection->outputSlotIndex(), inputSlot);
965 void Deserializer::RegisterInputSlotOfConnection(uint32_t sourceLayerIndex,
966 uint32_t outputSlotIndex,
969 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
971 m_GraphConnections[sourceLayerIndex] = Connections();
974 Connections& connections = m_GraphConnections[sourceLayerIndex];
975 if (connections.inputSlots.find(outputSlotIndex) == connections.inputSlots.end())
977 connections.inputSlots[outputSlotIndex] = {inputSlot};
981 connections.inputSlots[outputSlotIndex].push_back(inputSlot);
985 void Deserializer::RegisterOutputSlotOfConnection(uint32_t sourceLayerIndex,
986 uint32_t outputSlotIndex,
989 if (m_GraphConnections.find(sourceLayerIndex) == m_GraphConnections.end())
991 m_GraphConnections[sourceLayerIndex] = Connections();
994 Connections& connections = m_GraphConnections[sourceLayerIndex];
995 if (connections.outputSlots.find(outputSlotIndex) != connections.outputSlots.end())
1000 connections.outputSlots[outputSlotIndex] = outputSlot;
1006 auto inputs =
GetInputs(graph, layerIndex);
1010 auto outputs =
GetOutputs(graph, layerIndex);
1016 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1020 RegisterInputSlots(graph, layerIndex, layer);
1021 RegisterOutputSlots(graph, layerIndex, layer);
1024 void Deserializer::ParseActivation(
GraphPtr graph,
unsigned int layerIndex)
1027 auto inputs =
GetInputs(graph, layerIndex);
1031 auto outputs =
GetOutputs(graph, layerIndex);
1034 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ActivationLayer();
1036 auto serializerDescriptor = serializerLayer->descriptor();
1040 descriptor.
m_A = serializerDescriptor->a();
1041 descriptor.
m_B = serializerDescriptor->b();
1048 RegisterInputSlots(graph, layerIndex, layer);
1049 RegisterOutputSlots(graph, layerIndex, layer);
1052 void Deserializer::ParseAdd(
GraphPtr graph,
unsigned int layerIndex)
1055 auto inputs =
GetInputs(graph, layerIndex);
1059 auto outputs =
GetOutputs(graph, layerIndex);
1068 RegisterInputSlots(graph, layerIndex, layer);
1069 RegisterOutputSlots(graph, layerIndex, layer);
1072 void Deserializer::ParseArgMinMax(
GraphPtr graph,
unsigned int layerIndex)
1075 auto inputs =
GetInputs(graph, layerIndex);
1079 auto outputs =
GetOutputs(graph, layerIndex);
1082 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ArgMinMaxLayer();
1083 auto serializerDescriptor = serializerLayer->descriptor();
1087 descriptor.
m_Axis = serializerDescriptor->axis();
1089 IConnectableLayer* layer = m_Network->AddArgMinMaxLayer(descriptor, layerName.c_str());
1094 RegisterInputSlots(graph, layerIndex, layer);
1095 RegisterOutputSlots(graph, layerIndex, layer);
1098 void Deserializer::ParseBatchToSpaceNd(
GraphPtr graph,
unsigned int layerIndex)
1108 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_BatchToSpaceNdLayer()->descriptor();
1109 auto flatBufferCrops = flatBufferDescriptor->crops();
1110 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
1112 if (flatBufferCrops->Length() % 2 != 0)
1115 boost::format(
"The size of crops must be divisible by 2 %1%") %
CHECK_LOCATION().AsString()));
1118 std::vector<std::pair<unsigned int, unsigned int>> crops;
1119 crops.reserve(flatBufferCrops->Length() / 2);
1120 for (
unsigned int i = 0; i < flatBufferCrops->Length() - 1; i += 2)
1122 crops.emplace_back(flatBufferCrops->Get(i), flatBufferCrops->Get(i+1));
1128 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
1132 IConnectableLayer* layer = m_Network->AddBatchToSpaceNdLayer(descriptor, layerName.c_str());
1137 RegisterInputSlots(graph, layerIndex, layer);
1138 RegisterOutputSlots(graph, layerIndex, layer);
1141 void Deserializer::ParseBatchNormalization(
GraphPtr graph,
unsigned int layerIndex)
1145 auto inputs =
GetInputs(graph, layerIndex);
1148 auto outputs =
GetOutputs(graph, layerIndex);
1154 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_BatchNormalizationLayer();
1155 auto serializerDescriptor = serializerLayer->descriptor();
1158 descriptor.
m_Eps = serializerDescriptor->eps();
1172 layer->GetOutputSlot(0).SetTensorInfo(outputInfo);
1174 RegisterInputSlots(graph, layerIndex, layer);
1175 RegisterOutputSlots(graph, layerIndex, layer);
1178 void Deserializer::ParseConstant(
GraphPtr graph,
unsigned int layerIndex)
1183 auto outputs =
GetOutputs(graph, layerIndex);
1188 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_ConstantLayer();
1189 auto serializerInput = serializerLayer->input();
1193 IConnectableLayer* layer = m_Network->AddConstantLayer(input, layerName.c_str());
1198 RegisterOutputSlots(graph, layerIndex, layer);
1201 void Deserializer::ParseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1204 auto inputs =
GetInputs(graph, layerIndex);
1208 auto outputs =
GetOutputs(graph, layerIndex);
1211 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_Convolution2dLayer();
1213 auto serializerDescriptor = serializerLayer->descriptor();
1216 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1217 descriptor.
m_PadRight = serializerDescriptor->padRight();
1218 descriptor.
m_PadTop = serializerDescriptor->padTop();
1219 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1220 descriptor.
m_StrideX = serializerDescriptor->strideX();
1221 descriptor.
m_StrideY = serializerDescriptor->strideY();;
1222 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1223 descriptor.
m_DilationY = serializerDescriptor->dilationY();;
1224 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
1241 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1243 RegisterInputSlots(graph, layerIndex, layer);
1244 RegisterOutputSlots(graph, layerIndex, layer);
1247 void Deserializer::ParseDepthToSpace(
GraphPtr graph,
unsigned int layerIndex)
1251 auto inputs =
GetInputs(graph, layerIndex);
1254 auto outputs =
GetOutputs(graph, layerIndex);
1257 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_DepthToSpaceLayer()->descriptor();
1260 descriptor.
m_BlockSize = fbDescriptor->blockSize();
1264 IConnectableLayer* layer = m_Network->AddDepthToSpaceLayer(descriptor, layerName.c_str());
1269 RegisterInputSlots(graph, layerIndex, layer);
1270 RegisterOutputSlots(graph, layerIndex, layer);
1273 void Deserializer::ParseDepthwiseConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
1276 auto inputs =
GetInputs(graph, layerIndex);
1280 auto outputs =
GetOutputs(graph, layerIndex);
1283 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer();
1285 auto serializerDescriptor = serializerLayer->descriptor();
1288 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
1289 descriptor.
m_PadRight = serializerDescriptor->padRight();
1290 descriptor.
m_PadTop = serializerDescriptor->padTop();
1291 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
1292 descriptor.
m_StrideX = serializerDescriptor->strideX();
1293 descriptor.
m_StrideY = serializerDescriptor->strideY();
1294 descriptor.
m_DilationX = serializerDescriptor->dilationX();
1295 descriptor.
m_DilationY = serializerDescriptor->dilationY();
1296 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
1308 IConnectableLayer* layer = m_Network->AddDepthwiseConvolution2dLayer(descriptor,
1314 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1316 RegisterInputSlots(graph, layerIndex, layer);
1317 RegisterOutputSlots(graph, layerIndex, layer);
1320 void Deserializer::ParseDetectionPostProcess(
GraphPtr graph,
unsigned int layerIndex)
1323 auto inputs =
GetInputs(graph, layerIndex);
1327 auto outputs =
GetOutputs(graph, layerIndex);
1330 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_DetectionPostProcessLayer();
1332 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1340 descriptor.
m_NumClasses = flatBufferDescriptor->numClasses();
1342 descriptor.
m_ScaleX = flatBufferDescriptor->scaleX();
1343 descriptor.
m_ScaleY = flatBufferDescriptor->scaleY();
1344 descriptor.
m_ScaleW = flatBufferDescriptor->scaleW();
1345 descriptor.
m_ScaleH = flatBufferDescriptor->scaleH();
1353 for (
unsigned int i = 0; i < 4; i++)
1355 layer->GetOutputSlot(i).SetTensorInfo(
ToTensorInfo(outputs[i]));
1358 RegisterInputSlots(graph, layerIndex, layer);
1359 RegisterOutputSlots(graph, layerIndex, layer);
1362 void Deserializer::ParseDivision(
GraphPtr graph,
unsigned int layerIndex)
1365 auto inputs =
GetInputs(graph, layerIndex);
1369 auto outputs =
GetOutputs(graph, layerIndex);
1378 RegisterInputSlots(graph, layerIndex, layer);
1379 RegisterOutputSlots(graph, layerIndex, layer);
1382 void Deserializer::ParseEqual(
GraphPtr graph,
unsigned int layerIndex)
1385 auto inputs =
GetInputs(graph, layerIndex);
1389 auto outputs =
GetOutputs(graph, layerIndex);
1394 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1399 RegisterInputSlots(graph, layerIndex, layer);
1400 RegisterOutputSlots(graph, layerIndex, layer);
1403 void Deserializer::ParseGreater(
GraphPtr graph,
unsigned int layerIndex)
1406 auto inputs =
GetInputs(graph, layerIndex);
1410 auto outputs =
GetOutputs(graph, layerIndex);
1415 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1420 RegisterInputSlots(graph, layerIndex, layer);
1421 RegisterOutputSlots(graph, layerIndex, layer);
1424 void Deserializer::ParseInstanceNormalization(
GraphPtr graph,
unsigned int layerIndex)
1428 auto inputs =
GetInputs(graph, layerIndex);
1431 auto outputs =
GetOutputs(graph, layerIndex);
1434 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_InstanceNormalizationLayer();
1435 auto fbDescriptor = fbLayer->descriptor();
1438 descriptor.
m_Gamma = fbDescriptor->gamma();
1439 descriptor.
m_Beta = fbDescriptor->beta();
1440 descriptor.
m_Eps = fbDescriptor->eps();
1443 const std::string layerName =
GetLayerName(graph, layerIndex);
1446 IConnectableLayer* layer = m_Network->AddInstanceNormalizationLayer(descriptor, layerName.c_str());
1449 RegisterInputSlots(graph, layerIndex, layer);
1450 RegisterOutputSlots(graph, layerIndex, layer);
1453 void Deserializer::ParseL2Normalization(
GraphPtr graph,
unsigned int layerIndex)
1457 auto inputs =
GetInputs(graph, layerIndex);
1460 auto outputs =
GetOutputs(graph, layerIndex);
1464 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_L2NormalizationLayer();
1465 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1470 descriptor.
m_Eps = flatBufferDescriptor->eps();
1472 IConnectableLayer* layer = m_Network->AddL2NormalizationLayer(descriptor, layerName.c_str());
1475 RegisterInputSlots(graph, layerIndex, layer);
1476 RegisterOutputSlots(graph, layerIndex, layer);
1479 void Deserializer::ParseLogSoftmax(
GraphPtr graph,
unsigned int layerIndex)
1490 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->beta();
1491 descriptor.m_Axis = graph->layers()->Get(layerIndex)->layer_as_LogSoftmaxLayer()->descriptor()->axis();
1494 IConnectableLayer* layer = m_Network->AddLogSoftmaxLayer(descriptor, layerName.c_str());
1499 RegisterInputSlots(graph, layerIndex, layer);
1500 RegisterOutputSlots(graph, layerIndex, layer);
1503 void Deserializer::ParseMinimum(
GraphPtr graph,
unsigned int layerIndex)
1506 auto inputs =
GetInputs(graph, layerIndex);
1510 auto outputs =
GetOutputs(graph, layerIndex);
1519 RegisterInputSlots(graph, layerIndex, layer);
1520 RegisterOutputSlots(graph, layerIndex, layer);
1523 void Deserializer::ParseMaximum(
GraphPtr graph,
unsigned int layerIndex)
1526 auto inputs =
GetInputs(graph, layerIndex);
1530 auto outputs =
GetOutputs(graph, layerIndex);
1539 RegisterInputSlots(graph, layerIndex, layer);
1540 RegisterOutputSlots(graph, layerIndex, layer);
1544 unsigned int layerIndex)
1546 auto layerType = graph->layers()->Get(layerIndex)->layer_type();
1550 case Layer::Layer_ConcatLayer:
1551 return graph->layers()->Get(layerIndex)->layer_as_ConcatLayer()->descriptor();
1552 case Layer::Layer_MergerLayer:
1553 return graph->layers()->Get(layerIndex)->layer_as_MergerLayer()->descriptor();
1559 void Deserializer::ParseComparison(
GraphPtr graph,
unsigned int layerIndex)
1564 auto inputs =
GetInputs(graph, layerIndex);
1567 auto outputs =
GetOutputs(graph, layerIndex);
1570 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ComparisonLayer();
1571 auto fbDescriptor = fbLayer->descriptor();
1576 const std::string& layerName =
GetLayerName(graph, layerIndex);
1577 IConnectableLayer* layer = m_Network->AddComparisonLayer(descriptor, layerName.c_str());
1582 RegisterInputSlots(graph, layerIndex, layer);
1583 RegisterOutputSlots(graph, layerIndex, layer);
1586 void Deserializer::ParseElementwiseUnary(
GraphPtr graph,
unsigned int layerIndex)
1591 auto inputs =
GetInputs(graph, layerIndex);
1594 auto outputs =
GetOutputs(graph, layerIndex);
1597 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_ElementwiseUnaryLayer();
1598 auto fbDescriptor = fbLayer->descriptor();
1603 const std::string& layerName =
GetLayerName(graph, layerIndex);
1604 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
1609 RegisterInputSlots(graph, layerIndex, layer);
1610 RegisterOutputSlots(graph, layerIndex, layer);
1613 void Deserializer::ParseConcat(
GraphPtr graph,
unsigned int layerIndex)
1618 auto outputs =
GetOutputs(graph, layerIndex);
1623 unsigned int numViews = originsDescriptor->numViews();
1624 unsigned int numDimensions = originsDescriptor->numDimensions();
1627 auto inputs =
GetInputs(graph, layerIndex);
1631 auto originsPtr = originsDescriptor->viewOrigins();
1632 for (
unsigned int v = 0; v < numViews; ++v)
1634 auto originPtr = originsPtr->Get(v);
1635 for (
unsigned int d = 0; d < numDimensions; ++d)
1637 uint32_t value = originPtr->data()->Get(d);
1638 descriptor.SetViewOriginCoord(v, d, value);
1641 descriptor.SetConcatAxis(originsDescriptor->concatAxis());
1643 IConnectableLayer* layer = m_Network->AddConcatLayer(descriptor, layerName.c_str());
1647 RegisterInputSlots(graph, layerIndex, layer);
1648 RegisterOutputSlots(graph, layerIndex, layer);
1651 void Deserializer::ParseMultiplication(
GraphPtr graph,
unsigned int layerIndex)
1654 auto inputs =
GetInputs(graph, layerIndex);
1658 auto outputs =
GetOutputs(graph, layerIndex);
1662 IConnectableLayer* layer = m_Network->AddMultiplicationLayer(layerName.c_str());
1667 RegisterInputSlots(graph, layerIndex, layer);
1668 RegisterOutputSlots(graph, layerIndex, layer);
1671 void Deserializer::ParseFloor(
GraphPtr graph,
unsigned int layerIndex)
1676 auto inputs =
GetInputs(graph, layerIndex);
1679 auto outputs =
GetOutputs(graph, layerIndex);
1686 layer = m_Network->AddFloorLayer(layerName.c_str());
1691 RegisterInputSlots(graph, layerIndex, layer);
1692 RegisterOutputSlots(graph, layerIndex, layer);
1695 void Deserializer::ParseFullyConnected(
GraphPtr graph,
unsigned int layerIndex)
1698 auto inputs =
GetInputs(graph, layerIndex);
1702 auto outputs =
GetOutputs(graph, layerIndex);
1705 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer();
1707 auto flatBufferDescriptor = flatBufferLayer->descriptor();
1710 fullyConnectedDescriptor.
m_BiasEnabled = flatBufferDescriptor->biasEnabled();
1717 if (flatBufferDescriptor->biasEnabled())
1722 layer = m_Network->AddFullyConnectedLayer(fullyConnectedDescriptor,
1728 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
1730 RegisterInputSlots(graph, layerIndex, layer);
1731 RegisterOutputSlots(graph, layerIndex, layer);
1734 void Deserializer::ParsePad(
GraphPtr graph,
unsigned int layerIndex)
1744 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_PadLayer()->descriptor();
1745 auto flatBufferPadList = flatBufferDescriptor->padList();
1746 float padValue = flatBufferDescriptor->padValue();
1748 if (flatBufferPadList->Length() % 2 != 0)
1751 boost::format(
"The size of the pad list must be divisible by 2 %1%") %
CHECK_LOCATION().AsString()));
1754 std::vector<std::pair<unsigned int, unsigned int>> padList;
1755 padList.reserve(flatBufferPadList->Length() / 2);
1756 for (
unsigned int i = 0; i < flatBufferPadList->Length() - 1; i += 2)
1758 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
1764 IConnectableLayer* layer = m_Network->AddPadLayer(descriptor, layerName.c_str());
1769 RegisterInputSlots(graph, layerIndex, layer);
1770 RegisterOutputSlots(graph, layerIndex, layer);
1773 void Deserializer::ParsePermute(
GraphPtr graph,
unsigned int layerIndex)
1778 graph->layers()->Get(layerIndex)->layer_as_PermuteLayer()->descriptor()->dimMappings();
1780 auto inputs =
GetInputs(graph, layerIndex);
1783 auto outputs =
GetOutputs(graph, layerIndex);
1790 IConnectableLayer* layer = m_Network->AddPermuteLayer(descriptor, layerName.c_str());
1793 RegisterInputSlots(graph, layerIndex, layer);
1794 RegisterOutputSlots(graph, layerIndex, layer);
1798 unsigned int layerIndex)
1800 boost::ignore_unused(layerIndex);
1803 switch (pooling2dDesc->poolType())
1805 case PoolingAlgorithm_Average:
1810 case PoolingAlgorithm_Max:
1817 BOOST_ASSERT_MSG(
false,
"Unsupported pooling algorithm");
1821 switch (pooling2dDesc->outputShapeRounding())
1823 case OutputShapeRounding_Floor:
1828 case OutputShapeRounding_Ceiling:
1835 BOOST_ASSERT_MSG(
false,
"Unsupported output shape rounding");
1839 switch (pooling2dDesc->paddingMethod())
1841 case PaddingMethod_Exclude:
1846 case PaddingMethod_IgnoreValue:
1853 BOOST_ASSERT_MSG(
false,
"Unsupported padding method");
1857 switch (pooling2dDesc->dataLayout())
1859 case DataLayout_NCHW:
1864 case DataLayout_NHWC:
1871 BOOST_ASSERT_MSG(
false,
"Unsupported data layout");
1876 desc.
m_PadLeft = pooling2dDesc->padLeft();
1878 desc.
m_PadTop = pooling2dDesc->padTop();
1879 desc.
m_StrideX = pooling2dDesc->strideX();
1880 desc.
m_StrideY = pooling2dDesc->strideY();
1887 void Deserializer::ParsePooling2d(
GraphPtr graph,
unsigned int layerIndex)
1891 auto pooling2dDes = graph->layers()->Get(layerIndex)->layer_as_Pooling2dLayer()->descriptor();
1892 auto inputs =
GetInputs(graph, layerIndex);
1895 auto outputs =
GetOutputs(graph, layerIndex);
1901 IConnectableLayer* layer = m_Network->AddPooling2dLayer(pooling2dDescriptor, layerName.c_str());
1904 RegisterInputSlots(graph, layerIndex, layer);
1905 RegisterOutputSlots(graph, layerIndex, layer);
1908 void Deserializer::ParseQuantize(
GraphPtr graph,
unsigned int layerIndex)
1912 auto inputs =
GetInputs(graph, layerIndex);
1915 auto outputs =
GetOutputs(graph, layerIndex);
1923 RegisterInputSlots(graph, layerIndex, layer);
1924 RegisterOutputSlots(graph, layerIndex, layer);
1928 const std::vector<uint32_t>& targetDimsIn)
1930 std::vector<unsigned int> outputDims(targetDimsIn.begin(), targetDimsIn.end());
1931 const auto stretchDim = std::find(targetDimsIn.begin(), targetDimsIn.end(), -1);
1933 if (stretchDim != targetDimsIn.end())
1935 if (std::find(std::next(stretchDim), targetDimsIn.end(), -1) != targetDimsIn.end())
1938 boost::format(
"At most one component of shape can be -1 %1%") %
CHECK_LOCATION().AsString()));
1941 auto targetNumElements =
1942 boost::numeric_cast<
unsigned int>(
1943 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
1945 auto stretchIndex =
static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
1946 outputDims[stretchIndex] = inputTensorInfo.
GetNumElements() / targetNumElements;
1957 void Deserializer::ParseReshape(
GraphPtr graph,
unsigned int layerIndex)
1960 auto inputs =
GetInputs(graph, layerIndex);
1962 auto outputs =
GetOutputs(graph, layerIndex);
1968 const auto targetDims = graph->layers()->Get(layerIndex)->layer_as_ReshapeLayer()->descriptor()->targetShape();
1969 std::vector<uint32_t> outputDims(targetDims->begin(), targetDims->begin() + targetDims->size());
1972 const armnn::TensorShape& reshapeOutputTensorShape = reshapeOutputTensorInfo.GetShape();
1974 const std::vector<uint32_t> expectedDims(outputs[0]->dimensions()->begin(),
1975 outputs[0]->dimensions()->begin() + outputs[0]->dimensions()->size());
1977 if (inputs.size() > 1 && !
CheckShape(reshapeOutputTensorShape, expectedDims))
1979 std::stringstream ss;
1980 ss <<
"New shape defined in reshape parameters " 1981 << reshapeOutputTensorShape
1982 <<
" does not equal output shape " 1983 << actualOutputTensorInfo.
GetShape()
1993 IConnectableLayer* layer = m_Network->AddReshapeLayer(reshapeDesc, layerName.c_str());
1996 RegisterInputSlots(graph, layerIndex, layer);
1997 RegisterOutputSlots(graph, layerIndex, layer);
2000 void Deserializer::ParseResize(
GraphPtr graph,
unsigned int layerIndex)
2010 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeLayer()->descriptor();
2013 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2014 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2019 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2024 RegisterInputSlots(graph, layerIndex, layer);
2025 RegisterOutputSlots(graph, layerIndex, layer);
2028 void Deserializer::ParseResizeBilinear(
GraphPtr graph,
unsigned int layerIndex)
2038 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_ResizeBilinearLayer()->descriptor();
2041 descriptor.
m_TargetWidth = flatBufferDescriptor->targetWidth();
2042 descriptor.
m_TargetHeight = flatBufferDescriptor->targetHeight();
2047 IConnectableLayer* layer = m_Network->AddResizeLayer(descriptor, layerName.c_str());
2052 RegisterInputSlots(graph, layerIndex, layer);
2053 RegisterOutputSlots(graph, layerIndex, layer);
2056 void Deserializer::ParseSoftmax(
GraphPtr graph,
unsigned int layerIndex)
2067 descriptor.
m_Beta = graph->layers()->Get(layerIndex)->layer_as_SoftmaxLayer()->descriptor()->beta();
2070 IConnectableLayer* layer = m_Network->AddSoftmaxLayer(descriptor, layerName.c_str());
2075 RegisterInputSlots(graph, layerIndex, layer);
2076 RegisterOutputSlots(graph, layerIndex, layer);
2079 void Deserializer::ParseSpaceToBatchNd(
GraphPtr graph,
unsigned int layerIndex)
2089 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToBatchNdLayer()->descriptor();
2090 auto flatBufferPadList = flatBufferDescriptor->padList();
2091 auto flatBufferBlockShape = flatBufferDescriptor->blockShape();
2093 if (flatBufferPadList->Length() % 2 != 0)
2096 boost::format(
"The size of the pad list must be divisible by 2 %1%") %
CHECK_LOCATION().AsString()));
2099 std::vector<std::pair<unsigned int, unsigned int>> padList;
2100 padList.reserve(flatBufferPadList->Length() / 2);
2101 for (
unsigned int i = 0; i < flatBufferPadList->Length() - 1; i += 2)
2103 padList.emplace_back(flatBufferPadList->Get(i), flatBufferPadList->Get(i+1));
2109 std::vector<unsigned int>(flatBufferBlockShape->begin(), flatBufferBlockShape->end());
2113 IConnectableLayer* layer = m_Network->AddSpaceToBatchNdLayer(descriptor, layerName.c_str());
2118 RegisterInputSlots(graph, layerIndex, layer);
2119 RegisterOutputSlots(graph, layerIndex, layer);
2122 void Deserializer::ParseSpaceToDepth(
GraphPtr graph,
unsigned int layerIndex)
2132 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_SpaceToDepthLayer()->descriptor();
2135 descriptor.
m_BlockSize = flatBufferDescriptor->blockSize();
2139 IConnectableLayer* layer = m_Network->AddSpaceToDepthLayer(descriptor, layerName.c_str());
2144 RegisterInputSlots(graph, layerIndex, layer);
2145 RegisterOutputSlots(graph, layerIndex, layer);
2150 unsigned int layerIndex)
2152 boost::ignore_unused(layerIndex);
2155 switch (normalizationDescriptor->normChannelType())
2157 case NormalizationAlgorithmChannel_Across:
2162 case NormalizationAlgorithmChannel_Within:
2169 BOOST_ASSERT_MSG(
false,
"Unsupported normalization channel type");
2173 switch (normalizationDescriptor->normMethodType())
2175 case NormalizationAlgorithmMethod_LocalBrightness:
2180 case NormalizationAlgorithmMethod_LocalContrast:
2187 BOOST_ASSERT_MSG(
false,
"Unsupported normalization method type");
2191 switch (normalizationDescriptor->dataLayout())
2193 case DataLayout_NCHW:
2198 case DataLayout_NHWC:
2205 BOOST_ASSERT_MSG(
false,
"Unsupported data layout");
2209 desc.
m_Alpha = normalizationDescriptor->alpha();
2210 desc.
m_Beta = normalizationDescriptor->beta();
2211 desc.
m_K = normalizationDescriptor->k();
2212 desc.
m_NormSize = normalizationDescriptor->normSize();
2217 void Deserializer::ParseNormalization(
GraphPtr graph,
unsigned int layerIndex)
2221 auto normalizationDes = graph->layers()->Get(layerIndex)->layer_as_NormalizationLayer()->descriptor();
2234 IConnectableLayer* layer = m_Network->AddNormalizationLayer(normalizationDescriptor, layerName.c_str());
2237 RegisterInputSlots(graph, layerIndex, layer);
2238 RegisterOutputSlots(graph, layerIndex, layer);
2241 void Deserializer::ParseRsqrt(
GraphPtr graph,
unsigned int layerIndex)
2244 auto inputs =
GetInputs(graph, layerIndex);
2248 auto outputs =
GetOutputs(graph, layerIndex);
2254 IConnectableLayer* layer = m_Network->AddElementwiseUnaryLayer(descriptor, layerName.c_str());
2258 RegisterInputSlots(graph, layerIndex, layer);
2259 RegisterOutputSlots(graph, layerIndex, layer);
2262 void Deserializer::ParseSlice(
GraphPtr graph,
unsigned int layerIndex)
2266 auto inputs =
GetInputs(graph, layerIndex);
2269 auto outputs =
GetOutputs(graph, layerIndex);
2272 auto fbDescriptor = graph->layers()->Get(layerIndex)->layer_as_SliceLayer()->descriptor();
2274 auto fbBegin = fbDescriptor->begin();
2275 auto fbSize = fbDescriptor->size();
2277 if (fbBegin->Length() != fbSize->Length())
2280 boost::format(
"Begin and size descriptors must have the same length %1%") %
CHECK_LOCATION().AsString()));
2284 descriptor.
m_Begin.insert(descriptor.
m_Begin.end(), fbBegin->begin(), fbBegin->end());
2285 descriptor.
m_Size.insert(descriptor.
m_Size.end(), fbSize->begin(), fbSize->end());
2288 IConnectableLayer* layer = m_Network->AddSliceLayer(descriptor, layerName.c_str());
2293 RegisterInputSlots(graph, layerIndex, layer);
2294 RegisterOutputSlots(graph, layerIndex, layer);
2297 void Deserializer::ParseStridedSlice(
GraphPtr graph,
unsigned int layerIndex)
2307 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StridedSliceLayer()->descriptor();
2309 auto flatBufferBegin = flatBufferDescriptor->begin();
2310 auto flatBufferEnd = flatBufferDescriptor->end();
2311 auto flatBufferStride = flatBufferDescriptor->stride();
2313 if (!(flatBufferBegin->Length() == flatBufferEnd->Length() &&
2314 flatBufferBegin->Length() == flatBufferStride->Length()))
2317 boost::format(
"The size of the begin, end, and stride must be equal %1%") %
CHECK_LOCATION().AsString()));
2320 std::vector<int> begin(flatBufferBegin->begin(), flatBufferBegin->end());
2321 std::vector<int> end(flatBufferEnd->begin(), flatBufferEnd->end());
2322 std::vector<int> stride(flatBufferStride->begin(), flatBufferStride->end());
2325 descriptor.m_BeginMask = flatBufferDescriptor->beginMask();
2326 descriptor.m_EndMask = flatBufferDescriptor->endMask();
2327 descriptor.m_ShrinkAxisMask = flatBufferDescriptor->shrinkAxisMask();
2328 descriptor.m_EllipsisMask = flatBufferDescriptor->ellipsisMask();
2329 descriptor.m_NewAxisMask = flatBufferDescriptor->newAxisMask();
2330 descriptor.m_DataLayout =
ToDataLayout(flatBufferDescriptor->dataLayout());
2333 IConnectableLayer* layer = m_Network->AddStridedSliceLayer(descriptor, layerName.c_str());
2338 RegisterInputSlots(graph, layerIndex, layer);
2339 RegisterOutputSlots(graph, layerIndex, layer);
2342 void Deserializer::ParseSubtraction(
GraphPtr graph,
unsigned int layerIndex)
2345 auto inputs =
GetInputs(graph, layerIndex);
2349 auto outputs =
GetOutputs(graph, layerIndex);
2358 RegisterInputSlots(graph, layerIndex, layer);
2359 RegisterOutputSlots(graph, layerIndex, layer);
2362 void Deserializer::ParseGather(
GraphPtr graph,
unsigned int layerIndex)
2378 RegisterInputSlots(graph, layerIndex, layer);
2379 RegisterOutputSlots(graph, layerIndex, layer);
2382 void Deserializer::ParseMean(
GraphPtr graph,
unsigned int layerIndex)
2392 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_MeanLayer()->descriptor();
2393 auto flatBufferAxis = flatBufferDescriptor->axis();
2394 auto flatBufferKeepDims = flatBufferDescriptor->keepDims();
2397 descriptor.
m_Axis = std::vector<unsigned int>(flatBufferAxis->begin(), flatBufferAxis->end());
2401 IConnectableLayer* layer = m_Network->AddMeanLayer(descriptor, layerName.c_str());
2406 RegisterInputSlots(graph, layerIndex, layer);
2407 RegisterOutputSlots(graph, layerIndex, layer);
2410 void Deserializer::ParseSplitter(
GraphPtr graph,
unsigned int layerIndex)
2419 auto flatBufferViewsDescriptor = graph->layers()->Get(layerIndex)->layer_as_SplitterLayer()->descriptor();
2420 auto flatBufferViewSizes = flatBufferViewsDescriptor->viewSizes();
2421 auto flatBufferOriginsDescriptor = flatBufferViewsDescriptor->origins();
2422 auto flatBufferViewOrigins = flatBufferOriginsDescriptor->viewOrigins();
2423 uint32_t numViews = flatBufferOriginsDescriptor->numViews();
2424 uint32_t numDimensions = flatBufferOriginsDescriptor->numDimensions();
2431 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
2433 for (
unsigned int dIdx = 0; dIdx < numDimensions; ++dIdx)
2435 viewsDescriptor.
SetViewSize(vIdx, dIdx, flatBufferViewSizes->Get(vIdx)->data()->Get(dIdx));
2436 viewsDescriptor.
SetViewOriginCoord(vIdx, dIdx, flatBufferViewOrigins->Get(vIdx)->data()->Get(dIdx));
2441 IConnectableLayer* layer = m_Network->AddSplitterLayer(viewsDescriptor, layerName.c_str());
2444 for(
unsigned int vIdx = 0; vIdx < numViews; ++vIdx)
2450 RegisterInputSlots(graph, layerIndex, layer);
2451 RegisterOutputSlots(graph, layerIndex, layer);
2469 void Deserializer::ParseLstm(
GraphPtr graph,
unsigned int layerIndex)
2473 auto inputs =
GetInputs(graph, layerIndex);
2476 auto outputs =
GetOutputs(graph, layerIndex);
2479 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_LstmLayer();
2481 auto flatBufferDescriptor = flatBufferLayer->descriptor();
2482 auto flatBufferInputParams = flatBufferLayer->inputParams();
2512 if (!lstmDescriptor.m_CifgEnabled)
2514 inputToInputWeights =
ToConstTensor(flatBufferInputParams->inputToInputWeights());
2515 recurrentToInputWeights =
ToConstTensor(flatBufferInputParams->recurrentToInputWeights());
2516 cellToInputWeights =
ToConstTensor(flatBufferInputParams->cellToInputWeights());
2517 inputGateBias =
ToConstTensor(flatBufferInputParams->inputGateBias());
2527 if (lstmDescriptor.m_ProjectionEnabled)
2529 projectionWeights =
ToConstTensor(flatBufferInputParams->projectionWeights());
2530 projectionBias =
ToConstTensor(flatBufferInputParams->projectionBias());
2538 if (lstmDescriptor.m_PeepholeEnabled)
2540 cellToForgetWeights =
ToConstTensor(flatBufferInputParams->cellToForgetWeights());
2541 cellToOutputWeights =
ToConstTensor(flatBufferInputParams->cellToOutputWeights());
2551 if (lstmDescriptor.m_LayerNormEnabled)
2553 if (!lstmDescriptor.m_CifgEnabled)
2555 inputLayerNormWeights =
ToConstTensor(flatBufferInputParams->inputLayerNormWeights());
2558 forgetLayerNormWeights =
ToConstTensor(flatBufferInputParams->forgetLayerNormWeights());
2559 cellLayerNormWeights =
ToConstTensor(flatBufferInputParams->cellLayerNormWeights());
2560 outputLayerNormWeights =
ToConstTensor(flatBufferInputParams->outputLayerNormWeights());
2567 IConnectableLayer* layer = m_Network->AddLstmLayer(lstmDescriptor, lstmInputParams, layerName.c_str());
2581 RegisterInputSlots(graph, layerIndex, layer);
2582 RegisterOutputSlots(graph, layerIndex, layer);
2585 void Deserializer::ParseQuantizedLstm(
GraphPtr graph,
unsigned int layerIndex)
2589 auto inputs =
GetInputs(graph, layerIndex);
2592 auto outputs =
GetOutputs(graph, layerIndex);
2595 auto flatBufferLayer = graph->layers()->Get(layerIndex)->layer_as_QuantizedLstmLayer();
2597 auto flatBufferInputParams = flatBufferLayer->inputParams();
2627 IConnectableLayer* layer = m_Network->AddQuantizedLstmLayer(lstmInputParams, layerName.c_str());
2635 RegisterInputSlots(graph, layerIndex, layer);
2636 RegisterOutputSlots(graph, layerIndex, layer);
2639 void Deserializer::ParseDequantize(
GraphPtr graph,
unsigned int layerIndex)
2649 const std::string layerName =
GetLayerName(graph, layerIndex);
2655 RegisterInputSlots(graph, layerIndex, layer);
2656 RegisterOutputSlots(graph, layerIndex, layer);
2659 void Deserializer::ParseMerge(
GraphPtr graph,
unsigned int layerIndex)
2669 const std::string layerName =
GetLayerName(graph, layerIndex);
2675 RegisterInputSlots(graph, layerIndex, layer);
2676 RegisterOutputSlots(graph, layerIndex, layer);
2679 void Deserializer::ParseSwitch(
GraphPtr graph,
unsigned int layerIndex)
2682 auto inputs =
GetInputs(graph, layerIndex);
2686 auto outputs =
GetOutputs(graph, layerIndex);
2698 RegisterInputSlots(graph, layerIndex, layer);
2699 RegisterOutputSlots(graph, layerIndex, layer);
2702 void Deserializer::ParsePrelu(
GraphPtr graph,
unsigned int layerIndex)
2705 auto inputs =
GetInputs(graph, layerIndex);
2709 auto outputs =
GetOutputs(graph, layerIndex);
2718 RegisterInputSlots(graph, layerIndex, layer);
2719 RegisterOutputSlots(graph, layerIndex, layer);
2722 void Deserializer::ParseTransposeConvolution2d(
GraphPtr graph,
unsigned int layerIndex)
2726 auto inputs =
GetInputs(graph, layerIndex);
2729 auto outputs =
GetOutputs(graph, layerIndex);
2732 auto serializerLayer = graph->layers()->Get(layerIndex)->layer_as_TransposeConvolution2dLayer();
2734 auto serializerDescriptor = serializerLayer->descriptor();
2737 descriptor.
m_PadLeft = serializerDescriptor->padLeft();
2738 descriptor.
m_PadRight = serializerDescriptor->padRight();
2739 descriptor.
m_PadTop = serializerDescriptor->padTop();
2740 descriptor.
m_PadBottom = serializerDescriptor->padBottom();
2741 descriptor.
m_StrideX = serializerDescriptor->strideX();
2742 descriptor.
m_StrideY = serializerDescriptor->strideY();;
2743 descriptor.
m_BiasEnabled = serializerDescriptor->biasEnabled();;
2752 optionalBiases = armnn::MakeOptional<armnn::ConstTensor>(biases);
2755 IConnectableLayer* layer = m_Network->AddTransposeConvolution2dLayer(descriptor,
2761 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
2763 RegisterInputSlots(graph, layerIndex, layer);
2764 RegisterOutputSlots(graph, layerIndex, layer);
2767 void Deserializer::ParseStack(
GraphPtr graph,
unsigned int layerIndex)
2770 auto inputs =
GetInputs(graph, layerIndex);
2772 auto outputs =
GetOutputs(graph, layerIndex);
2775 auto flatBufferDescriptor = graph->layers()->Get(layerIndex)->layer_as_StackLayer()->descriptor();
2776 unsigned int axis = flatBufferDescriptor->axis();
2777 unsigned int numInputs = flatBufferDescriptor->numInputs();
2780 auto flatBufferInputShape = flatBufferDescriptor->inputShape();
2781 std::vector<uint32_t> vectorInputShape(flatBufferInputShape->begin(),
2782 flatBufferInputShape->begin() + flatBufferInputShape->size());
2784 TensorShape inputShape(static_cast<unsigned int>(vectorInputShape.size()), vectorInputShape.data());
2787 for (
unsigned int i=0; i<inputs.size(); ++i)
2790 if (descriptor.m_InputShape != inputShape)
2792 std::stringstream ss;
2793 ss <<
"Shape of input " 2797 <<
" does not equal defined input shape " 2798 << descriptor.m_InputShape
2806 IConnectableLayer* layer = m_Network->AddStackLayer(descriptor, layerName.c_str());
2811 RegisterInputSlots(graph, layerIndex, layer);
2812 RegisterOutputSlots(graph, layerIndex, layer);
2815 void Deserializer::ParseStandIn(
GraphPtr graph,
unsigned int layerIndex)
2819 auto inputs =
GetInputs(graph, layerIndex);
2820 auto outputs =
GetOutputs(graph, layerIndex);
2822 auto fbLayer = graph->layers()->Get(layerIndex)->layer_as_StandInLayer();
2823 auto fbDescriptor = fbLayer->descriptor();
2826 descriptor.
m_NumInputs = fbDescriptor->numInputs();
2832 const std::string layerName =
GetLayerName(graph, layerIndex);
2835 for (
unsigned int i = 0u; i < descriptor.
m_NumOutputs; ++i)
2841 RegisterInputSlots(graph, layerIndex, layer);
2842 RegisterOutputSlots(graph, layerIndex, layer);
armnn::ComparisonOperation ToComparisonOperation(armnnSerializer::ComparisonOperation operation)
#define CHECK_VALID_SIZE(ACTUAL,...)
float m_A
Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH).
bool m_ProjectionEnabled
Enable/disable the projection layer.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
std::string FileLine() const
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
float m_ScaleX
Center size encoding scale x.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
armnn::DataLayout ToDataLayout(armnnSerializer::DataLayout dataLayout)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
UnaryOperation m_Operation
Specifies the elementwiseUnary operation to execute.
uint32_t m_MaxClassesPerDetection
Maximum numbers of classes per detection, used in Fast NMS.
armnn::INetworkPtr CreateNetworkFromBinary(const std::vector< uint8_t > &binaryContent) override
Create an input network from binary file contents.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
unsigned int GetNumDimensions() const
uint32_t m_PadRight
Padding right value in the width dimension.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
static std::string GetLayerName(const GraphPtr &graph, unsigned int index)
uint32_t m_NumClasses
Number of classes.
uint32_t m_DilationX
Dilation factor value for width dimension.
A NormalizationDescriptor for the NormalizationLayer.
static armnn::TensorInfo OutputShapeOfReshape(const armnn::TensorInfo &inputTensorInfo, const std::vector< uint32_t > &targetDimsIn)
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
float m_Alpha
Alpha value for the normalization equation.
float m_ScaleW
Center size encoding scale weight.
uint32_t m_PadTop
Padding top value in the height dimension.
uint32_t m_NumOutputs
Number of output tensors.
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding values for the input dimension: heightPad{top, bottom} widthPad{left, right}.
float m_ClippingThresCell
Clipping threshold value for the cell state.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_TargetHeight
Target height value.
#define CHECK_CONST_TENSOR_SIZE(CONST_TENSOR_SIZE, TENSOR_SIZE)
float m_Gamma
Gamma, the scale scalar value applied for the normalized tensor. Defaults to 1.0. ...
std::vector< unsigned int > m_Axis
Values for the dimensions to reduce.
static armnn::Pooling2dDescriptor GetPoolingDescriptor(PoolingDescriptor pooling2dDescriptor, unsigned int layerIndex)
BindingPointInfo GetNetworkInputBindingInfo(unsigned int layerId, const std::string &name) const override
Retrieve binding info (layer id and tensor info) for the network input identified by the given layer ...
std::vector< TensorRawPtr > TensorRawPtrVector
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t m_PadTop
Padding top value in the height dimension.
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
A PadDescriptor for the PadLayer.
An ActivationDescriptor for the ActivationLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
uint32_t m_PadRight
Padding right value in the width dimension.
const armnnSerializer::LstmDescriptor * LstmDescriptorPtr
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Status SetViewSize(uint32_t view, uint32_t coord, uint32_t value)
Set the size of the views. The arguments are: view, dimension, value. If the view is greater than or ...
float m_ScaleY
Center size encoding scale y.
const armnnSerializer::SerializedGraph * GraphPtr
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
armnn::UnaryOperation ToUnaryOperation(armnnSerializer::UnaryOperation operation)
std::vector< unsigned int > m_BlockShape
Block shape value.
bool m_KeepDims
Enable/disable keep dimensions. If true, then the reduced dimensions that are of length 1 are kept...
uint32_t m_PadTop
Padding top value in the height dimension.
A L2NormalizationDescriptor for the L2NormalizationLayer.
bool m_BiasEnabled
Enable/disable bias.
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.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
ArgMinMaxFunction m_Function
Specify if the function is to find Min or Max.
static IDeserializer * CreateRaw()
#define CHECK_LAYERS(GRAPH, LAYERS_INDEX, LAYER_INDEX)
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
Krichevsky 2012: Local Brightness Normalization.
Jarret 2009: Local Contrast Normalization.
float m_Beta
Exponentiation value.
float m_Beta
Beta, the offset scalar value applied for the normalized tensor. Defaults to 1.0. ...
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
#define CHECKED_NON_NEGATIVE(VALUE)
bool m_UseRegularNms
Use Regular NMS.
static LayerBaseRawPtr GetBaseLayer(const GraphPtr &graphPtr, unsigned int layerIndex)
A ReshapeDescriptor for the ReshapeLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
const armnnSerializer::OriginsDescriptor * GetOriginsDescriptor(const armnnSerializer::SerializedGraph *graph, unsigned int layerIndex)
uint32_t m_PadTop
Padding top value in the height dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
TensorShape m_TargetShape
Target shape value.
uint32_t m_PadLeft
Padding left value in the width dimension.
int m_Axis
Axis to reduce across the input tensor.
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
uint32_t m_PoolWidth
Pooling width value.
bool m_PeepholeEnabled
Enable/disable peephole.
armnn::ArgMinMaxFunction ToArgMinMaxFunction(armnnSerializer::ArgMinMaxFunction function)
The padding fields count, but are ignored.
static TensorRawPtrVector GetOutputs(const GraphPtr &graph, unsigned int layerIndex)
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
armnn::ResizeMethod ToResizeMethod(armnnSerializer::ResizeMethod method)
float m_NmsIouThreshold
Intersection over union threshold.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
std::vector< unsigned int > m_Begin
Beginning indices of the slice in each dimension.
The padding fields don't count and are ignored.
uint32_t m_NormSize
Depth radius value.
float m_B
Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
static GraphPtr LoadGraphFromBinary(const uint8_t *binaryContent, size_t len)
uint32_t m_DetectionsPerClass
Detections per classes, used in Regular NMS.
armnn::ConstTensor ToConstTensor(Deserializer::ConstTensorRawPtr constTensorPtr)
const armnnSerializer::ConstTensor * ConstTensorRawPtr
const armnnSerializer::LayerBase * LayerBaseRawPtr
An LstmDescriptor for the LstmLayer.
virtual unsigned int GetNumOutputSlots() const =0
armnnSerializer::TensorInfo * TensorRawPtr
uint32_t m_PadLeft
Padding left value in the width dimension.
void CheckLayers(Graph &graph)
float m_Beta
Beta value for the normalization equation.
const armnnSerializer::NormalizationDescriptor * NormalizationDescriptorPtr
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
A FullyConnectedDescriptor for the FullyConnectedLayer.
bool CheckShape(const armnn::TensorShape &actual, const std::vector< uint32_t > &expected)
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
float m_Eps
Value to add to the variance. Used to avoid dividing by zero.
std::unique_ptr< IDeserializer, void(*)(IDeserializer *parser)> IDeserializerPtr
float m_NmsScoreThreshold
NMS score threshold.
void SetShape(const TensorShape &newShape)
static armnn::NormalizationDescriptor GetNormalizationDescriptor(NormalizationDescriptorPtr normalizationDescriptor, unsigned int layerIndex)
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
Base class for all ArmNN exceptions so that users can filter to just those.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
float m_Eps
Epsilon, small scalar value added to variance to avoid dividing by zero. Defaults to 1e-12f...
uint32_t m_PadRight
Padding right value in the width dimension.
bool m_BiasEnabled
Enable/disable bias.
const armnnSerializer::Pooling2dDescriptor * PoolingDescriptor
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
A StackDescriptor for the StackLayer.
uint32_t m_NumInputs
Number of input tensors.
ActivationFunction m_Function
The activation function to use (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square).
std::vector< unsigned int > m_Size
Size of the slice in each dimension.
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...
uint32_t m_TargetWidth
Target width value.
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
#define CHECK_GRAPH(GRAPH, LAYERS_INDEX)
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
ComparisonOperation m_Operation
Specifies the comparison operation to execute.
static IDeserializerPtr Create()
bool m_BiasEnabled
Enable/disable bias.
unsigned int m_BlockSize
Scalar specifying the input block size. It must be >= 1.
float m_K
Kappa value used for the across channel normalization equation.
std::vector< float > anchors({ 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 100.5f, 1.0f, 1.0f })
unsigned int GetNumElements() const
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
BindingPointInfo GetNetworkOutputBindingInfo(unsigned int layerId, const std::string &name) const override
Retrieve binding info (layer id and tensor info) for the network output identified by the given layer...
A Pooling2dDescriptor for the Pooling2dLayer.
uint32_t m_ActivationFunc
The activation function to use. 0: None, 1: Relu, 3: Relu6, 4: Tanh, 6: Sigmoid.
virtual unsigned int GetNumInputSlots() const =0
uint32_t m_DilationY
Dilation along y axis.
A StandInDescriptor for the StandIn layer.
A SliceDescriptor for the SliceLayer.
const armnnSerializer::TensorInfo * TensorRawPtr
static TensorRawPtrVector GetInputs(const GraphPtr &graph, unsigned int layerIndex)
bool m_LayerNormEnabled
Enable/disable layer normalization.
bool m_BiasEnabled
Enable/disable bias.
static void Destroy(IDeserializer *parser)
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
armnn::ActivationFunction ToActivationFunction(armnnSerializer::ActivationFunction function)
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A PermuteDescriptor for the PermuteLayer.
A Convolution2dDescriptor for the Convolution2dLayer.
armnn::TensorInfo ToTensorInfo(Deserializer::TensorRawPtr tensorPtr)
A MeanDescriptor for the MeanLayer.
virtual int Connect(IInputSlot &destination)=0
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
uint32_t m_DilationX
Dilation along x axis.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
std::vector< std::pair< unsigned int, unsigned int > > m_Crops
The values to crop from the input dimension.
static armnn::LstmDescriptor GetLstmDescriptor(LstmDescriptorPtr lstmDescriptor)
uint32_t m_PadBottom
Padding bottom value in the height dimension.
NormalizationAlgorithmChannel m_NormChannelType
Normalization channel algorithm to use (Across, Within).
const TensorShape & GetShape() const
float m_ClippingThresProj
Clipping threshold value for the projection.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
An ArgMinMaxDescriptor for ArgMinMaxLayer.
#define CHECK_CONST_TENSOR_PTR(TENSOR_PTR)
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
float m_ScaleH
Center size encoding scale height.
A ResizeDescriptor for the ResizeLayer.
float m_Eps
Used to avoid dividing by zero.
std::string AsString() const
#define CHECK_TENSOR_PTR(TENSOR_PTR)
A ComparisonDescriptor for the ComparisonLayer.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
std::vector< unsigned int > m_BlockShape
Block shape values.
An OriginsDescriptor for the ConcatLayer. Descriptor to configure the concatenation process...
uint32_t m_DilationY
Dilation factor value for height dimension.
uint32_t m_MaxDetections
Maximum numbers of detections.
static int32_t GetBindingLayerInfo(const GraphPtr &graphPtr, unsigned int layerIndex)
A StridedSliceDescriptor for the StridedSliceLayer.
uint32_t m_PadRight
Padding right value in the width dimension.