Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fluid.global_scope().find_var 使用问题 #18270

Closed
lgone2000 opened this issue Jun 23, 2019 · 3 comments
Closed

fluid.global_scope().find_var 使用问题 #18270

lgone2000 opened this issue Jun 23, 2019 · 3 comments
Assignees
Labels
PythonAPI User 用于标记用户问题

Comments

@lgone2000
Copy link
Contributor

下面程序中,
print(list(fluid.default_main_program().list_vars()))
可以正确输出所有变量。
但 print('v=', fluid.global_scope().find_var('fc.w_0')) 返回为None
执行 exe.run(fluid.default_startup_program()) 后有可以正常输出变量。

难道var缺省不在global_scope中?如果要求必须执行startup_program, 希望能在文档中明确说明这些变量的状态,以及什么函数是在 startup_program执行后才是可用的。 否则让人混淆。
另外如果内部状态不完整情况下调用find_var ,建议扔一个异常,而不是返回None。


def test_find_var():
    input = fluid.layers.data(name='input', shape=[1], dtype='float32')
    fc = fluid.layers.fc(name='fc', input=input, size=10)
    loss = fluid.layers.reduce_sum(input=fc)
    
    print(list(fluid.default_main_program().list_vars()))
    #will output the vars
    
    
    print('v=', fluid.global_scope().find_var('fc.w_0'))
    #output None
    
    exe = fluid.Executor(fluid.CPUPlace())
    exe.run(fluid.default_startup_program())
    print('v=', fluid.global_scope().find_var('fc.w_0'))
    #output fc.w_0

@NHZlX
Copy link
Contributor

NHZlX commented Jun 24, 2019

您好 你是要打印模型参数还是模型输出呢

@NHZlX
Copy link
Contributor

NHZlX commented Jun 25, 2019

执行 exe.run(fluid.default_startup_program()) 过程是在加载参数的过程。有必要加入到文档中去。这边会反馈到相关人员。

=======

https://gist.github.com/NHZlX/4116e09952ab54e66dadec094e9769e2 参照这个脚本, python get_var_fluid.py {your_model_dir} {the_tmp_var_name} ,该脚本默认输入全为1, 并将对应的中间变量写入到文件中。

@paddle-bot-old
Copy link

paddle-bot-old bot commented Jul 6, 2020

Since you haven't replied for more than a year, we have closed this issue/pr.
If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up.
由于您超过一年未回复,我们将关闭这个issue/pr。
若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PythonAPI User 用于标记用户问题
Projects
None yet
Development

No branches or pull requests

2 participants