【Tensorflow】队列:tf.FIFOQueue和tf.RandomShuffleQueue

一、tf.FIFOQueue

import tensorflow as tf

q = tf.FIFOQueue(2, 'int32')
init = q.enqueue_many(([0, 10], ))
x = q.dequeue()
y = x + 1
q_inc = q.enqueue(y)

with tf.Session() as sess:
    init.run()
    for _ in range(5):
        v, _ = sess.run([x, q_inc])
        print(v)

【Tensorflow】队列:tf.FIFOQueue和tf.RandomShuffleQueue_第1张图片

二、tf.RandomShuffleQueue

import tensorflow as tf
p = tf.RandomShuffleQueue(2, min_after_dequeue=1, dtypes=tf.int32)
init = p.enqueue_many(([0, 10], ))
x = p.dequeue()
y = x + 1
p_inc = p.enqueue(y)

with tf.Session() as sess:
    init.run()
    for _ in range(5):
        v, _ = sess.run([x, p_inc])
        print(v)

【Tensorflow】队列:tf.FIFOQueue和tf.RandomShuffleQueue_第2张图片

你可能感兴趣的:(tensorflow)