class

LazyConv3d

extendsConv3d
LazyConv3d(out_channels: int, kernel_size: _Size3d, stride: _Size3d = 1, padding: _Size3d | str = 0, dilation: _Size3d = 1, groups: int = 1, bias: bool = True, padding_mode: str = 'zeros', device: DeviceLike = None, dtype: DTypeLike = None)
source

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_channelsint
Number of output channels.
kernel_sizeint or tuple[int, int, int]
Size of the 3D convolving kernel.
strideint or tuple[int, int, int]= 1
Stride of the convolution. Default: 1.
paddingint, tuple[int, int, int], or str= 0
Zero-padding or "same" / "valid" string specifier. Default: 0.
dilationint or tuple[int, int, int]= 1
Spacing between kernel elements. Default: 1.
groupsint= 1
Number of blocked connections. Default: 1.
biasbool= True
If True, a learnable bias is added after materialization. Default: True.
padding_modestr= 'zeros'
"zeros", "reflect", "replicate", or "circular". Default: "zeros".
deviceDeviceLike= None
Device used when allocating weights. Default: None.
dtypeDTypeLike= None
Data type used when allocating weights. Default: None.

Attributes

weightParameter or None
None before materialization; shape (out_channels, in_channels // groups, K_D, K_H, K_W) afterwards.
biasParameter or None
None before materialization; (out_channels,) if bias=True, else None.
in_channelsint or None
None before the first forward pass.

Notes

Input: (N,Cin,D,H,W)(N, C_{\text{in}}, D, H, W)CinC_{\text{in}} is inferred automatically. Output: (N,Cout,Dout,Hout,Wout)(N, C_{\text{out}}, D_{\text{out}}, H_{\text{out}}, W_{\text{out}}) — 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)
8

Methods (3)

dunder

__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: str = 'zeros', device: DeviceLike = None, dtype: DTypeLike = None)
source

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

fn

forward

Tensor
forward(x: Tensor)
source

Apply the convolution to the input tensor.

Parameters

inputTensor
Input tensor of shape (N,Cin,)(N, C_{\text{in}}, *).

Returns

Tensor

Output tensor of shape (N,Cout,)(N, C_{\text{out}}, *) with spatial dimensions determined by stride, padding, dilation, and kernel size.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.