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

Method ParsePool

src/armnnTfLiteParser/TfLiteParser.cpp:2113–2188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2111}
2112
2113void TfLiteParserImpl::ParsePool(size_t subgraphIndex,
2114 size_t operatorIndex,
2115 PoolingAlgorithm algorithm)
2116{
2117 CHECK_MODEL(m_Model, subgraphIndex, operatorIndex);
2118
2119 const auto& operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
2120 const auto* options = operatorPtr->builtin_options.AsPool2DOptions();
2121
2122 CHECK_SUPPORTED_FUSED_ACTIVATION(options, subgraphIndex, operatorIndex);
2123
2124 std::string layerName;
2125
2126 switch (algorithm)
2127 {
2128 case PoolingAlgorithm::Average:
2129 layerName =
2130 fmt::format("AveragePool2D:{}:{}", subgraphIndex, operatorIndex);
2131 break;
2132 case PoolingAlgorithm::Max:
2133 layerName =
2134 fmt::format("MaxPool2D:{}:{}", subgraphIndex, operatorIndex);
2135 break;
2136 default:
2137 throw ParseException(fmt::format("Unsupported Pooling Algorithm {}", CHECK_LOCATION().AsString()));
2138 }
2139
2140 Pooling2dDescriptor desc;
2141
2142 desc.m_PoolType = algorithm;
2143 desc.m_StrideX = CHECKED_NON_NEGATIVE(options->stride_w);
2144 desc.m_StrideY = CHECKED_NON_NEGATIVE(options->stride_h);
2145 desc.m_PoolWidth = CHECKED_NON_NEGATIVE(options->filter_width);
2146 desc.m_PoolHeight = CHECKED_NON_NEGATIVE(options->filter_height);
2147 desc.m_PaddingMethod = PaddingMethod::Exclude;
2148 desc.m_OutputShapeRounding = OutputShapeRounding::Floor;
2149 desc.m_DataLayout = armnn::DataLayout::NHWC;
2150
2151 auto inputs = GetInputs(m_Model, subgraphIndex, operatorIndex);
2152 CHECK_VALID_SIZE(inputs.size(), 1);
2153 armnn::TensorInfo inputTensorInfo = InputTensorInfo(subgraphIndex, operatorIndex, 0);
2154
2155 // assuming input is NHWC
2156 unsigned int inputHeight = inputTensorInfo.GetShape()[1];
2157 unsigned int inputWidth = inputTensorInfo.GetShape()[2];
2158
2159 CalcPadding(inputHeight, desc.m_PoolHeight, desc.m_StrideY, 1u,
2160 desc.m_PadTop, desc.m_PadBottom, options->padding);
2161 CalcPadding(inputWidth, desc.m_PoolWidth, desc.m_StrideX, 1u,
2162 desc.m_PadLeft, desc.m_PadRight, options->padding);
2163
2164 auto outputs = GetOutputs(m_Model, subgraphIndex, operatorIndex);
2165 CHECK_VALID_SIZE(outputs.size(), 1);
2166
2167 IConnectableLayer* layer = m_Network->AddPooling2dLayer(desc, layerName.c_str());
2168
2169 if (!layer)
2170 {

Callers

nothing calls this directly

Calls 13

formatEnum · 0.85
ParseExceptionClass · 0.85
AsUnsignedVectorFunction · 0.85
AddPooling2dLayerMethod · 0.80
GetOutputSlotMethod · 0.80
CalcPaddingFunction · 0.70
AsStringMethod · 0.45
sizeMethod · 0.45
GetShapeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected