【问题标题】:Split data into batches in Tensorflow for classification在 Tensorflow 中将数据拆分为批次进行分类
【发布时间】:2017-06-16 08:14:10
【问题描述】:

我正在使用以下代码训练数据。但在这里我需要将数据分成批次(如 MNIST tensorflow 示例中给出的:batch_xs, batch_ys = mnist.train.next_batch(100))。

当我寻找 next_batch 方法时,它在任何库中都不可用。我是张量流的新手。只是想知道我是否可以在训练时将数据分成批次。

任何帮助将不胜感激。

for i in range(training_epochs):  
  sess.run(optimizer, feed_dict={x: inputX, y_: inputY}) # Take a gradient descent step using our inputs and labels

# That's all! The rest of the cell just outputs debug messages. 
# Display logs per epoch step
  if (i) % display_step == 0:
    cc = sess.run(cost, feed_dict={x: inputX, y_:inputY})
    print "Training step:", '%04d' % (i), "cost=", "{:.9f}".format(cc) #, \"W=", sess.run(W), "b=", sess.run(b)

print "Optimization Finished!"
training_cost = sess.run(cost, feed_dict={x: inputX, y_: inputY})
print "Training cost=", training_cost, "W=", sess.run(W), "b=", sess.run(b), '\n'

【问题讨论】:

    标签: machine-learning tensorflow classification


    【解决方案1】:

    next_batch 不是通用库方法。这是一种特定于 MNIST 数据集的方法,它读取下一个小批量输入以提供给 Tensorflow。

    您可以在此处查看其实现: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/datasets/mnist.py#L160

    您需要为您的数据集实现类似的东西。 此代码并非特定于 Tensorflow —— 您可以使用任何您喜欢的 Python 库来执行此操作。

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 2020-07-16
      • 2018-12-27
      • 2018-04-26
      • 2014-04-20
      • 2017-05-06
      • 1970-01-01
      • 2018-05-14
      • 1970-01-01
      相关资源
      最近更新 更多