我有一个NumPy数组,想要在TensorFlow的代码中使用Queue读取它。我希望队列返回整个数据集并进行洗牌,指定一定数量的epochs并在此之后抛出错误。最好不需要硬编码示例的大小或示例的数量。
我认为shuffle batch就是为此目的而设计的。我已经尝试使用以下方式:
那种方法的问题在于它会连续读取所有数据,我无法指定在某些轮数后停止。我知道我可以使用RandomShuffleQueue并将数据少量地插入其中几次,但是: a)我不想浪费 epoch*data 的内存,并且 b)这将允许队列在 epochs 之间进行洗牌。
是否有一种好的方法在 Tensorflow 中按 epochs 读取已打乱的数据而不编写自己的队列?
data = tf.constant(train_np) # train_np is my numpy array of shape (num_examples, example_size)
batch = tf.train.shuffle_batch([data], batch_size=5, capacity=52200, min_after_dequeue=10, num_threads=1, seed=None, enqueue_many=True)
sess.run(tf.initialize_all_variables())
tf.train.start_queue_runners(sess=sess)
batch.eval()
那种方法的问题在于它会连续读取所有数据,我无法指定在某些轮数后停止。我知道我可以使用RandomShuffleQueue并将数据少量地插入其中几次,但是: a)我不想浪费 epoch*data 的内存,并且 b)这将允许队列在 epochs 之间进行洗牌。
是否有一种好的方法在 Tensorflow 中按 epochs 读取已打乱的数据而不编写自己的队列?
CancelledError: Dequeue operation was cancelled [[Node: shuffle_batch = QueueDequeueMany[_class=["loc:@shuffle_batch/random_shuffle_queue"], component_types=[DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]
- sygidequeue_up_to
。 - Yaroslav Bulatov