interpolate(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, antialias: bool = False)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
Input of shape
(N, C, *spatial). "nearest",
"nearest-exact" and "area" take 1, 2 or 3 spatial axes;
"linear" takes 1, "bilinear" / "bicubic" 2 and
"trilinear" 3.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", "nearest-exact", "linear",
"bilinear", "bicubic", "trilinear", "area".
Default "nearest".align_cornersbool= NoneOnly accepted by
"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.recompute_scale_factorbool= NoneIf
True, the sampling step is in_size / out_size from the
resolved output size rather than 1 / scale_factor. Not
allowed together with size.antialiasbool= FalseFor
"bilinear" and "bicubic": when downsampling, widen
the filter over every input sample an output sample covers, so
detail finer than the output grid is averaged rather than
aliased. Default False.Returns
TensorResampled tensor of shape (N, C, *out_spatial).
Raises
ValueErrorFor an unknown mode, a mode given the wrong number of spatial
axes, both or neither of
size and scale_factor,
align_corners or antialias with a mode that has no use
for it, or a non-positive size.TypeErrorFor an integer input with any mode but the two nearest ones.
Notes
Output sample reads the input around
where when a scale factor is
given and recompute_scale_factor is not True, and
otherwise. The two
differ whenever
is not a whole number. "nearest" copies sample
and "nearest-exact" sample
; "area" is adaptive
average pooling to the output size.
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)
>>> interpolate(x, scale_factor=0.25, mode="bicubic", antialias=True).shape
(1, 3, 8, 8)