From 6c2355b1f7dd722eb908dd505826df8df6756471 Mon Sep 17 00:00:00 2001 From: Bruno Goncalves Date: Wed, 19 Dec 2018 12:52:01 -0200 Subject: Added ParsePad method to TfLiteParser Change-Id: I2e671f66cf1b0a24b4ca9e96b554dc7db3af9655 --- src/armnnTfLiteParser/TfLiteParser.cpp | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/armnnTfLiteParser/TfLiteParser.cpp') diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp index e3306b317f..0e8d3c5b68 100644 --- a/src/armnnTfLiteParser/TfLiteParser.cpp +++ b/src/armnnTfLiteParser/TfLiteParser.cpp @@ -453,6 +453,7 @@ TfLiteParser::TfLiteParser() m_ParserFunctions[tflite::BuiltinOperator_ADD] = &TfLiteParser::ParseAdd; m_ParserFunctions[tflite::BuiltinOperator_MUL] = &TfLiteParser::ParseMul; m_ParserFunctions[tflite::BuiltinOperator_MEAN] = &TfLiteParser::ParseMean; + m_ParserFunctions[tflite::BuiltinOperator_PAD] = &TfLiteParser::ParsePad; } void TfLiteParser::ResetParser() @@ -1086,6 +1087,41 @@ void TfLiteParser::ParseMean(size_t subgraphIndex, size_t operatorIndex) RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]}); } +void TfLiteParser::ParsePad(size_t subgraphIndex, size_t operatorIndex) +{ + CHECK_MODEL(m_Model, subgraphIndex, operatorIndex); + + TfLiteParser::TensorRawPtrVector inputs = GetInputs(m_Model, subgraphIndex, operatorIndex); + + TfLiteParser::TensorRawPtrVector outputs = GetOutputs(m_Model, subgraphIndex, operatorIndex); + CHECK_VALID_SIZE(outputs.size(), 1); + + armnn::TensorInfo padTensorInfo = ToTensorInfo(inputs[1]); + BufferRawPtr bufferPtr = GetBuffer(m_Model, inputs[1]->buffer); + + std::vector padBuffer(padTensorInfo.GetNumElements()); + ::memcpy(padBuffer.data(), bufferPtr->data.data(), padTensorInfo.GetNumBytes()); + + size_t step = 2; + armnn::PadDescriptor desc; + for (unsigned int i = 0; i < padTensorInfo.GetNumElements() / step; ++i) + { + desc.m_PadList.emplace_back(padBuffer[i * step], padBuffer[i * step + 1]); + } + + auto layerName = boost::str(boost::format("Pad:%1%:%2%") % subgraphIndex % operatorIndex); + IConnectableLayer* layer = m_Network->AddPadLayer(desc, layerName.c_str()); + + TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]); + layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); + + auto inputTensorIndexes = AsUnsignedVector(GetInputTensorIds(m_Model, subgraphIndex, operatorIndex)); + RegisterInputSlots(subgraphIndex, operatorIndex, layer, {inputTensorIndexes[0]}); + + auto outputTensorIndexes = AsUnsignedVector(GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex)); + RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]}); +} + void TfLiteParser::ParseRelu(size_t subgraphIndex, size_t operatorIndex) { CHECK_MODEL(m_Model, subgraphIndex, operatorIndex); -- cgit v1.2.1