Trilinear and Bilinear interpolation

Hi,

I’m wondering if trilinear and bilinear interpolation would be the same if I retained one of the dimensions. For example:

x = torch.rand([5, 6, 3, 30, 50]) # B C T H W
F.upsample(x, size=(3, 60, 100), mode='trilinear') # 5 6 3 60 100

Is the second tensor equivalent to bilinear upsampling of each tensor along the temporal axis?

Looks like it is.

import torch, torch.nn.functional as F
x = torch.rand([5, 6, 3, 30, 50]) # B C T H W
z = F.upsample(x, size=(3, 60, 100), mode='trilinear') # 5 6 3 60 100

z2 =  []
for t in range(3):
   x_t  = x[:, :, t, :, :]
   z2.append(F.upsample(x_t, size=(60, 100), mode='bilinear')) # 5 6 60 100
z2 = torch.stack(z2, dim=2) # 5 6 3 60 100

print(bool((z==z2).all())) # True

2 Likes