1. 程式人生 > >一直在等待,一直會等待 TensorFlow常見API--5

一直在等待,一直會等待 TensorFlow常見API--5

tf.train.Saver

__init__(
    var_list=None,
    reshape=False,
    sharded=False,
    max_to_keep=5,
    keep_checkpoint_every_n_hours=10000.0,
    name=None,
    restore_sequentially=False,
    saver_def=None,
    builder=None,
    defer_build=False,
    allow_empty=False,
    write_version=tf.train.SaverDef.V2,
    pad_step_number=False,
    save_relative_paths=False,
    filename=None
)

        用以儲存與恢復變數的構造器,包含了一些操作方法。 var_list: 用以說明被儲存與恢復的變數。

save: 通過構造器的儲存方法儲存變數。It requires a session in which the graph was launched. 變數儲存之前必須被初始化。

save(
    sess,
    save_path,
    global_step=None,
    latest_filename=None,
    meta_graph_suffix='meta',
    write_meta_graph=True,
    write_state=True,
    strip_default_attrs=False
)

sess: A Session to use to save the variables. save_path: String. Prefix of filenames created for the checkpoint. global_step: If provided the global step number is appended to save_path to create the checkpoint filenames. The optional argument can be a Tensor, a Tensor name or an integer.

restore:

restore(
    sess,
    save_path
)

        恢復之前儲存的變數 sess: A Session to use to restore the parameters. None in eager mode. save_path: Path where parameters were previously saved.