class

AdaptiveAvgPool3d

extendsModule
AdaptiveAvgPool3d(output_size: _Size3d)
source

Applies adaptive 3-D average pooling to produce a fixed output volume.

Automatically derives window parameters so that the output has the specified (D_out, H_out, W_out) shape regardless of input size. For output voxel (d,h,w)(d, h, w):

y[n,c,d,h,w]=1(deds)(hehs)(wews)i=dsde1j=hshe1k=wswe1x[n,c,i,j,k]y[n,c,d,h,w] = \frac{1}{(d_e-d_s)(h_e-h_s)(w_e-w_s)} \sum_{i=d_s}^{d_e-1} \sum_{j=h_s}^{h_e-1} \sum_{k=w_s}^{w_e-1} x[n,c,i,j,k]

where the boundary indices follow the same ratio formula as in AdaptiveAvgPool2d, applied independently per dimension.

Parameters

output_sizeint or tuple[int, int, int]
Target (D_out, H_out, W_out). A scalar is broadcast to all three dimensions.

Attributes

output_sizeint or tuple[int, int, int]

Notes

  • Input: (N, C, D_in, H_in, W_in)
  • Output: (N, C, D_out, H_out, W_out)
  • Pass output_size=(1, 1, 1) for 3-D global average pooling, which collapses a volumetric feature map to a single vector per channel — the standard head for 3-D classification networks.
  • Window sizes are determined per output cell and may differ, but all cells together partition the input without overlap or gap.

Examples

3-D global average pooling:
>>> import lucid
>>> import lucid.nn as nn
>>> gap = nn.AdaptiveAvgPool3d(output_size=1)
>>> x = lucid.ones((2, 256, 4, 7, 7))
>>> y = gap(x)
>>> y.shape
(2, 256, 1, 1, 1)
Fixed spatial output with variable input:
>>> pool = nn.AdaptiveAvgPool3d(output_size=(2, 4, 4))
>>> for d in [4, 8, 16]:
...     x = lucid.ones((1, 64, d, 28, 28))
...     assert pool(x).shape == (1, 64, 2, 4, 4)

Methods (3)

dunder

__init__

None
__init__(output_size: _Size3d)
source

Initialise the AdaptiveAvgPool3d module. See the class docstring for parameter semantics.

fn

forward

Tensor
forward(x: Tensor)
source

Apply the pooling operation to the input tensor.

Parameters

inputTensor
Input tensor of shape (N,C,)(N, C, *) where * are the spatial dimensions appropriate for this pooling layer.

Returns

Tensor

Pooled output tensor.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.