【问题标题】:A quick example to train a model batch by batch in Tensorflow?在 Tensorflow 中批量训练模型的快速示例?
【发布时间】:2017-11-07 11:04:44
【问题描述】:

我在谷歌上搜索了很多,我找不到一个批量训练模型的例子。 Tensorflow 数据集中内置的 mnist 具有 mnist.train.next_batch(BATCH_SIZE) 函数,我需要这样的函数来将我的数据集分成批次并为每次迭代加载下一批。

【问题讨论】:

  • next_batch 的源代码是免费提供的。您当然可以为您的代码重用该代码。

标签: python python-2.7 python-3.x numpy tensorflow


【解决方案1】:

您可以按如下方式拆分您的火车数据:

#Generate a random batch of 200 samples
rand_index = np.random.choice(len(x_data), size=200)
rand_x = x_data[rand_index]
rand_y = y_data[rand_index]

然后在每次迭代中,您逐批训练。

for i in range(1000):
   for u in range(number_of_batches):
      sess.run(train, feed_dict={x: rand_x.....})

类似的东西会起作用。

【讨论】:

  • 目前我的训练方式相同,但是对于每个模型,我需要计算 number_of_batches 和编号。手动每次迭代的批次,它对复杂的模型很疯狂,
猜你喜欢
  • 2023-03-15
  • 2017-12-05
  • 1970-01-01
  • 2017-06-10
  • 1970-01-01
  • 2019-04-02
  • 1970-01-01
  • 1970-01-01
  • 2018-04-01
相关资源
最近更新 更多