Pooling Layers#
Pooling layers reduce spatial dimensions by aggregating values in local regions, providing translation invariance and reducing computational cost in deeper layers.
MaxPool: Takes the maximum value in each pooling window (preserves strong features)
AvgPool: Takes the average value in each pooling window (smoother downsampling)
AdaptivePool: Automatically calculates kernel size to produce a target output size
FractionalMaxPool: Randomized pooling with fractional output size
MaxUnpool: Computes the partial inverse of MaxPool using stored indices
LPPool: Power-average pooling (generalization of avg/max pooling)
MaxPool1d / MaxPool2d / MaxPool3d#
-
class MaxPool1d : public torch::nn::ModuleHolder<MaxPool1dImpl>#
A
ModuleHoldersubclass forMaxPool1dImpl.See the documentation for
MaxPool1dImplclass to learn what methods it provides, and examples of how to useMaxPool1dwithtorch::nn::MaxPool1dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = MaxPool1dImpl#
-
using Impl = MaxPool1dImpl#
-
class MaxPool1dImpl : public torch::nn::MaxPoolImpl<1, MaxPool1dImpl>#
Applies maxpool over a 1-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.MaxPool1d to learn about the exact behavior of this module.
See the documentation for
torch::nn::MaxPool1dOptionsclass to learn what constructor arguments are supported for this module.Example:
MaxPool1d model(MaxPool1dOptions(3).stride(2));
-
class MaxPool2d : public torch::nn::ModuleHolder<MaxPool2dImpl>#
A
ModuleHoldersubclass forMaxPool2dImpl.See the documentation for
MaxPool2dImplclass to learn what methods it provides, and examples of how to useMaxPool2dwithtorch::nn::MaxPool2dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = MaxPool2dImpl#
-
using Impl = MaxPool2dImpl#
-
class MaxPool2dImpl : public torch::nn::MaxPoolImpl<2, MaxPool2dImpl>#
Applies maxpool over a 2-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.MaxPool2d to learn about the exact behavior of this module.
See the documentation for
torch::nn::MaxPool2dOptionsclass to learn what constructor arguments are supported for this module.Example:
MaxPool2d model(MaxPool2dOptions({3, 2}).stride({2, 2}));
-
class MaxPool3d : public torch::nn::ModuleHolder<MaxPool3dImpl>#
A
ModuleHoldersubclass forMaxPool3dImpl.See the documentation for
MaxPool3dImplclass to learn what methods it provides, and examples of how to useMaxPool3dwithtorch::nn::MaxPool3dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = MaxPool3dImpl#
-
using Impl = MaxPool3dImpl#
-
class MaxPool3dImpl : public torch::nn::MaxPoolImpl<3, MaxPool3dImpl>#
Applies maxpool over a 3-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.MaxPool3d to learn about the exact behavior of this module.
See the documentation for
torch::nn::MaxPool3dOptionsclass to learn what constructor arguments are supported for this module.Example:
MaxPool3d model(MaxPool3dOptions(3).stride(2));
Example:
auto pool = torch::nn::MaxPool2d(
torch::nn::MaxPool2dOptions(2).stride(2));
AvgPool1d / AvgPool2d / AvgPool3d#
-
class AvgPool1d : public torch::nn::ModuleHolder<AvgPool1dImpl>#
A
ModuleHoldersubclass forAvgPool1dImpl.See the documentation for
AvgPool1dImplclass to learn what methods it provides, and examples of how to useAvgPool1dwithtorch::nn::AvgPool1dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = AvgPool1dImpl#
-
using Impl = AvgPool1dImpl#
-
class AvgPool1dImpl : public torch::nn::AvgPoolImpl<1, AvgPool1dImpl>#
Applies avgpool over a 1-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.AvgPool1d to learn about the exact behavior of this module.
See the documentation for
torch::nn::AvgPool1dOptionsclass to learn what constructor arguments are supported for this module.Example:
AvgPool1d model(AvgPool1dOptions(3).stride(2));
-
class AvgPool2d : public torch::nn::ModuleHolder<AvgPool2dImpl>#
A
ModuleHoldersubclass forAvgPool2dImpl.See the documentation for
AvgPool2dImplclass to learn what methods it provides, and examples of how to useAvgPool2dwithtorch::nn::AvgPool2dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = AvgPool2dImpl#
-
using Impl = AvgPool2dImpl#
-
class AvgPool2dImpl : public torch::nn::AvgPoolImpl<2, AvgPool2dImpl>#
Applies avgpool over a 2-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.AvgPool2d to learn about the exact behavior of this module.
See the documentation for
torch::nn::AvgPool2dOptionsclass to learn what constructor arguments are supported for this module.Example:
AvgPool2d model(AvgPool2dOptions({3, 2}).stride({2, 2}));
-
class AvgPool3d : public torch::nn::ModuleHolder<AvgPool3dImpl>#
A
ModuleHoldersubclass forAvgPool3dImpl.See the documentation for
AvgPool3dImplclass to learn what methods it provides, and examples of how to useAvgPool3dwithtorch::nn::AvgPool3dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = AvgPool3dImpl#
-
using Impl = AvgPool3dImpl#
-
class AvgPool3dImpl : public torch::nn::AvgPoolImpl<3, AvgPool3dImpl>#
Applies avgpool over a 3-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.AvgPool3d to learn about the exact behavior of this module.
See the documentation for
torch::nn::AvgPool3dOptionsclass to learn what constructor arguments are supported for this module.Example:
AvgPool3d model(AvgPool3dOptions(5).stride(2));
AdaptiveAvgPool1d / AdaptiveAvgPool2d / AdaptiveAvgPool3d#
-
class AdaptiveAvgPool1d : public torch::nn::ModuleHolder<AdaptiveAvgPool1dImpl>#
A
ModuleHoldersubclass forAdaptiveAvgPool1dImpl.See the documentation for
AdaptiveAvgPool1dImplclass to learn what methods it provides, and examples of how to useAdaptiveAvgPool1dwithtorch::nn::AdaptiveAvgPool1dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = AdaptiveAvgPool1dImpl#
-
using Impl = AdaptiveAvgPool1dImpl#
-
class AdaptiveAvgPool1dImpl : public torch::nn::AdaptiveAvgPoolImpl<1, ExpandingArray<1>, AdaptiveAvgPool1dImpl>#
Applies adaptive avgpool over a 1-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.AdaptiveAvgPool1d to learn about the exact behavior of this module.
See the documentation for
torch::nn::AdaptiveAvgPool1dOptionsclass to learn what constructor arguments are supported for this module.Example:
AdaptiveAvgPool1d model(AdaptiveAvgPool1dOptions(5));
-
class AdaptiveAvgPool2d : public torch::nn::ModuleHolder<AdaptiveAvgPool2dImpl>#
A
ModuleHoldersubclass forAdaptiveAvgPool2dImpl.See the documentation for
AdaptiveAvgPool2dImplclass to learn what methods it provides, and examples of how to useAdaptiveAvgPool2dwithtorch::nn::AdaptiveAvgPool2dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = AdaptiveAvgPool2dImpl#
-
using Impl = AdaptiveAvgPool2dImpl#
-
class AdaptiveAvgPool2dImpl : public torch::nn::AdaptiveAvgPoolImpl<2, ExpandingArrayWithOptionalElem<2>, AdaptiveAvgPool2dImpl>#
Applies adaptive avgpool over a 2-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.AdaptiveAvgPool2d to learn about the exact behavior of this module.
See the documentation for
torch::nn::AdaptiveAvgPool2dOptionsclass to learn what constructor arguments are supported for this module.Example:
AdaptiveAvgPool2d model(AdaptiveAvgPool2dOptions({3, 2}));
-
class AdaptiveAvgPool3d : public torch::nn::ModuleHolder<AdaptiveAvgPool3dImpl>#
A
ModuleHoldersubclass forAdaptiveAvgPool3dImpl.See the documentation for
AdaptiveAvgPool3dImplclass to learn what methods it provides, and examples of how to useAdaptiveAvgPool3dwithtorch::nn::AdaptiveAvgPool3dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = AdaptiveAvgPool3dImpl#
-
using Impl = AdaptiveAvgPool3dImpl#
-
class AdaptiveAvgPool3dImpl : public torch::nn::AdaptiveAvgPoolImpl<3, ExpandingArrayWithOptionalElem<3>, AdaptiveAvgPool3dImpl>#
Applies adaptive avgpool over a 3-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.AdaptiveAvgPool3d to learn about the exact behavior of this module.
See the documentation for
torch::nn::AdaptiveAvgPool3dOptionsclass to learn what constructor arguments are supported for this module.Example:
AdaptiveAvgPool3d model(AdaptiveAvgPool3dOptions(3));
Example:
// Output will always be 7x7 regardless of input size
auto adaptive_pool = torch::nn::AdaptiveAvgPool2d(
torch::nn::AdaptiveAvgPool2dOptions({7, 7}));
AdaptiveMaxPool1d / AdaptiveMaxPool2d / AdaptiveMaxPool3d#
-
class AdaptiveMaxPool1d : public torch::nn::ModuleHolder<AdaptiveMaxPool1dImpl>#
A
ModuleHoldersubclass forAdaptiveMaxPool1dImpl.See the documentation for
AdaptiveMaxPool1dImplclass to learn what methods it provides, and examples of how to useAdaptiveMaxPool1dwithtorch::nn::AdaptiveMaxPool1dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = AdaptiveMaxPool1dImpl#
-
using Impl = AdaptiveMaxPool1dImpl#
-
class AdaptiveMaxPool1dImpl : public torch::nn::AdaptiveMaxPoolImpl<1, ExpandingArray<1>, AdaptiveMaxPool1dImpl>#
Applies adaptive maxpool over a 1-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.AdaptiveMaxPool1d to learn about the exact behavior of this module.
See the documentation for
torch::nn::AdaptiveMaxPool1dOptionsclass to learn what constructor arguments are supported for this module.Example:
AdaptiveMaxPool1d model(AdaptiveMaxPool1dOptions(3));
-
class AdaptiveMaxPool2d : public torch::nn::ModuleHolder<AdaptiveMaxPool2dImpl>#
A
ModuleHoldersubclass forAdaptiveMaxPool2dImpl.See the documentation for
AdaptiveMaxPool2dImplclass to learn what methods it provides, and examples of how to useAdaptiveMaxPool2dwithtorch::nn::AdaptiveMaxPool2dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = AdaptiveMaxPool2dImpl#
-
using Impl = AdaptiveMaxPool2dImpl#
-
class AdaptiveMaxPool2dImpl : public torch::nn::AdaptiveMaxPoolImpl<2, ExpandingArrayWithOptionalElem<2>, AdaptiveMaxPool2dImpl>#
Applies adaptive maxpool over a 2-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.AdaptiveMaxPool2d to learn about the exact behavior of this module.
See the documentation for
torch::nn::AdaptiveMaxPool2dOptionsclass to learn what constructor arguments are supported for this module.Example:
AdaptiveMaxPool2d model(AdaptiveMaxPool2dOptions({3, 2}));
-
class AdaptiveMaxPool3d : public torch::nn::ModuleHolder<AdaptiveMaxPool3dImpl>#
A
ModuleHoldersubclass forAdaptiveMaxPool3dImpl.See the documentation for
AdaptiveMaxPool3dImplclass to learn what methods it provides, and examples of how to useAdaptiveMaxPool3dwithtorch::nn::AdaptiveMaxPool3dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = AdaptiveMaxPool3dImpl#
-
using Impl = AdaptiveMaxPool3dImpl#
-
class AdaptiveMaxPool3dImpl : public torch::nn::AdaptiveMaxPoolImpl<3, ExpandingArrayWithOptionalElem<3>, AdaptiveMaxPool3dImpl>#
Applies adaptive maxpool over a 3-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.AdaptiveMaxPool3d to learn about the exact behavior of this module.
See the documentation for
torch::nn::AdaptiveMaxPool3dOptionsclass to learn what constructor arguments are supported for this module.Example:
AdaptiveMaxPool3d model(AdaptiveMaxPool3dOptions(3));
FractionalMaxPool2d / FractionalMaxPool3d#
-
class FractionalMaxPool2d : public torch::nn::ModuleHolder<FractionalMaxPool2dImpl>#
A
ModuleHoldersubclass forFractionalMaxPool2dImpl.See the documentation for
FractionalMaxPool2dImplclass to learn what methods it provides, and examples of how to useFractionalMaxPool2dwithtorch::nn::FractionalMaxPool2dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = FractionalMaxPool2dImpl#
-
using Impl = FractionalMaxPool2dImpl#
-
class FractionalMaxPool2dImpl : public torch::nn::Cloneable<FractionalMaxPool2dImpl>#
Applies fractional maxpool over a 2-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.FractionalMaxPool2d to learn about the exact behavior of this module.
See the documentation for
torch::nn::FractionalMaxPool2dOptionsclass to learn what constructor arguments are supported for this module.Example:
FractionalMaxPool2d model(FractionalMaxPool2dOptions(5).output_size(1));
Public Functions
-
inline FractionalMaxPool2dImpl(ExpandingArray<2> kernel_size)#
-
explicit FractionalMaxPool2dImpl(FractionalMaxPool2dOptions options_)#
-
virtual void reset() override#
reset()must perform initialization of all members with reference semantics, most importantly parameters, buffers and submodules.
-
virtual void pretty_print(std::ostream &stream) const override#
Pretty prints the
FractionalMaxPool2dmodule into the givenstream.
-
std::tuple<Tensor, Tensor> forward_with_indices(const Tensor &input)#
Returns the outputs and the indices of the max values.
Useful for
torch::nn::MaxUnpool2dlater.
-
inline FractionalMaxPool2dImpl(ExpandingArray<2> kernel_size)#
-
class FractionalMaxPool3d : public torch::nn::ModuleHolder<FractionalMaxPool3dImpl>#
A
ModuleHoldersubclass forFractionalMaxPool3dImpl.See the documentation for
FractionalMaxPool3dImplclass to learn what methods it provides, and examples of how to useFractionalMaxPool3dwithtorch::nn::FractionalMaxPool3dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = FractionalMaxPool3dImpl#
-
using Impl = FractionalMaxPool3dImpl#
-
class FractionalMaxPool3dImpl : public torch::nn::Cloneable<FractionalMaxPool3dImpl>#
Applies fractional maxpool over a 3-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.FractionalMaxPool3d to learn about the exact behavior of this module.
See the documentation for
torch::nn::FractionalMaxPool3dOptionsclass to learn what constructor arguments are supported for this module.Example:
FractionalMaxPool3d model(FractionalMaxPool3dOptions(5).output_size(1));
Public Functions
-
inline FractionalMaxPool3dImpl(ExpandingArray<3> kernel_size)#
-
explicit FractionalMaxPool3dImpl(FractionalMaxPool3dOptions options_)#
-
virtual void reset() override#
reset()must perform initialization of all members with reference semantics, most importantly parameters, buffers and submodules.
-
virtual void pretty_print(std::ostream &stream) const override#
Pretty prints the
FractionalMaxPool3dmodule into the givenstream.
-
std::tuple<Tensor, Tensor> forward_with_indices(const Tensor &input)#
Returns the outputs and the indices of the max values.
Useful for
torch::nn::MaxUnpool3dlater.
-
inline FractionalMaxPool3dImpl(ExpandingArray<3> kernel_size)#
MaxUnpool1d / MaxUnpool2d / MaxUnpool3d#
Computes a partial inverse of MaxPool, using the indices of the maximum
values computed during pooling to place values back into unpooled positions.
-
class MaxUnpool1d : public torch::nn::ModuleHolder<MaxUnpool1dImpl>#
A
ModuleHoldersubclass forMaxUnpool1dImpl.See the documentation for
MaxUnpool1dImplclass to learn what methods it provides, and examples of how to useMaxUnpool1dwithtorch::nn::MaxUnpool1dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = MaxUnpool1dImpl#
-
using Impl = MaxUnpool1dImpl#
-
class MaxUnpool1dImpl : public torch::nn::MaxUnpoolImpl<1, MaxUnpool1dImpl>#
Applies maxunpool over a 1-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.MaxUnpool1d to learn about the exact behavior of this module.
See the documentation for
torch::nn::MaxUnpool1dOptionsclass to learn what constructor arguments are supported for this module.Example:
MaxUnpool1d model(MaxUnpool1dOptions(3).stride(2).padding(1));
Public Functions
Friends
- friend struct torch::nn::AnyModuleHolder
-
class MaxUnpool2d : public torch::nn::ModuleHolder<MaxUnpool2dImpl>#
A
ModuleHoldersubclass forMaxUnpool2dImpl.See the documentation for
MaxUnpool2dImplclass to learn what methods it provides, and examples of how to useMaxUnpool2dwithtorch::nn::MaxUnpool2dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = MaxUnpool2dImpl#
-
using Impl = MaxUnpool2dImpl#
-
class MaxUnpool2dImpl : public torch::nn::MaxUnpoolImpl<2, MaxUnpool2dImpl>#
Applies maxunpool over a 2-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.MaxUnpool2d to learn about the exact behavior of this module.
See the documentation for
torch::nn::MaxUnpool2dOptionsclass to learn what constructor arguments are supported for this module.Example:
MaxUnpool2d model(MaxUnpool2dOptions(3).stride(2).padding(1));
Public Functions
Friends
- friend struct torch::nn::AnyModuleHolder
-
class MaxUnpool3d : public torch::nn::ModuleHolder<MaxUnpool3dImpl>#
A
ModuleHoldersubclass forMaxUnpool3dImpl.See the documentation for
MaxUnpool3dImplclass to learn what methods it provides, and examples of how to useMaxUnpool3dwithtorch::nn::MaxUnpool3dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = MaxUnpool3dImpl#
-
using Impl = MaxUnpool3dImpl#
-
class MaxUnpool3dImpl : public torch::nn::MaxUnpoolImpl<3, MaxUnpool3dImpl>#
Applies maxunpool over a 3-D input.
See https://pytorch.org/docs/main/nn.html#torch.nn.MaxUnpool3d to learn about the exact behavior of this module.
See the documentation for
torch::nn::MaxUnpool3dOptionsclass to learn what constructor arguments are supported for this module.Example:
MaxUnpool3d model(MaxUnpool3dOptions(3).stride(2).padding(1));
Public Functions
Friends
- friend struct torch::nn::AnyModuleHolder
Example:
auto pool = torch::nn::MaxPool2d(
torch::nn::MaxPool2dOptions(2).stride(2).return_indices(true));
auto unpool = torch::nn::MaxUnpool2d(
torch::nn::MaxUnpoolOptions<2>(2).stride(2));
auto [output, indices] = pool->forward_with_indices(input);
auto reconstructed = unpool->forward(output, indices);
LPPool1d / LPPool2d / LPPool3d#
-
class LPPool1d : public torch::nn::ModuleHolder<LPPool1dImpl>#
A
ModuleHoldersubclass forLPPool1dImpl.See the documentation for
LPPool1dImplclass to learn what methods it provides, and examples of how to useLPPool1dwithtorch::nn::LPPool1dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = LPPool1dImpl#
-
using Impl = LPPool1dImpl#
-
class LPPool1dImpl : public torch::nn::LPPoolImpl<1, LPPool1dImpl>#
Applies the LPPool1d function element-wise.
See https://pytorch.org/docs/main/nn.html#torch.nn.LPPool1d to learn about the exact behavior of this module.
See the documentation for
torch::nn::LPPool1dOptionsclass to learn what constructor arguments are supported for this module.Example:
LPPool1d model(LPPool1dOptions(1, 2).stride(5).ceil_mode(true));
-
class LPPool2d : public torch::nn::ModuleHolder<LPPool2dImpl>#
A
ModuleHoldersubclass forLPPool2dImpl.See the documentation for
LPPool2dImplclass to learn what methods it provides, and examples of how to useLPPool2dwithtorch::nn::LPPool2dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = LPPool2dImpl#
-
using Impl = LPPool2dImpl#
-
class LPPool2dImpl : public torch::nn::LPPoolImpl<2, LPPool2dImpl>#
Applies the LPPool2d function element-wise.
See https://pytorch.org/docs/main/nn.html#torch.nn.LPPool2d to learn about the exact behavior of this module.
See the documentation for
torch::nn::LPPool2dOptionsclass to learn what constructor arguments are supported for this module.Example:
LPPool2d model(LPPool2dOptions(1, std::vector<int64_t>({3, 4})).stride({5, 6}).ceil_mode(true));
-
class LPPool3d : public torch::nn::ModuleHolder<LPPool3dImpl>#
A
ModuleHoldersubclass forLPPool3dImpl.See the documentation for
LPPool3dImplclass to learn what methods it provides, and examples of how to useLPPool3dwithtorch::nn::LPPool3dOptions. See the documentation forModuleHolderto learn about PyTorch’s module storage semantics.Public Types
-
using Impl = LPPool3dImpl#
-
using Impl = LPPool3dImpl#
-
class LPPool3dImpl : public torch::nn::LPPoolImpl<3, LPPool3dImpl>#
Applies the LPPool3d function element-wise.
See https://pytorch.org/docs/main/nn.html#torch.nn.LPPool3d to learn about the exact behavior of this module.
See the documentation for
torch::nn::LPPool3dOptionsclass to learn what constructor arguments are supported for this module.Example:
LPPool3d model(LPPool3dOptions(1, std::vector<int64_t>({3, 4, 5})).stride( {5, 6, 7}).ceil_mode(true));