fn
interpolate
→Tensorinterpolate(x: Tensor, size: int | tuple[int, ...] | None = None, scale_factor: float | tuple[float, ...] | None = None, mode: str = 'nearest', align_corners: bool | None = None, recompute_scale_factor: bool | None = None)Resample an N-D tensor to a target spatial size or scale factor.
Supports the standard family of image / volume resampling kernels.
The leading two axes (N batch and C channels) are preserved;
only the trailing spatial axes are resampled.
Parameters
xTensorInput of shape
(N, C, *spatial) where len(spatial) is 1
(linear), 2 (bilinear / bicubic / area / nearest-2d) or 3
(trilinear / nearest-3d).sizeint or tuple of int= NoneTarget spatial size. Mutually exclusive with
scale_factor.scale_factorfloat or tuple of float= NoneMultiplicative factor applied to each spatial axis. Output size
is
floor(in_size * scale_factor).modestr= 'nearest'One of
"nearest", "linear", "bilinear", "bicubic",
"trilinear", "area", "nearest-exact". Default
"nearest".align_cornersbool= NoneOnly meaningful for
"linear" / "bilinear" / "bicubic"
/ "trilinear". If True, the corner pixels of the input
and output are exactly aligned, and the values at those corners
are preserved. If False (default), pixels are treated as
1×1 squares and the sampling grid is centred — this matches
the convention used by most modern vision frameworks.recompute_scale_factorbool= NoneIf
True, recompute scale_factor from the resolved
size to avoid floating-point drift when chaining resamples.Returns
TensorResampled tensor of shape (N, C, *out_spatial).
Notes
The two align_corners conventions produce different sampling
grids — for the default, vs
for
align_corners=True. The choice matters when fine alignment with
other ops (warping, geometric losses) is required.
Examples
>>> import lucid
>>> from lucid.nn.functional import interpolate
>>> x = lucid.randn(1, 3, 32, 32)
>>> y = interpolate(x, scale_factor=2.0, mode="bilinear", align_corners=False)
>>> y.shape
(1, 3, 64, 64)