save_persistables¶
- paddle.fluid.io. save_persistables ( executor, dirname, main_program=None, filename=None ) [source]
- 
         Save all persistable variables from main_programto the folderdirnameor filefilename. You can refer to Save and Load a Model for more details. And then saves these persistables variables to the folderdirnameor filefilename.The dirnameis used to specify the folder where persistable variables are going to be saved. If you would like to save variables in separate files, setfilenameNone; if you would like to save all variables in a single file, usefilenameto specify the file name.- Parameters
- 
           - executor (Executor) – The executor to run for saving persistable variables. You can refer to Executor for more details. 
- dirname (str, optional) – The saving directory path. When you need to save the parameter to the memory, set it to None. 
- main_program (Program, optional) – The program whose persistbale variables will be saved. You can refer to Basic Concept for more details. If it is None, the default main program will be used. Default: None. 
- filename (str, optional) – The file to save all variables. If you prefer to save variables in different files, set it to None. Default: None. 
 
- Returns
- 
           
           - When saving parameters to a file, returns None.
- 
             When saving parameters to memory, returns a binary string containing parameters. 
 
- Return type
- 
           str 
 Examples import paddle import paddle.fluid as fluid paddle.enable_static() dir_path = "./my_paddle_model" file_name = "persistables" image = fluid.data(name='img', shape=[None, 28, 28], dtype='float32') label = fluid.data(name='label', shape=[None, 1], dtype='int64') feeder = fluid.DataFeeder(feed_list=[image, label], place=fluid.CPUPlace()) predict = fluid.layers.fc(input=image, size=10, act='softmax') loss = fluid.layers.cross_entropy(input=predict, label=label) avg_loss = paddle.mean(loss) exe = fluid.Executor(fluid.CPUPlace()) exe.run(fluid.default_startup_program()) fluid.io.save_persistables(executor=exe, dirname=dir_path, filename=file_name) # The persistables variables weights and bias in the fc layer of the network # are going to be saved in the same file named "persistables" in the path # "./my_paddle_model" 
