官方教程中ifelse执行报错,请教
yz2yz2 发布于2020-09-16 浏览:1401 回复:0
0
收藏

https://aistudio.baidu.com/aistudio/education/lessonvideo/658562

照着官方教程里,敲了ifelse这段代码,在本地和aistudio上都报相同的错误,求助该如何解决,讲师自己没有跑过这代码吗?

import paddle.fluid as fluid

a = fluid.layers.fill_constant(shape=[2,1], dtype='int64', value=5)
b = fluid.layers.fill_constant(shape=[2,1], dtype='int64', value=6)

ifcond = fluid.layers.less_than(x=a, y=b)
ie = fluid.layers.IfElse(ifcond)
with ie.true_block():
c = ie.input(a)
c += 1
ie.output(c)

cpu = fluid.CPUPlace()
exe = fluid.Executor(cpu)
exe.run(fluid.default_startup_program())

outs = exe.run(fluid.default_main_program(), fetch_list=[c])
print(outs)

报错如下:

----------------------
Error Message Summary:
----------------------
NotFoundError: Input variable(tmp_0) cannot be found in scope for operator 'Fetch'.Confirm that you have used the fetch `Variable` format instead of the string literal('tmp_0') in `fetch_list` parameter when using `executor.run` method. In other words, the format of `executor.run(fetch_list=[fetch_var])`(fetch_var is a Variable) is recommended.
[Hint: fetch_var should not be null.] at (D:\1.8.4\paddle\paddle\fluid\operators\controlflow\fetch_op.cc:82)
[operator < fetch > error]

 

 

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