load_persistables_cn.rst 750 字节
Newer Older
H
Hao Wang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
.. _cn_api_fluid_dygraph_load_persistables:

load_persistables
-------------------------------

.. py:function:: paddle.fluid.dygraph.load_persistables(dirname='save_dir')

该函数尝试从dirname中加载持久性变量。


参数:
    - **dirname**  (str) – 目录路径。默认为save_dir


返回:   两个字典:从文件中恢复的参数字典;从文件中恢复的优化器字典

返回类型:   dict
  
**代码示例**

.. code-block:: python

    my_layer = layer(fluid.Layer)
    param_path = "./my_paddle_model"
    sgd = SGDOptimizer(learning_rate=1e-3)
    param_dict, optimizer_dict = fluid.dygraph.load_persistables(my_layer.parameters(), param_path)
    param_1 = param_dict['PtbModel_0.w_1']
    sgd.load(optimizer_dict)