torch.nn.AdaptiveAvgPool3d
class AdaptiveAvgPool3d extends Modulenew AdaptiveAvgPool3d(output_size: number | [number, number, number])
- readonly
output_size(number | [number, number, number])
3D adaptive average pooling: reduces volumetric dimensions to fixed output size with averaging.
Applies average pooling with automatically computed kernel/stride to produce exact output_size (D_out × H_out × W_out), regardless of input size. Smooth downsampling of 3D data. Essential for:
- 3D networks with variable volumetric inputs (medical, video data)
- Global average pooling from 3D feature maps
- Fixed-size representation from variable-size 3D volumes
- Smooth 3D spatial downsampling
- Fixed output: Always produces exactly specified 3D dimensions
- Smooth averaging: Retains more information than MaxPool3d
- Variable input: Works with any 3D input size
- Memory intensive: 3D operations use significant memory
- Memory intensive: 3D pooling more expensive than 2D
- Computational cost: Expensive 3D operation
- Information loss: 3D spatial information compressed
Examples
// Global average pooling on 3D features
const pool = new torch.nn.AdaptiveAvgPool3d(1); // Reduce to single value per channel
const x = torch.randn([8, 256, 8, 16, 16]); // 3D feature maps
const y = pool.forward(x); // [8, 256, 1, 1, 1] - global average// Variable 3D volume sizes to fixed feature volume
const pool = new torch.nn.AdaptiveAvgPool3d([4, 4, 4]);
const x1 = torch.randn([4, 128, 64, 64, 64]);
const y1 = pool.forward(x1); // [4, 128, 4, 4, 4]
const x2 = torch.randn([4, 128, 32, 32, 32]); // Different size
const y2 = pool.forward(x2); // [4, 128, 4, 4, 4] - same output!