Skip to content
class

InterpolateBilinearBackward

InterpolateBilinearBackward

Autograd node for 2-D bilinear interpolation.

Resizes a 4-D tensor of shape (N, C, H_in, W_in) to (N, C, H_out, W_out) by linearly interpolating between the four neighbouring input pixels:

y[i,j]=∑a,b∈{0,1}wia wjb x[i0+a,j0+b] y[i, j] = \sum_{a, b \in \{0, 1\}} w_{i}^{a} \, w_{j}^{b} \, x[i_0 + a, j_0 + b]

where (i0,j0)(i_0, j_0) is the integer floor of the source coordinate and wiaw_i^a, wjbw_j^b are the fractional bilinear weights computed from the align_corners rule above. The backward distributes grad_out back to the same four pixels weighted by the same bilinear coefficients, recomputed in the backend (no per-sample weight cache is saved).

Math

xin={j⋅(Win−1)/(Wout−1)align_corners(j+0.5)⋅Win/Wout−0.5otherwise x_{\text{in}} = \begin{cases} j \cdot (W_{\text{in}} - 1) / (W_{\text{out}} - 1) & \text{align\_corners} \\ (j + 0.5) \cdot W_{\text{in}} / W_{\text{out}} - 0.5 & \text{otherwise} \end{cases}

(analogous formula for yiny_{\text{in}}).

Attributes

schema_v1OpSchema
"interpolate_bilinear", AmpPolicy::Promote.
H_in_, W_in_int
Saved input spatial dimensions.
H_out_, W_out_int
Requested output spatial dimensions.
align_corners_bool
Coordinate mapping mode (see file header).
orig_shape_Shape
Full (N, C, H_in, W_in) shape for backward reconstruction.

Static methods

1
static

forward

→TensorImplPtr
int forward(const int & input, int H_out, int W_out, bool align_corners)

Compute the bilinear resize with autograd wiring.

Parameters

inputTensorImplPtr
4-D input tensor of shape (N, C, H_in, W_in).
H_outint
Desired output height.
W_outint
Desired output width.
align_cornersbool
Coordinate mapping mode (see file header).

Returns

TensorImplPtr

Resampled tensor of shape (N, C, H_out, W_out).

Raises

ShapeMismatch
If input is not 4-D.

Methods

2
fn

apply

int apply(int grad_out)

Backward pass: scatters grad_out to source pixels using the same bilinear weights as the forward.

fn

apply_for_graph

int apply_for_graph(const int & grad_out)

Graph-mode backward: the same adjoint as two matmuls against the 1-D resampling matrices, so it can be differentiated again.