一个关于paddle.fluid.layers.space_to_depth的问题
Created by: cyfwry
欢迎您对PaddlePaddle提出建议,非常感谢您对PaddlePaddle的贡献! 在留下您的建议时,辛苦您同步提供如下信息:
- 版本、环境信息 1)PaddlePaddle版本:1.7,2 2)CPU/GPU:CPU&GPU,用的是ai studio平台环境 3)系统环境:ai studio平台环境
- 复现信息: 我尝试使用api:paddle.fluid.layers.space_to_depth(x, blocksize, name=None)(参考文档https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/layers_cn/space_to_depth_cn.html#space-to-depth),但我发现文档中给出的范例不可以成功使用(但示例可以),原因在于pd中的space_to_depth的实现和tf的space_to_depth以及pixelshuffle并不一致,它是从各个channel中提出元素并重组(而不是像其他的,从本channel中提出元素),这导致channel必须能够被blocksize**2整除。 测试代码如下: import paddle.fluid as fluid start_prog=fluid.Program() main_prog=fluid.Program() with fluid.program_guard(main_prog,start_prog): a=fluid.layers.data(name='a',shape=[1,4,4,4],dtype='int64',append_batch_size=False) b=fluid.layers.space_to_depth(a,2)
place=fluid.CPUPlace() exe=fluid.Executor(place) import numpy as np input=np.arange(64).reshape(1,4,4,4) exe.run(start_prog) exe.run(main_prog,fetch_list=[b],feed={'a':input}) 以上代码(与示例一致)能够成功执行
import paddle.fluid as fluid start_prog=fluid.Program() main_prog=fluid.Program() with fluid.program_guard(main_prog,start_prog): a=fluid.layers.data(name='a',shape=[1,1,4,4],dtype='int64',append_batch_size=False) b=fluid.layers.space_to_depth(a,2)
place=fluid.CPUPlace() exe=fluid.Executor(place) import numpy as np input=np.arange(16).reshape(1,1,4,4) exe.run(start_prog) exe.run(main_prog,fetch_list=[b],feed={'a':input}) 以上代码(与范例一致)报错:Error: input channel should be divisible of the square of SpaceToDepthOp blocksize [Hint: Expected x_dims[1] % (blocksize * blocksize) == 0, but received x_dims[1] % (blocksize * blocksize):1 != 0:0.] at (/paddle/paddle/fluid/operators/space_to_depth_op.cc:63) [operator < space_to_depth > error]
- 建议描述: 1、修改范例,使其与正确的示例一致。 2、或许未来考虑出一个和pixelshuffle一致的api?