space_to_depth

    该OP对成块的空间数据进行重组,输出一个输入张量的拷贝,其高度和宽度维度上的值移至通道维度。

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

    该OP适用于在卷积间重放缩激活函数,并保持所有的数据。

    范例如下:

    参数:

    • blocksize (int) – 在每个特征图上选择元素时采用的块大小,应该 >= 2

    • name (str,可选) - 具体用法请参见 ,一般无需设置,默认值为None。

    返回:输出,形状为 [batch, channel * blocksize * blocksize, height/blocksize, width/blocksize] 的4维Tensor或LoD Tensor。数据类型与输入 x 一致。

    返回类型:Variable

    • TypeError - blocksize 必须是int64类型

    代码示例

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