torch.nn.functional.adaptive_max_pool3d
function adaptive_max_pool3d(input: Tensor, output_size: number | [number, number, number], options: AdaptiveMaxPoolFunctionalOptions & { return_indices: true }): PoolWithIndicesResultfunction adaptive_max_pool3d(input: Tensor, output_size: number | [number, number, number], options?: AdaptiveMaxPoolFunctionalOptions): Tensor | PoolWithIndicesResult3D Adaptive Max Pooling: takes max values to fixed volumetric size automatically.
Applies adaptive max pooling over 3D spatial dimensions (depth, height, width) with automatic kernel/stride computation. Optionally returns indices of max values. Useful for:
- 3D object recognition: standardizing volumetric feature sizes before classifier
- Medical imaging: handling variable volume sizes in classification pipelines
- Video classification: extracting temporal-spatial features with automatic sizing
- Unpooling: using returned indices to reconstruct higher-resolution features
- Variable-size 3D handling: same network works with any volume dimensions
- 3D Autoencoders: encoder pooling with indices for decoder upsampling
Unlike regular pooling, adaptive pooling automatically computes the kernel and stride to achieve the target output volumetric size. Preserves maximum values in each adaptive 3D window. Can return indices for unpooling in deconvolutional networks.
- 3D adaptive kernels: Automatically computed for all three spatial dimensions
- Index preservation: return_indices=true enables feature reconstruction
- Input invariance: Same output size regardless of input volume dimensions
- Max preservation: Keeps strongest 3D local activations
- Global max special case: output_size=1 gives global maximum
- Memory intensive: 3D operations use more memory than 2D
- Index semantics: Returned indices correspond to flattened 3D positions
- Computational cost: More expensive than adaptive 2D pooling
Parameters
inputTensor- 5D input tensor of shape (batch, channels, depth, height, width)
output_sizenumber | [number, number, number]- Target spatial size: single value for (size, size, size) or [depth, height, width]
optionsAdaptiveMaxPoolFunctionalOptions & { return_indices: true }- Options for the operation. See
AdaptiveMaxPoolFunctionalOptions.
Returns
PoolWithIndicesResult– - If return_indices=false: Tensor with shape (batch, channels, out_depth, out_height, out_width) - If return_indices=true: [pooled_tensor, indices_tensor] for unpoolingExamples
// 3D CNN classification: global max pooling
const features = torch.randn(8, 512, 8, 14, 14); // 3D CNN features
const pooled = torch.nn.functional.adaptive_max_pool3d(features, 1);
// Output: (8, 512, 1, 1, 1) - ready for classification head
// Variable volume sizes: same network for different resolutions
const small_vol = torch.randn(4, 256, 16, 32, 32);
const out1 = torch.nn.functional.adaptive_max_pool3d(small_vol, 4); // → (4, 256, 4, 4, 4)
const large_vol = torch.randn(4, 256, 32, 64, 64); // 2x larger
const out2 = torch.nn.functional.adaptive_max_pool3d(large_vol, 4); // → (4, 256, 4, 4, 4)
// Both produce (4, 256, 4, 4, 4) regardless of input volume size
// 3D Autoencoder with unpooling
const x = torch.randn(1, 128, 32, 32, 32);
const [encoded, indices] = torch.nn.functional.adaptive_max_pool3d(x, 16, true);
// encoded: (1, 128, 16, 16, 16) - compressed volume
// indices: (1, 128, 16, 16, 16) - for decoder unpooling
// Asymmetric pooling: preserve temporal dimension
const video = torch.randn(2, 256, 32, 16, 16); // depth=temporal
const features = torch.nn.functional.adaptive_max_pool3d(video, [32, 8, 8]);
// Output: (2, 256, 32, 8, 8) - no temporal poolingSee Also
- PyTorch torch.nn.functional.adaptive_max_pool3d
- adaptive_avg_pool3d - Average variant for smoothing
- max_pool3d - Regular 3D max pooling with explicit kernel/stride
- adaptive_max_pool2d - 2D spatial variant
- adaptive_max_pool1d - 1D temporal variant