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:
import tensorflow as tf
x = tf.Variable(tf.zeros([1]))
saver = tf.train.Saver()
sess = tf.Session()
for i in range(10):
sess.run(tf.initialize_all_variables())
saver.save( sess, '/home/eneskocabey/Desktop/model' + str(i) )
When I ran this code, I saw only 5 models on my Desktop. Why is this? How can I save more than 5 models with the same tf.train.Saver()
constructor?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With