image_resize

    注意: 参数 actual_shape 将被弃用,请使用 out_shape 替代。

    该OP用于调整一个batch中图片的大小。

    输入为4-D Tensor时形状为(num_batches, channels, in_h, in_w)或者(num_batches, in_h, in_w, channels),输入为5-D Tensor时形状为(num_batches, channels, in_d, in_h, in_w)或者(num_batches, in_d, in_h, in_w, channels),并且调整大小只适用于深度,高度和宽度对应的维度。

    支持的插值方法:

    最近邻插值是在输入张量的高度和宽度上进行最近邻插值。

    双线性插值是线性插值的扩展,用于在直线2D网格上插值两个变量(例如,该操作中的H方向和W方向)的函数。 关键思想是首先在一个方向上执行线性插值,然后在另一个方向上再次执行线性插值。

    三线插值是线性插值的一种扩展,是3参数的插值方程(比如op里的D,H,W方向),在三个方向上进行线性插值。

    Align_corners和align_mode是可选参数,插值的计算方法可以由它们选择。

    有关最近邻插值的详细信息,请参阅维基百科: https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation

    有关双线性插值的详细信息,请参阅维基百科:

    有关三线插值的详细信息,请参阅维基百科: https://en.wikipedia.org/wiki/Trilinear_interpolation

    4-D Tensor,形状为 (num_batches, channels, out_h, out_w) 或 (num_batches, out_h, out_w, channels);或者5-D Tensor,形状为 (num_batches, channels, out_d, out_h, out_w) 或 (num_batches, out_d, out_h, out_w, channels)。

    1. import paddle.fluid as fluid
    2. input = fluid.layers.data(name="input", shape=[3,6,9], dtype="float32")
    3. # input.shape = [-1, 3, 6, 9], where -1 indicates batch size, and it will get the exact value in runtime.
    4. out = fluid.layers.image_resize(input, out_shape=[12, 12], resample="NEAREST")
    5. out0 = fluid.layers.image_resize(input, out_shape=[12, 12], resample="NEAREST")
    6. # out0.shape = [-1, 3, 12, 12], it means out0.shape[0] = input.shape[0] in runtime.
    7. # out_shape is a list in which each element is a integer or a tensor Variable
    8. out1 = fluid.layers.image_resize(input, out_shape=[12, dim1], resample="NEAREST")
    9. # out_shape is a 1-D tensor Variable
    10. shape_tensor = fluid.layers.data(name="shape_tensor", shape=[2], dtype="int32", append_batch_size=False)
    11. out2 = fluid.layers.image_resize(input, out_shape=shape_tensor, resample="NEAREST")
    12. # out2.shape = [-1, 3, -1, -1]
    13. # when use actual_shape
    14. actual_shape_tensor = fluid.layers.data(name="actual_shape_tensor", shape=[2], dtype="int32", append_batch_size=False)
    15. out3 = fluid.layers.image_resize(input, out_shape=[4, 4], resample="NEAREST", actual_shape=actual_shape_tensor)
    16. # out3.shape = [-1, 3, 4, 4]
    17. # scale is a Variable
    18. scale_tensor = fluid.layers.data(name="scale", shape=[1], dtype="float32", append_batch_size=False)
    19. out4 = fluid.layers.image_resize(input, scale=scale_tensor)