Skip to content

  • 体验新版
    • 正在加载...
  • 登录
  • PaddlePaddle
  • Paddle
  • Issue
  • #22724

P
Paddle
  • 项目概览

PaddlePaddle / Paddle
大约 2 年 前同步成功

通知 2325
Star 20933
Fork 5424
  • 代码
    • 文件
    • 提交
    • 分支
    • Tags
    • 贡献者
    • 分支图
    • Diff
  • Issue 1423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
  • Wiki 0
    • Wiki
  • 分析
    • 仓库
    • DevOps
  • 项目成员
  • Pages
P
Paddle
  • 项目概览
    • 项目概览
    • 详情
    • 发布
  • 仓库
    • 仓库
    • 文件
    • 提交
    • 分支
    • 标签
    • 贡献者
    • 分支图
    • 比较
  • Issue 1,423
    • Issue 1,423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
    • 合并请求 543
  • Pages
  • 分析
    • 分析
    • 仓库分析
    • DevOps
  • Wiki 0
    • Wiki
  • 成员
    • 成员
  • 收起侧边栏
  • 动态
  • 分支图
  • 创建新Issue
  • 提交
  • Issue看板
已关闭
开放中
Opened 2月 22, 2020 by saxon_zh@saxon_zhGuest

Error: Cannot find fetch variable in scope, fetch_var_name is crop_tensor_0.tmp_0

Created by: txyugood

代码如下:

import numpy as np
from paddle import fluid
a = np.zeros([60000,4], dtype='float32')
# a[50000] = np.array([1,1,1,1])

input = fluid.layers.data(shape=[60000, 4], append_batch_size=False, name='image')
i = fluid.layers.fill_constant(shape=[1], dtype='int32', value=0)  # 循环计数器
loop_len = fluid.layers.fill_constant(shape=[1], dtype='int32', value=input.shape[0])

cond = fluid.layers.less_than(x=i, y=loop_len)  # 循环条件
while_op = fluid.layers.While(cond=cond)
offset = fluid.layers.zeros(shape=[1], dtype='int32')

with while_op.block():  # 循环体
    crop = fluid.layers.crop_tensor(input,
                                    shape=[1, 4],
                                    offsets=[i, offset])
    i = fluid.layers.increment(x=i, value=1, in_place=True)
    fluid.layers.less_than(x=i, y=loop_len, cond=cond)  # 更新循环条件

exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
res = exe.run(fluid.default_main_program(), feed={'image':a}, fetch_list=[crop])
print(res[0])

log 如下:

Connected to pydev debugger (build 193.6494.30)
/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/paddle/fluid/executor.py:795: UserWarning: The current program is empty.
  warnings.warn(error_info)
/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/paddle/fluid/executor.py:779: UserWarning: The following exception is not an EOF exception.
  "The following exception is not an EOF exception.")
Traceback (most recent call last):
  File "/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/paddle/fluid/executor.py", line 780, in run
    six.reraise(*sys.exc_info())
  File "/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/six.py", line 703, in reraise
    raise value
  File "/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/paddle/fluid/executor.py", line 775, in run
    use_program_cache=use_program_cache)
  File "/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/paddle/fluid/executor.py", line 822, in _run_impl
    use_program_cache=use_program_cache)
  File "/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/paddle/fluid/executor.py", line 899, in _run_program
    fetch_var_name)
paddle.fluid.core_avx.EnforceNotMet: 

--------------------------------------------
C++ Call Stacks (More useful to developers):
--------------------------------------------
0   std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > paddle::platform::GetTraceBackString<char const*>(char const*&&, char const*, int)
1   paddle::platform::EnforceNotMet::EnforceNotMet(std::exception_ptr, char const*, int)
2   paddle::operators::FetchOp::RunImpl(paddle::framework::Scope const&, paddle::platform::Place const&) const
3   paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, paddle::platform::Place const&)
4   paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool)
5   paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, bool)
6   void pybind11::cpp_function::initialize<paddle::pybind::pybind11_init_core_avx(pybind11::module&)::$_103, void, paddle::framework::Executor&, paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, pybind11::name, pybind11::is_method, pybind11::sibling>(paddle::pybind::pybind11_init_core_avx(pybind11::module&)::$_103&&, void (*)(paddle::framework::Executor&, paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&), pybind11::name const&, pybind11::is_method const&, pybind11::sibling const&)::'lambda'(pybind11::detail::function_call&)::__invoke(pybind11::detail::function_call&)
7   pybind11::cpp_function::dispatcher(_object*, _object*, _object*)
8   __pyx_f_18_pydevd_frame_eval_35pydevd_frame_evaluator_darwin_36_64_get_bytecode_while_frame_eval
9   __pyx_f_18_pydevd_frame_eval_35pydevd_frame_evaluator_darwin_36_64_get_bytecode_while_frame_eval
10  __pyx_f_18_pydevd_frame_eval_35pydevd_frame_evaluator_darwin_36_64_get_bytecode_while_frame_eval
11  __pyx_f_18_pydevd_frame_eval_35pydevd_frame_evaluator_darwin_36_64_get_bytecode_while_frame_eval
12  __pyx_f_18_pydevd_frame_eval_35pydevd_frame_evaluator_darwin_36_64_get_bytecode_while_frame_eval
13  __pyx_f_18_pydevd_frame_eval_35pydevd_frame_evaluator_darwin_36_64_get_bytecode_while_frame_eval

------------------------------------------
Python Call Stacks (More useful to users):
------------------------------------------
  File "/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/paddle/fluid/framework.py", line 2488, in append_op
    attrs=kwargs.get("attrs", None))
  File "/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/paddle/fluid/executor.py", line 563, in _add_feed_fetch_ops
    attrs={'col': i})
  File "/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/paddle/fluid/executor.py", line 894, in _run_program
    fetch_var_name=fetch_var_name)
  File "/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/paddle/fluid/executor.py", line 822, in _run_impl
    use_program_cache=use_program_cache)
  File "/Users/alex/miniconda3/envs/paddle161/lib/python3.6/site-packages/paddle/fluid/executor.py", line 775, in run
    use_program_cache=use_program_cache)
  File "/Users/alex/baidu/yolact_paddle/test.py", line 23, in <module>
    res = exe.run(fluid.default_main_program(), feed={'image':a}, fetch_list=[crop])
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 1434, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 1427, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 2118, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 2127, in <module>
    main()

----------------------
Error Message Summary:
----------------------
Error: Cannot find fetch variable in scope, fetch_var_name is crop_tensor_0.tmp_0 at (/home/teamcity/work/ef54dc8a5b211854/paddle/fluid/operators/controlflow/fetch_op.cc:38)
  [operator < fetch > error]

在循环中使用 fluid.layers.crop_tensor报错,大概是说作用域的问题,但是文档里没有看到 While 作用域相关内容,请问这个需要如何解决?

指派人
分配到
无
里程碑
无
分配里程碑
工时统计
无
截止日期
无
标识: paddlepaddle/Paddle#22724
渝ICP备2023009037号

京公网安备11010502055752号

网络110报警服务 Powered by GitLab CE v13.7
开源知识
Git 入门 Pro Git 电子书 在线学 Git
Markdown 基础入门 IT 技术知识开源图谱
帮助
使用手册 反馈建议 博客
《GitCode 隐私声明》 《GitCode 服务条款》 关于GitCode
Powered by GitLab CE v13.7