space_to_depth

    重组时,依据 blocksize 指明的数据块大小, 对形为 [batch, channel, height, width] 的输入张量进行space_to_depth(广度至深度)运算,生成形为 的输出:

    范例如下:

    • 参数:
      • x (Variable) – 输入,形状为 [batch, channel, height, width] 的4维Tensor或LoD Tensor。数据类型支持int32,int64,float32或float64。
      • blocksize (int) – 在每个特征图上选择元素时采用的块大小,应该 >= 2
      • name (str,可选) - 具体用法请参见 ,一般无需设置,默认值为None。

    返回类型:Variable

    • 抛出异常:
    1. import paddle.fluid as fluid
    2. import numpy as np
    3.  
    4. data = fluid.data(
    5. name='data', shape=[1, 4, 2, 2], dtype='float32')
    6. space_to_depthed = fluid.layers.space_to_depth(
    7. x=data, blocksize=2)
    8.  
    9. exe = fluid.Executor(fluid.CPUPlace())
    10. data_np = np.arange(0,16).reshape((1,4,2,2)).astype('float32')
    11.  
    12. #array([[[[ 0., 1.], [ 2., 3.]],
    13. # [[ 4., 5.], [ 6., 7.]],
    14. # [[ 8., 9.], [10., 11.]],
    15. # [[12., 13.], [14., 15.]]]], dtype=float32)
    16.  
    17. out_main = exe.run(fluid.default_main_program(),
    18. feed={'data': data_np},
    19. fetch_list=[space_to_depthed])
    20.  
    21. print(out_main)
    22. #[array([[[[ 0.]], [[ 4.]], [[ 1.]], [[ 5.]],
    23. # [[ 8.]], [[12.]], [[ 9.]], [[13.]],
    24. # [[10.]], [[14.]], [[11.]], [[15.]]]], dtype=float32)]