torch.nn.AdaptiveMaxPool3d
class AdaptiveMaxPool3d extends Modulenew AdaptiveMaxPool3d(output_size: number | [number, number, number], options?: AdaptiveMaxPool3dOptions)
- readonly
output_size(number | [number, number, number]) - readonly
return_indices(boolean)
3D adaptive max pooling: reduces volumetric dimensions to fixed output size with automatic kernel selection.
Applies max pooling with automatically computed kernel_size and stride to produce exact output_size (D_out × H_out × W_out), regardless of input size. Enables networks to accept variable-size 3D volumes. Essential for:
- 3D CNNs with variable volumetric input sizes (medical imaging, video)
- Fixed feature representation from volumetric data
- Preprocessing 3D data of different resolutions
- Size-invariant 3D feature extraction
- Efficient 3D spatial downsampling with guaranteed output dimensions
Extends adaptive pooling to 3D domain. Output volumetric dimensions are exactly specified, kernel/stride computed automatically.
- Fixed output: Always produces exactly specified 3D dimensions
- Variable input: Works with any 3D input size
- Memory intensive: 3D operations use significant memory
- Automatic kernel: No manual kernel/stride computation needed
- Memory intensive: 3D pooling uses more memory than 2D
- Information loss: Non-max values discarded per region
- Computational cost: Expensive 3D operation
Examples
// Variable 3D volume sizes to fixed feature volume
const pool = new torch.nn.AdaptiveMaxPool3d([8, 8, 8]);
// Different input 3D sizes -> same 8x8x8 output
const x1 = torch.randn([4, 128, 64, 64, 64]);
const y1 = pool.forward(x1); // [4, 128, 8, 8, 8]
const x2 = torch.randn([4, 128, 128, 128, 128]); // 2x larger
const y2 = pool.forward(x2); // [4, 128, 8, 8, 8] - same output!// Global max pooling (reduce to 1x1x1)
const pool = new torch.nn.AdaptiveMaxPool3d(1);
const volume = torch.randn([8, 256, 16, 32, 32]);
const pooled = pool.forward(volume); // [8, 256, 1, 1, 1]