PaddlePaddle / Paddle

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

2.1版本训练权重转1.8版本权重问题 #45070

Closed zzm422 closed 3 months ago

zzm422 commented 2 years ago

请提出你的问题 Please ask your question

2.1版本训练的权重model.pdparams文件转成1.8版本权重, 文件为model和model_params,用于推理?没有找到方法,求助!!!!!!!

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!

zhwesky2010 commented 2 years ago

@zzm422 你好,是说2.3的save_inference_model保存的参数能通过1.8的load_inference_model来加载吗

zhwesky2010 commented 2 years ago

@zzm422 你试下直接在load_inference_model时指定下文件全名

zzm422 commented 2 years ago

1、训练保存模型参数使用:(paddle2.1) paddle.save(model.state_dict(), os.path.join(config.model_save_dir, "model.pdparams")) paddle.save(optimizer.state_dict(), os.path.join(config.model_save_dir, "optimizer.pdopt")) 训练保存的模型参数文件为model.pdparams

2、推理使用:(paddle1.8) [inference_program, feed_target_names, fetch_targets] = fluid.io.load_inference_model(dirname=model_dir, executor=exe, params_filename=model_name) results = exe.run(inference_program, feed={feed_target_names[0]: images}, fetch_list=fetch_targets) 加载需要的模型和参数为:model和model_params两个文件

3、问题:如何由model.pdparams转成model和model_params,用于推理。

zhwesky2010 commented 2 years ago

paddle.save保存的只有动态图参数,如果需要动态图模型+参数,需要使用paddle.jit.save,然后使用paddle.jit.load或者paddle.static.load_inference_model加载。 1.8的这个fluid.io.load_inference_model可以试试,应该是支持不了paddle.jit.save的产出

ggbond3 commented 2 years ago

同问,在使用K210部署paddle时,AIstudio案例是paddle1.8的模型转化成kdmodel,现已经使用paddle2.3和paddleslim生成模型,但无法转换,想要将其转化成1.8下fluid.io生成的模型该怎么转。

paddle-bot[bot] commented 3 months ago

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。 若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。