MCPcopy Create free account
hub / github.com/ARM-software/armnn / ParsePad

Method ParsePad

src/armnnTfLiteParser/TfLiteParser.cpp:2964–3088  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2962}
2963
2964void TfLiteParserImpl::ParsePad(size_t subgraphIndex, size_t operatorIndex)
2965{
2966 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2967
2968 TfLiteParserImpl::TensorRawPtrVector inputs = GetInputs(m_Model, subgraphIndex, operatorIndex);
2969
2970 TfLiteParserImpl::TensorRawPtrVector outputs = GetOutputs(m_Model, subgraphIndex, operatorIndex);
2971 CHECK_VALID_SIZE(outputs.size(), 1);
2972
2973 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2974 armnn::TensorInfo padTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
2975
2976 std::vector<unsigned int> padBuffer = GetUIntBuffer(padTensorInfo, m_Model, inputs[1]->buffer);
2977
2978 size_t step = 2;
2979 armnn::PadDescriptor desc;
2980 auto opcode = GetOpCode(m_Model, subgraphIndex, operatorIndex);
2981
2982 if (opcode == tflite::BuiltinOperator_PAD)
2983 {
2984 CHECK_VALID_SIZE(inputs.size(), 2);
2985
2986 if (inputTensorInfo.IsQuantized())
2987 {
2988 desc.m_PadValue = static_cast<float>(inputTensorInfo.GetQuantizationOffset());
2989 }
2990 }
2991 else if (opcode == tflite::BuiltinOperator_PADV2)
2992 {
2993 CHECK_VALID_SIZE(inputs.size(), 3);
2994
2995 armnn::TensorInfo padValueTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 2);
2996
2997 if (padValueTensorInfo.GetNumElements() != 1)
2998 {
2999 ARMNN_THROW_PARSE_EXCEPTION("Multiple padding values are not supported in PADV2");
3000 }
3001 BufferRawPtr padValueBufferPtr = GetBuffer(m_Model, inputs[2]->buffer);
3002
3003 // Get the pad value from the input tensor
3004 if (!padValueBufferPtr->data.empty())
3005 {
3006 switch (padValueTensorInfo.GetDataType())
3007 {
3008 case armnn::DataType::Float32:
3009 {
3010 std::vector<float> padValueBuffer(padValueTensorInfo.GetNumElements());
3011
3012 const size_t requiredBytes = padValueTensorInfo.GetNumElements() * sizeof(float);
3013 if (padValueBufferPtr->data.size() < requiredBytes)
3014 {
3015 throw ParseException("Pad value buffer is too small for expected data.");
3016 }
3017
3018 ::memcpy(padValueBuffer.data(), padValueBufferPtr->data.data(), padValueBufferPtr->data.size());
3019 desc.m_PadValue = padValueBuffer[0];
3020 break;
3021 }

Callers

nothing calls this directly

Calls 15

GetUIntBufferFunction · 0.85
GetOpCodeFunction · 0.85
ParseExceptionClass · 0.85
formatEnum · 0.85
AsUnsignedVectorFunction · 0.85
IsQuantizedMethod · 0.80
emptyMethod · 0.80
AddPadLayerMethod · 0.80
GetOutputSlotMethod · 0.80
sizeMethod · 0.45
GetQuantizationOffsetMethod · 0.45

Tested by

no test coverage detected