40 BOOST_ASSERT(inputShapes.size() == 1);
45 BOOST_ASSERT_MSG(inputShape.GetNumDimensions() == 4,
"Pooling2dLayer will always have 4D input.");
47 unsigned int inWidth = inputShape[dimensionIndices.
GetWidthIndex()];
48 unsigned int inHeight = inputShape[dimensionIndices.
GetHeightIndex()];
50 unsigned int inBatchSize = inputShape[0];
53 unsigned int outWidth = 1;
54 unsigned int outHeight = 1;
58 "Stride can only be zero when performing global pooling");
60 auto CalcSize = [](
auto inSize,
auto lowPad,
auto highPad,
auto poolSize,
auto stride,
auto outputShapeRounding)
62 unsigned int readSize = inSize + lowPad + highPad - poolSize;
63 float div =
static_cast<float>(readSize) / static_cast<float>(stride);
65 unsigned int size = 0;
66 switch (outputShapeRounding)
69 size =
static_cast<unsigned int>(ceil(div)) + 1;
72 size =
static_cast<unsigned int>(floor(div)) + 1;
75 BOOST_ASSERT_MSG(
false,
"Unsupported Output Shape Rounding");
80 if ((size - 1)*stride >= inSize + lowPad)
93 unsigned int outChannels = inChannels;
94 unsigned int outBatchSize = inBatchSize;
97 TensorShape( { outBatchSize, outHeight, outWidth, outChannels } ) :
98 TensorShape( { outBatchSize, outChannels, outHeight, outWidth });
100 return std::vector<TensorShape>({ tensorShape });
109 BOOST_ASSERT(inferredShapes.size() == 1);
111 ConditionalThrowIfNotEqual<LayerValidationException>(
112 "Pooling2dLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
uint32_t m_PadBottom
Padding bottom value in the height dimension.
Pooling2dDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
const Pooling2dDescriptor & GetParameters() const
unsigned int GetWidthIndex() const
const TensorShape & GetShape() const
uint32_t m_PadLeft
Padding left value in the width dimension.
Pooling2dLayer(const Pooling2dDescriptor ¶m, const char *name)
Constructor to create a Pooling2dLayer.
uint32_t m_PoolWidth
Pooling width value.
uint32_t m_PadTop
Padding top value in the height dimension.
Copyright (c) 2020 ARM Limited.
virtual void VisitPooling2dLayer(const IConnectableLayer *layer, const Pooling2dDescriptor &pooling2dDescriptor, const char *name=nullptr)=0
Function that a pooling layer should call back to when its Accept(ILayerVisitor&) function is invoked...
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
unsigned int GetHeightIndex() const
void Accept(ILayerVisitor &visitor) const override
Apply a visitor to this layer.
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
uint32_t m_PoolHeight
Pooling height value.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Pooling2dLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
uint32_t m_PadRight
Padding right value in the width dimension.
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
By default returns inputShapes if the number of inputs are equal to number of outputs, otherwise infers the output shapes from given input shapes and layer properties.
This layer represents a pooling 2d operation.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
virtual std::unique_ptr< IWorkload > CreatePooling2d(const Pooling2dQueueDescriptor &descriptor, const WorkloadInfo &info) const
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of Pooling2dLayer.
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the Pooling2d type.
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
virtual const TensorInfo & GetTensorInfo() const =0
const char * GetName() const override
Returns the name of the layer.
A Pooling2dDescriptor for the Pooling2dLayer.
void Pooling2d(Decoder< float > &rInputDecoder, Encoder< float > &rOutputEncoder, const TensorInfo &inputInfo, const TensorInfo &outputInfo, const Pooling2dDescriptor ¶ms)
Computes the Pooling2d operation.
const TensorInfo & GetTensorInfo() const override
unsigned int GetChannelsIndex() const
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.