TensorFlow: Saver has 5 models limit

后端 未结 2 986
暖寄归人
暖寄归人 2020-12-25 15:13

I wanted to save multiple models for my experiment but I noticed that tf.train.Saver() constructor could not save more than 5 models. Here is a simple code:

2条回答
  •  悲哀的现实
    2020-12-25 16:12

    The tf.train.Saver() constructor takes an optional argument called max_to_keep, which defaults to keeping the 5 most recent checkpoints of your model. To save more models, simply specify a value for that argument:

    import tensorflow as tf 
    
    x = tf.Variable(tf.zeros([1]))
    saver = tf.train.Saver(max_to_keep=10)
    sess = tf.Session()
    
    for i in range(10):
      sess.run(tf.initialize_all_variables())
      saver.save(sess, '/home/eneskocabey/Desktop/model' + str(i))
    

    To keep all checkpoints, pass the argument max_to_keep=None to the saver constructor.

提交回复
热议问题