space_to_depth
space_to_depth
(x, blocksize, name=None)[源代码]
重组时,依据 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。
- x (Variable) – 输入,形状为
返回类型:Variable
- 抛出异常:
- import paddle.fluid as fluid
- import numpy as np
- data = fluid.data(
- name='data', shape=[1, 4, 2, 2], dtype='float32')
- space_to_depthed = fluid.layers.space_to_depth(
- x=data, blocksize=2)
- exe = fluid.Executor(fluid.CPUPlace())
- data_np = np.arange(0,16).reshape((1,4,2,2)).astype('float32')
- #array([[[[ 0., 1.], [ 2., 3.]],
- # [[ 4., 5.], [ 6., 7.]],
- # [[ 8., 9.], [10., 11.]],
- # [[12., 13.], [14., 15.]]]], dtype=float32)
- out_main = exe.run(fluid.default_main_program(),
- feed={'data': data_np},
- fetch_list=[space_to_depthed])
- print(out_main)
- #[array([[[[ 0.]], [[ 4.]], [[ 1.]], [[ 5.]],
- # [[ 8.]], [[12.]], [[ 9.]], [[13.]],
- # [[10.]], [[14.]], [[11.]], [[15.]]]], dtype=float32)]