TensorFlow-谷歌深度学习库 存取训练过程中的参数 #tf.train.Saver #checkpoints file

当你一溜十三招训练出了很多参数,如权重矩阵和偏置参数, 当然希望可以通过一种方式把这些参数的值记录下来啊。这很关键,因为如果你把这些值丢弃的话那就前功尽弃了。这很重要啊有木有!!

在TensorFlow中使用tf.train.Saver这个类取不断的存取checkpoints文件从而实现这一目的。

看一下官方说明文档:

class Saver(builtins.object)
Saves and restores variables.for an overview of variables, saving and restoring.
The `Saver` class adds ops to save and restore variables to and from  *checkpoints*.

Checkpoints are binary files in a proprietary format which map variable names to tensor values. The best way to examine the contents of a checkpoint is to load it using a `Saver`.

  __init__(self, 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=2, pad_step_number=False, save_relative_paths=False, filename=None)
 # Creates a `Saver`.
 # The constructor adds ops to save and restore variables.

当需要将参数写入checkpoint时,用save函数

 save(self, sess, save_path, global_step=None, latest_filename=None, meta_graph_suffix='meta', write_meta_graph=True, write_state=True, strip_default_attrs=False)
"""
      Saves variables.
       
       This method runs the ops added by the constructor for saving variables.
       It requires a session in which the graph was launched.  The variables to
       save must also have been initialized.
       
       The method returns the path prefix of the newly created checkpoint files.
       This string can be passed directly to a call to `restore()`.
"""

当要读取参数是,用restore函数

  restore(self, sess, save_path)
"""
 |      Restores previously saved variables.
 |      
 |      This method runs the ops added by the constructor for restoring variables.
 |      It requires a session in which the graph was launched.  The variables to
 |      restore do not have to have been initialized, as restoring is itself a way
 |      to initialize variables.
"""

 

转载于:https://www.cnblogs.com/duwenlu/p/8674176.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值