fn
dirac_
→Tensordirac_(tensor: Tensor, groups: int = 1)Initialise a 3/4/5-D convolution weight in-place as a Dirac delta.
The kernel is filled with zeros except for a single 1 at the
spatial centre of each (out_channel, in_channel) matched pair,
so that — at initialisation — the convolution acts as the identity
function on its input channels (subject to channel-count matching
per group). Useful for residual networks where one wants gradients
to flow unchanged through deep stacks at step 0.
Parameters
tensorTensorConvolution weight of shape
(out_channels, in_channels // groups, *K) where K is
the 1-D, 2-D, or 3-D spatial kernel shape.groupsint= 1Number of groups in the convolution.
out_channels must be
divisible by groups. Default 1.Returns
Tensortensor (mutated) for chaining.
Raises
ValueErrorIf
tensor.ndim is not in {3, 4, 5} or if
out_channels is not divisible by groups.Notes
For convolution input with the resulting weight, where .
Examples
>>> import lucid
>>> from lucid.nn.init import dirac_
>>> w = lucid.empty(16, 16, 3, 3) # (out, in, kH, kW)
>>> dirac_(w)