文档中示例代码运行异常
军人的生活就是 发布于2021-01 浏览:439 回复:0
0
收藏

文档连接:https://aistudio.baidu.com/aistudio/projectdetail/1457687

paddlepaddle版本:2.0

文档源代码:

import paddle.fluid as fluid
import numpy as np

a = fluid.layers.create_tensor(dtype='int64', name='a')
b = fluid.layers.create_tensor(dtype='int64', name='b')
y = fluid.layers.sum(x=[a, b])

place = fluid.CPUPlace()
exe = fluid.executor.Executor(place)
# 进行参数初始化
exe.run(fluid.default_startup_program())

a1 = np.array([3, 2]).astype('int64')
b1 = np.array([1, 1]).astype('int64')

out_a, out_b, result = exe.run(program=fluid.default_main_program(),
                               feed={'a': a1, 'b': b1},
                               fetch_list=[a, b, y])

print(out_a, " + ", out_b," = ", result)


 

Traceback (most recent call last):
File "test.py", line 6, in
y = fluid.layers.sum(x=[a, b])
File "/home/jinhl/anaconda3/envs/py36/lib/python3.6/site-packages/paddle/fluid/layers/nn.py", line 10821, in sum
return paddle.add_n(x)
File "/home/jinhl/anaconda3/envs/py36/lib/python3.6/site-packages/paddle/tensor/math.py", line 839, in add_n
return core.ops.sum(inputs, 'use_mkldnn', False)
ValueError: (InvalidArgument) Sum operator should have at least one tensor
[Hint: Expected dtype != -1, but received dtype:-1 == -1:-1.] (at /paddle/paddle/fluid/operators/sum_op.cc:146)
[Hint: If you need C++ stacktraces for debugging, please set `FLAGS_call_stack_level=2`.]
[operator < sum > error]

是版本更新之后,接口发生变化了吗?

收藏
点赞
0
个赞
TOP
切换版块