LazyConv3d
_LazyConvMixinConv3dLazyConv3d(out_channels: int, kernel_size: _Size3d, stride: _Size3d = 1, padding: _Size3d | str = 0, dilation: _Size3d = 1, groups: int = 1, bias: bool = True, padding_mode: PaddingMode = 'zeros', device: DeviceLike = None, dtype: DTypeLike = None)A Conv3d that infers in_channels from the first input.
Lazy initialization for 3D convolution: in_channels need not be
specified at construction time. Weight allocation and Kaiming
uniform initialization are deferred until the first forward
call (or state_dict load), at which point C_in is read from
x.shape[1].
Parameters
out_ channelsintkernel_ sizeint or tuple[int, int, int]strideint or tuple[int, int, int]= 11.paddingint, tuple[int, int, int], or str= 0"same" / "valid" string specifier.
Default: 0.dilationint or tuple[int, int, int]= 11.groupsint= 11.biasbool= TrueTrue, a learnable bias is added after materialization.
Default: True.padding_ modestr= 'zeros'"zeros", "reflect", "replicate", or "circular".
Default: "zeros".deviceDeviceLike= NoneNone.dtypeDTypeLike= NoneNone.Attributes
Notes
Input:
— is
inferred automatically.
Output:
—
same formula as Conv3d.
State-dict materialization. A 5-D weight tensor in the
state_dict triggers materialization before parameter copying.
Examples
Lazy 3D conv in a volumetric network:
>>> import lucid
>>> import lucid.nn as nn
>>> lazy3d = nn.LazyConv3d(out_channels=32, kernel_size=3, padding=1)
>>> x = lucid.zeros(2, 4, 16, 32, 32) # in_channels=4 inferred
>>> y = lazy3d(x)
>>> y.shape
(2, 32, 16, 32, 32)
Verify materialization:
>>> import lucid
>>> import lucid.nn as nn
>>> lazy3d = nn.LazyConv3d(out_channels=16, kernel_size=3, padding=1)
>>> print(lazy3d.in_channels)
None
>>> _ = lazy3d(lucid.zeros(1, 8, 4, 4, 4))
>>> print(lazy3d.in_channels)
8Used by 1
Constructors
1__init__
→None__init__(out_channels: int, kernel_size: _Size3d, stride: _Size3d = 1, padding: _Size3d | str = 0, dilation: _Size3d = 1, groups: int = 1, bias: bool = True, padding_mode: PaddingMode = 'zeros', device: DeviceLike = None, dtype: DTypeLike = None)Initialise the LazyConv3d module. See the class docstring for parameter semantics.
Instance methods
4Return a string representation of the layer's configuration.
The eager layer's forward; the first call sizes in_channels from input.
initialize_parameters
→Nonefrom _LazyConvMixininitialize_parameters(input: Tensor, args: object = (), kwargs: object = {})Size in_channels from input and allocate the weights, if not sized yet.
Takes the extra positional and keyword arguments the reference's lazy convolutions accept, and ignores them, as it does.
Parameters
inputTensor*argsobject= ()**kwargsobject= ()Re-draw the values; nothing to do until the layer has been sized.