0

我是张量流的初学者。我有一个包含 43 个输入和一个输出的数据集。我将创建一个小批量数据来运行深度学习。

这是我的输入:

x = tf.placeholder(tf.float32, shape=[None, 43])
y_ = tf.placeholder(tf.float32, shape=[None])

我从一个 matlab 文件中给它们喂食,看着:

train_mat = train_mat["binary_train"].value
feed_dict={x:Train[0:100,0:43] , y_:Train[0:100,43]}

我将有随机批次而不是调用 0:100 记录。我看见

tf.train.batch

但是,我无法意识到它是如何工作的。你能否指导我如何做到这一点。

谢谢, 阿夫辛

4

1 回答 1

0

和其他类似的tf.train.batch方法是基于队列的,它最适合并行异步加载大量样本。此处的文档描述了在 TensorFlow 中使用队列的基本知识。还有另一个博客描述了如何从文件中读取数据

如果您要使用队列,则placeholderandfeed_dict是不必要的。

对于您的具体情况,潜在的解决方案可能如下所示:

from tensorflow.python.training import queue_runner

# capacity and min_after_dequeue could be set according to your case
q = tf.RandomShuffleQueue(1000, 500, tf.float32)
enq = q.enqueue_many(train_mat)
queue_runner.add_queue_runner(queue_runner.QueueRunner(q, [enq]))

deq = q.dequeue()
input = deq[:, 0:43]
label = deq[:, 43]

x, y_ = tf.train.batch([input, label], 100)

# then you can use x and y_ directly in inference and train process.

上面的代码基于一些假设,因为所提供的信息是不充分的。但是,我希望代码能以某种方式启发您。

于 2016-08-16T03:47:33.627 回答