繁体   English   中英

使用Tensorflow批处理非图像数据集

[英]Batching for a non-image data set with Tensorflow

我是tensorflow的初学者。 我有一个包含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

但是,我不知道它是如何工作的。 你能指导我怎么做吗。

谢谢,阿夫申

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

如果要使用队列,则不需要placeholderfeed_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.

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM