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.",
void Pooling2d(Decoder< float > &rInputDecoder, Encoder< float > &rOutputEncoder, const TensorInfo &inputInfo, const TensorInfo &outputInfo, const Pooling2dDescriptor ¶ms)
Computes the Pooling2d operation.
const char * GetName() const override
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
virtual const TensorInfo & GetTensorInfo() const =0
Pooling2dLayer * Clone(Graph &graph) const override
uint32_t m_PoolHeight
Pooling height value.
unsigned int GetHeightIndex() const
uint32_t m_PadTop
Padding top value in the height dimension.
uint32_t m_PadRight
Padding right value in the width dimension.
This layer represents a pooling 2d operation.
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
virtual void VisitPooling2dLayer(const IConnectableLayer *layer, const Pooling2dDescriptor &pooling2dDescriptor, const char *name=nullptr)=0
unsigned int GetWidthIndex() const
uint32_t m_PoolWidth
Pooling width value.
const Pooling2dDescriptor & GetParameters() const
void ValidateTensorShapesFromInputs() override
Pooling2dDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
uint32_t m_PadLeft
Padding left value in the width dimension.
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
virtual std::unique_ptr< IWorkload > CreatePooling2d(const Pooling2dQueueDescriptor &descriptor, const WorkloadInfo &info) const
unsigned int GetChannelsIndex() const
OutputShapeRounding m_OutputShapeRounding
The rounding method for the output shape. (Floor, Ceiling).
Pooling2dLayer(const Pooling2dDescriptor ¶m, const char *name)
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
A Pooling2dDescriptor for the Pooling2dLayer.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
void Accept(ILayerVisitor &visitor) const override
uint32_t m_PadBottom
Padding bottom value in the height dimension.
const TensorShape & GetShape() const
const TensorInfo & GetTensorInfo() const override
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
const InputSlot & GetInputSlot(unsigned int index) const override