I have a TensorFlow based neural network and a set of variables.
The training function is like this:
def train(load = True, step)
"""
Defining the neural network is skipped here
"""
train_step = tf.train.AdamOptimizer(1e-4).minimize(mse)
# Saver
saver = tf.train.Saver()
if not load:
# Initalizing variables
sess.run(tf.initialize_all_variables())
else:
saver.restore(sess, 'Variables/map.ckpt')
print 'Model Restored!'
# Perform stochastic gradient descent
for i in xrange(step):
train_step.run(feed_dict = {x: train, y_: label})
# Save model
save_path = saver.save(sess, 'Variables/map.ckpt')
print 'Model saved in file: ', save_path
print 'Training Done!'
I was calling the training function like this:
# First train
train(False, 1)
# Following train
for i in xrange(10):
train(True, 10)
I did this kind of training because I needed to feed different dataset to my model. However, if I call the train function in this way TensorFlow will generate error message indicating that it cannot read the saved model from file.
After some experiments I found that this happened because the checkpoint saving was slow. Before the file was written to the disk the next train function would start reading, thus generate the error.
I have tried to use time.sleep() function to make some delay between each call but it didn't work.
Anyone knows how to work out this kind of write/read error? Thank you very much!