fn

conv_transpose2d

Tensor
conv_transpose2d(x: Tensor, weight: Tensor, bias: Tensor | None = None, stride: int | tuple[int, int] = 1, padding: int | tuple[int, int] = 0, output_padding: int | tuple[int, int] = 0, groups: int = 1, dilation: int | tuple[int, int] = 1)
source

Transposed 2-D convolution — the standard upsampling primitive.

Also referred to as "deconvolution", though this is not the mathematical inverse of conv2d. Performs the transpose of a 2-D forward convolution: each input cell scatters a weighted copy of the kernel into the (larger) output canvas. Used in image-segmentation decoders, GAN generators, super-resolution networks, and U-Net style architectures.

Parameters

xTensor
Input of shape (N, C_in, H_in, W_in).
weightTensor
Filters of shape (C_in, C_out/groups, kH, kW).
biasTensor= None
Per-output-channel bias of shape (C_out,). Materialised as zeros when None.
strideint or (int, int)= 1
Upsampling factor between input cells (default 1).
paddingint or (int, int)= 0
Implicit zero-padding subtracted from each side of the output.
output_paddingint or (int, int)= 0
Additional one-sided trailing padding on the output, used to resolve the size ambiguity when stride > 1.
groupsint= 1
Channel grouping.
dilationint or (int, int)= 1
Spacing between kernel taps.

Returns

Tensor

Output of shape (N, C_out, H_out, W_out) where each spatial dimension satisfies

Hout=(Hin1)sH2pH+dH(kH1)+opH+1H_{\text{out}} = (H_{\text{in}} - 1) \cdot s_H - 2 p_H + d_H (k_H - 1) + \text{op}_H + 1

Notes

Checkerboard artifacts are a well-known failure mode when kernel_size is not a multiple of stride. Alternatives are nearest/bilinear upsample + conv2d, or pixel-shuffle (sub-pixel convolution).

The forward of this op equals the backward of conv2d w.r.t. input; that duality is what makes it useful as a learnable upsampler — its gradients give the structure of an ordinary conv.

Examples

>>> import lucid
>>> from lucid.nn.functional import conv_transpose2d
>>> x = lucid.randn(1, 16, 7, 7)
>>> w = lucid.randn(16, 8, 4, 4)
>>> y = conv_transpose2d(x, w, stride=2, padding=1)
>>> y.shape
(1, 8, 14, 14)