Skip to content

Instantly share code, notes, and snippets.

@sameerg07
Created July 11, 2018 06:33
Show Gist options
  • Save sameerg07/df7178326b802544b2a4d1966d5e0358 to your computer and use it in GitHub Desktop.
Save sameerg07/df7178326b802544b2a4d1966d5e0358 to your computer and use it in GitHub Desktop.
thread and queues in tf
# Create the graph, etc.
init_op = tf.global_variables_initializer()
# Create a session for running operations in the Graph.
sess = tf.Session()
# Initialize the variables (like the epoch counter).
sess.run(init_op)
# Start input enqueue threads.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
try:
while not coord.should_stop():
# Run training steps or whatever
sess.run(train_op)
except tf.errors.OutOfRangeError:
print('Done training -- epoch limit reached')
finally:
# When done, ask the threads to stop.
coord.request_stop()
# Wait for threads to finish.
coord.join(threads)
sess.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment