首页 Paddle框架 帖子详情
elementwise_mul ShapeError
收藏
快速回复
Paddle框架 问答深度学习 4999 1
elementwise_mul ShapeError
收藏
快速回复
Paddle框架 问答深度学习 4999 1

环境
cpu
paddle1.6
python3.7
代码
`import paddle.fluid as fluid
import numpy as np

x = fluid.layers.data(name='x', shape=[1], dtype='float32')
x_s = fluid.layers.shape(x)

y = fluid.layers.create_parameter(name='y', shape=[1], dtype='float32')
y_s = fluid.layers.shape(y)

out_put = fluid.layers.elementwise_mul(y, x)`

错误信息
line 10, in <module> out_put = fluid.layers.elementwise_mul(y, x) Error: ShapeError: the dimension of input X must greater than or equal to the one of input Y. But received: the shape of input X = [1], the dimension of input X = 1, the shape of input Y = [-1, 1], the dimension of input Y = 2 [Hint: Expected x_dim.size() >= y_dim.size(), but received x_dim.size():1 < y_dim.size():2.] at (/paddle/paddle/fluid/operators/elementwise/elementwise_op.h:61) [operator < elementwise_mul > error]
x,y的shape都是[1],这里怎么说有一个是[-1,1]呢

0
收藏
回复
全部评论(1)
时间顺序
AIStudio790260
#2 回复于2020-01

您好,默认情况下,fluid.layers.data会在shape前面加-1作为batch_size,所以x的shape是[-1, 1],而y是[1],详见fluid.layers.data
可以设置x = fluid.layers.data(name='x', shape=[1], dtype='float32', append_batch_size=False),不加-1。

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户