PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
http://www.paddlepaddle.org/
Apache License 2.0
22.07k stars 5.54k forks source link

paddle官网的异步读取数据的范例代码中,无法使用save_inference保存模型 #44553

Open tianrenheyi09 opened 2 years ago

tianrenheyi09 commented 2 years ago

bug描述 Describe the Bug

https://www.paddlepaddle.org.cn/documentation/docs/zh/1.8/advanced_guide/data_preparing/static_mode/use_py_reader.html paddle官网的异步读取数据的范例代码中,无法使用save_inference保存模型 在以上实例代码中,每个epoch加上保存模型的代码,报错 fluid.io.save_inference_model(dirname="./modelm", feeded_var_names=['image'], target_vars=[train_loss], executor=exe)

其他补充信息 Additional Supplementary Information

No response

paddle-bot[bot] commented 2 years ago

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

ronny1996 commented 2 years ago

请问使用什么版本的Paddle和环境?有详细的错误信息吗?

tianrenheyi09 commented 2 years ago

paddle1.8,提示变量不存在

tianrenheyi09 commented 2 years ago

INFO 2022-07-22 17:57:43,665 dataloader_auto_checkpoint.py:157] end dataloader epoch_no:0
Traceback (most recent call last):
File "test5.py", line 135, in
fluid.io.save_inference_model(dirname="./modelm", feeded_var_names=['image'], target_vars=[train_loss], executor=exe)
File "/opt/_internal/cpython-3.7.0/lib/python3.7/site-packages/paddle/fluid/io.py", line 1250, in save_inference_model
prepend_feed_ops(main_program, feeded_var_names)
File "/opt/_internal/cpython-3.7.0/lib/python3.7/site-packages/paddle/fluid/io.py", line 1046, in prepend_feed_ops
out = global_block.var(name)
File "/opt/_internal/cpython-3.7.0/lib/python3.7/site-packages/paddle/fluid/framework.py", line 2392, in var
raise ValueError("var %s not in this block" % name)
ValueError: var image not in this block

tianrenheyi09 commented 2 years ago

for epoch_id in six.moves.range(1): run_iterable(train_prog, exe, train_loss, train_loader)

run_iterable(test_prog, exe, test_loss, test_loader)

fluid.io.save_inference_model(dirname="./modelm", feeded_var_names=['image'], target_vars=[train_loss], executor=exe)
ronny1996 commented 2 years ago

你好,能贴一段可复现的代码吗?

ronny1996 commented 2 years ago

你好,请设置一下save_inference_model的main_program参数

tianrenheyi09 commented 2 years ago

多谢,添加main_program参数后,可以正常保存