Created
July 11, 2018 06:33
-
-
Save sameerg07/df7178326b802544b2a4d1966d5e0358 to your computer and use it in GitHub Desktop.
thread and queues in tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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