resize_trilinear
注意: 参数 actual_shape
将被弃用,请使用 out_shape
替代。
该层对输入进行放缩,基于给定的由 actual_shape
, out_shape
, scale
确定的输出shape,进行三线插值。三线插值是包含三个参数的线性插值方程(D方向,H方向, W方向),在一个3D格子上进行三个方向的线性插值。更多细节,请参考维基百科:https://en.wikipedia.org/wiki/Trilinear_interpolation Align_corners和align_mode都是可选参数,可以用来设置插值的计算方法,如下:
参数:
out_shape (list|tuple|Variable|None) – 调整最近邻层的输出形状,形式为(out_h, out_w)。默认值:None。如果
out_shape
是列表,每一个元素可以是整数或者shape为[1]的变量。如果out_shape
是变量,则其维度大小为1。scale (float|None) – 输入高、宽的乘法器。
out_shape
和scale
二者至少设置其一。out_shape
具有比scale
更高的优先级。 默认: Nonename (str|None) – 输出变量的命名
align_corners (bool)- 一个可选的bool型参数,如果为True,则将输入和输出张量的4个角落像素的中心对齐,并保留角点像素的值。 默认值:True
align_mode (bool) - (int,默认为’1’),双线性插值选项,src_idx = scale*(dst_index+0.5)-0.5时取’0’,src_idx = scale*dst_index时取’1’。
data_format (str,可选)- 指定输入的数据格式,输出的数据格式将与输入保持一致,可以是”NCDHW”和”NDHWC”。N是批尺寸,C是通道数,H是特征高度,W是特征宽度。默认值:”NCDHW”。
代码示例
import paddle.fluid as fluid
input = fluid.layers.data(name="input", shape=[3,6,9,11], dtype="float32")
out0 = fluid.layers.resize_trilinear(input, out_shape=[12, 12, 12])
# out0.shape = [-1, 3, 12, 12, 12], it means out0.shape[0] = input.shape[0] in runtime.
# out_shape is a list in which each element is a integer or a tensor Variable
dim1 = fluid.layers.data(name="dim1", shape=[1], dtype="int32", append_batch_size=False)
# out1.shape = [-1, 3, 12, -1, 4]
# out_shape is a 1-D tensor Variable
out2 = fluid.layers.resize_trilinear(input, out_shape=shape_tensor)
# out2.shape = [-1, 3, -1, -1, -1]
# when use actual_shape
actual_shape_tensor = fluid.layers.data(name="actual_shape_tensor", shape=[3], dtype="int32", append_batch_size=False)
out3 = fluid.layers.resize_trilinear(input, out_shape=[4, 4, 8], actual_shape=actual_shape_tensor)
# out3.shape = [-1, 3, 4, 4, 8]
# scale is a Variable
scale_tensor = fluid.layers.data(name="scale", shape=[1], dtype="float32", append_batch_size=False)
# out4.shape = [-1, 3, -1, -1, -1]