conv_transpose2d
→Tensorconv_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)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(N, C_in, H_in, W_in).weightTensor(C_in, C_out/groups, kH, kW).biasTensor= None(C_out,). Materialised as
zeros when None.strideint or (int, int)= 11).paddingint or (int, int)= 0output_paddingint or (int, int)= 0stride > 1.groupsint= 1dilationint or (int, int)= 1Returns
TensorOutput of shape (N, C_out, H_out, W_out) where each spatial
dimension satisfies
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)