Skip to content

Instantly share code, notes, and snippets.

@ethan-funny
Forked from zhiqizhiqi/fifoqueue_speed.py
Created September 13, 2017 03:15
Show Gist options
  • Save ethan-funny/b6e9c328fe0b16cc9d2812b9554bf19c to your computer and use it in GitHub Desktop.
Save ethan-funny/b6e9c328fe0b16cc9d2812b9554bf19c to your computer and use it in GitHub Desktop.
import tensorflow as tf
import time
from datetime import datetime
import numpy as np
FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_bool('cluster', False, '')
def log(obj):
print datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3], obj
def main(_):
server = tf.train.Server.create_local_server()
raw_shape = [576, 3, 220, 220]
shape = tf.TensorShape(raw_shape)
if FLAGS.cluster:
sess = tf.Session(server.target)
else:
sess = tf.Session()
with tf.device('/cpu:0'):
q = tf.FIFOQueue(10, tf.float32, shape, name = 'Q', shared_name = 'share_queue')
rand_data = tf.zeros(shape)
init_op = tf.initialize_local_variables()
sess.run(init_op)
result = q.dequeue()
x = tf.placeholder(tf.float32, shape, 'data')
enqueue_op = q.enqueue(x)
while True:
time.sleep(1)
log('pushing')
sess.run(enqueue_op, feed_dict = {x: np.zeros(raw_shape)})
log('push done')
sess.run(result)
log('pop done')
if __name__ == '__main__':
tf.logging.set_verbosity(tf.logging.INFO)
tf.app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment