From 8560e513652b1f005441dba126dc39e32b0ae54c Mon Sep 17 00:00:00 2001 From: littletomatodonkey Date: Thu, 13 Aug 2020 13:20:59 +0000 Subject: [PATCH] fix save var doc --- docs/en/faq_en.md | 10 +++++++++- docs/zh_CN/faq.md | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/en/faq_en.md b/docs/en/faq_en.md index e006870b..6f34117f 100644 --- a/docs/en/faq_en.md +++ b/docs/en/faq_en.md @@ -45,7 +45,15 @@ VALID: >> * Q: What should I do if I want to transform the weights' format from `pdparams` to an earlier version(before Paddle1.7.0), which consists of the scattered files? -* A: You can use `fluid.load` to load the `pdparams` weights and use `fluid.io.save_vars` to save the weights as scattered files. +* A: You can use `fluid.load` to load the `pdparams` weights and use `fluid.io.save_vars` to save the weights as scattered files. The demo is as follows. Finally all the scattered files will be saved in the path `path_to_save_var`. +``` +fluid.load( + program=infer_prog, model_path=args.pretrained_model, executor=exe) +state = fluid.io.load_program_state(args.pretrained_model) +def exists(var): + return var.name in state +fluid.io.save_vars(exe, "./path_to_save_var", infer_prog, predicate=exists) +``` >> diff --git a/docs/zh_CN/faq.md b/docs/zh_CN/faq.md index dd73b674..bd540147 100644 --- a/docs/zh_CN/faq.md +++ b/docs/zh_CN/faq.md @@ -45,7 +45,15 @@ VALID: >> * Q: 如果想将保存的`pdparams`模型参数文件转换为早期版本(Paddle1.7.0之前)的零碎文件(每个文件均为一个单独的模型参数),该怎么实现呢? -* A: 可以首先导入`pdparams`模型,之后使用`fluid.io.save_vars`函数将模型保存为零散的碎文件。 +* A: 可以首先导入`pdparams`模型,之后使用`fluid.io.save_vars`函数将模型保存为零散的碎文件。示例代码如下,最终所有零散文件会被保存在`path_to_save_var`目录下。 +``` +fluid.load( + program=infer_prog, model_path=args.pretrained_model, executor=exe) +state = fluid.io.load_program_state(args.pretrained_model) +def exists(var): + return var.name in state +fluid.io.save_vars(exe, "./path_to_save_var", infer_prog, predicate=exists) +``` >> -- GitLab