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

Method ParseResize

src/armnnTfLiteParser/TfLiteParser.cpp:3617–3689  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3615}
3616
3617void TfLiteParserImpl::ParseResize(size_t subgraphIndex, size_t operatorIndex, ResizeMethod resizeMethod)
3618{
3619 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
3620
3621 auto inputs = GetInputs(m_Model, subgraphIndex, operatorIndex);
3622 CHECK_VALID_SIZE(inputs.size(), 2);
3623
3624 auto outputs = GetOutputs(m_Model, subgraphIndex, operatorIndex);
3625 CHECK_VALID_SIZE(outputs.size(), 1);
3626
3627 armnn::TensorInfo sizeTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 1);
3628
3629 // Data for the parsed tensor args (size) must be stored locally.
3630 std::vector<int32_t> sizeTensorData(sizeTensorInfo.GetNumElements());
3631
3632 BufferRawPtr sizeBufferPtr = GetBuffer(m_Model, inputs[1]->buffer);
3633 ValidateBuffer(sizeBufferPtr, sizeTensorInfo, "size");
3634 ::memcpy(sizeTensorData.data(), sizeBufferPtr->data.data(), sizeTensorInfo.GetNumBytes());
3635
3636 ResizeDescriptor desc;
3637 desc.m_Method = resizeMethod;
3638 desc.m_TargetHeight = static_cast<uint32_t> (sizeTensorData[0]);
3639 desc.m_TargetWidth = static_cast<uint32_t> (sizeTensorData[1]);
3640 desc.m_DataLayout = armnn::DataLayout::NHWC;
3641
3642 auto layerName = fmt::format("Resize:");
3643
3644 switch (resizeMethod)
3645 {
3646 case ResizeMethod::Bilinear:
3647 {
3648 layerName += fmt::format("BILINEAR:{}:{}", subgraphIndex, operatorIndex);
3649
3650 const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
3651 const auto * options = operatorPtr->builtin_options.AsResizeBilinearOptions();
3652
3653 desc.m_AlignCorners = options->align_corners;
3654 desc.m_HalfPixelCenters = options->half_pixel_centers;
3655 break;
3656 }
3657 case ResizeMethod::NearestNeighbor:
3658 {
3659 layerName += fmt::format("NEARESTNEIGHBOR:{}:{}", subgraphIndex, operatorIndex);
3660 break;
3661 }
3662 default:
3663 {
3664 throw ParseException(
3665 fmt::format("Unexpected ResizeMethod[{}] when creating layerName {} ",
3666 static_cast<int>(resizeMethod), CHECK_LOCATION().AsString()));
3667 }
3668 }
3669
3670 TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
3671
3672 IConnectableLayer* layer = m_Network->AddResizeLayer(desc, layerName.c_str());
3673
3674 if (!layer)

Callers

nothing calls this directly

Calls 14

formatEnum · 0.85
ParseExceptionClass · 0.85
AsUnsignedVectorFunction · 0.85
AddResizeLayerMethod · 0.80
GetOutputSlotMethod · 0.80
sizeMethod · 0.45
GetNumElementsMethod · 0.45
dataMethod · 0.45
GetNumBytesMethod · 0.45
AsStringMethod · 0.45

Tested by

no test coverage detected