class
UpsamplingBilinear2d
extends
UpsampleUpsamplingBilinear2d(size: int | tuple[int, int] | None = None, scale_factor: float | tuple[float, float] | None = None)Bilinear upsampling for 4-D tensors (N, C, H, W) with aligned corners.
A convenience wrapper around Upsample with mode='bilinear' and
align_corners=True fixed. The align_corners=True default matches
the reference framework's UpsamplingBilinear2d — note that plain
Upsample(mode='bilinear') defaults to align_corners=False, which
gives different output values near the image boundary.
Bilinear interpolation performs 2-D linear interpolation between the four nearest input neighbours:
where are the fractional offsets within the
input grid cell (computed with corner-aligned coordinates when
align_corners=True).
Parameters
sizeint or tuple[int, int] or None= NoneTarget output spatial size
(H_out, W_out). Mutually exclusive
with scale_factor.scale_factorfloat or tuple[float, float] or None= NoneSpatial scale multiplier
(s_H, s_W). Mutually exclusive with
size.Notes
- Input: .
- Output: .
align_corners=Truemeans that the corner pixels of the input and output grids coincide exactly; this is the legacy behaviour used in many pre-trained segmentation and super-resolution models.- When precise sub-pixel alignment matters (e.g. image restoration),
prefer
Upsample(mode='bilinear', align_corners=False)which avoids the half-pixel offset at image boundaries.
Examples
**4× bilinear upsampling with corner alignment:**
>>> import lucid
>>> import lucid.nn as nn
>>>
>>> up = nn.UpsamplingBilinear2d(scale_factor=4)
>>> x = lucid.zeros(1, 64, 8, 8)
>>> up(x).shape
(1, 64, 32, 32)
**Upsample to a fixed output size:**
>>> up = nn.UpsamplingBilinear2d(size=(512, 512))
>>> x = lucid.zeros(2, 3, 128, 128)
>>> up(x).shape
(2, 3, 512, 512)Methods (1)
dunder
__init__
→None__init__(size: int | tuple[int, int] | None = None, scale_factor: float | tuple[float, float] | None = None)Initialise the UpsamplingBilinear2d module. See the class docstring for parameter semantics.