Pooling
#include <popnn/Pooling.hpp>
Support for pooling operations.
-
namespace popnn
Functions used in neural networks.
-
namespace pooling
Functions for pooling operations.
Functions
-
std::ostream &operator<<(std::ostream &o, const PoolParams ¶ms)
-
const char *asString(const PoolingType &method)
-
std::vector<std::size_t> getOutputFieldShape(const PoolParams ¶ms)
-
uint64_t getFwdFlops(const PoolParams ¶ms)
-
uint64_t getBwdFlops(const PoolParams ¶ms)
-
double getFwdPerfectCycleCount(const poplar::Graph &graph, const PoolParams ¶ms)
-
double getBwdPerfectCycleCount(const poplar::Graph &graph, const PoolParams ¶ms)
-
poplar::Tensor pool(poplar::Graph &graph, const PoolParams ¶ms, const poplar::Tensor &in, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Add a pooling operation to the graph.
This performs a pooling over the spatial dimensions […]. The shape of the input should be [
batchSize * numChannels * ...
].- Parameters
graph – The graph that the operation will be added to.
params – The pooling parameters.
in – The input tensor.
prog – The program sequence to append the operation to.
debugContext – Optional debug information.
options – Pooling options (not currently used).
- Returns
A tensor with the results of the pooling operation.
-
poplar::Tensor poolInputGradient(poplar::Graph &graph, const PoolParams ¶ms, const poplar::Tensor &in, const poplar::Tensor &pooled, const poplar::Tensor &pooledGradient, bool useScaledGradient, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Calculate the gradient with respect to the input of a pooling operation given the gradient of the output.
While this function can be used for maximum, average or sum pooling, poolInputGradient(poplar::Graph&, const PoolParams&, const unsigned, const poplar::Tensor&, poplar::program::Sequence&, const poplar::DebugContext&, const poplar::OptionFlags&) is recommended for average or sum pooling.
This performs a pooling over the spatial dimensions […]. The shape of the input should be [
batchSize * numChannels * ...
].- Parameters
graph – The graph the operation will be added to.
params – The pooling parameters.
in – The forward activations tensor input to pooling.
pooled – The output of pooling in the forward pass.
pooledGradient – The gradients to the pooling operation.
useScaledGradient – Use a scaled gradient if set to true. Otherwise, the gradient is propagated to all the positions which matched the pooled value in the forward pass.
prog – The program sequence to append the operation to.
debugContext – Optional debug information.
options – The pooling options. See pool().
- Returns
A tensor with the results of the pooling operation.
-
poplar::Tensor poolInputGradient(poplar::Graph &graph, const PoolParams ¶ms, const unsigned fwdChansPerGroup, const poplar::Tensor &pooledGradient, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {})
Calculate the gradient with respect to the input of a pooling operation given the gradient of the output.
This function should be used for average and sum pooling.
This performs a pooling over the spatial dimensions […]. The shape of the output will be [
batchSize * numChannels * ...
].- Parameters
graph – The graph the operation will be added to.
params – The pooling parameters.
fwdChansPerGroup – Used in creating the output tensor.
pooledGradient – The gradients to the pooling operation.
prog – The program sequence to append the operation to.
debugContext – Optional debug information.
options – The pooling options. See pool().
- Returns
A tensor with the results of the pooling operation.
-
struct PoolParams
Public Functions
-
inline PoolParams(PoolingType poolingType, std::vector<std::size_t> inputFieldShape, std::vector<std::size_t> kernelShape, std::vector<unsigned> stride, std::vector<int> inputTruncationOrPaddingLower, std::vector<int> inputTruncationOrPaddingUpper, std::size_t numChannels, std::size_t batchSize, poplar::Type dType)
Public Members
-
PoolingType poolingType
The type of pooling to be performed (for example, maximum, sum or average).
-
std::vector<std::size_t> inputFieldShape
The input shape not including the dimensions for batch size
batchSize
and number of channelsnumChannels
.
-
std::vector<int> inputTruncationOrPaddingLower
The lower padding (for values >0) or truncation (for values <0) for each input dimension specifying the padding/truncation at the start of the dimension.
-
inline PoolParams(PoolingType poolingType, std::vector<std::size_t> inputFieldShape, std::vector<std::size_t> kernelShape, std::vector<unsigned> stride, std::vector<int> inputTruncationOrPaddingLower, std::vector<int> inputTruncationOrPaddingUpper, std::size_t numChannels, std::size_t batchSize, poplar::Type dType)
-
std::ostream &operator<<(std::ostream &o, const PoolParams ¶ms)
-
namespace pooling