torch.nn.functional.interpolate
(input, size=None, scale_factor=None, mode='nearest', align_corners=None, recompute_scale_factor=None, antialias=False)
Down/up samples the input to either the given size
or the given scale_factor
The algorithm used for interpolation is determined by mode
.
Currently temporal, spatial and volumetric sampling are supported, i.e. expected inputs are 3-D, 4-D or 5-D in shape.
The input dimensions are interpreted in the form: mini-batch x channels x [optional depth] x [optional height] x width.
The modes available for resizing are: nearest, linear (3D-only), bilinear, bicubic (4D-only), trilinear (5D-only), area, nearest-exact
官方文档给的解释是进行上下采样到指定大小,可以理解是对图片进行缩放,可以将图片缩放到指定大小。mode为调整的大小模式,有些只支持4D,5D,要先对数据进行处理,增加维度后才可以使用。例如对于一个三维的图像,要使用双三次插值,因为双三次插值只支持思维数据,可以使用torch.unsqueeze()对数据增加1的维度
torch.unsqueeze(x,0)
即在数据的第0个维度添加1,例如一个3*64*64的数据,经过处理后变为1*3*64*64