gpt4 book ai didi

machine-learning - Tensorflow-如何使用完整批处理的 MNIST 数据集?

转载 作者:行者123 更新时间:2023-11-30 09:52:23 26 4
gpt4 key购买 nike

我正在研究机器学习。在我学习的过程中,我发现了使用 MNIST 数据集的 Tensorflow CNN 代码。这是我想知道的代码。

cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y_conv), reduction_indices=[1]))
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
sess.run(tf.global_variables_initializer())

for i in range(1000):
batch = mnist.train.next_batch(100)
if i%100 == 0:
train_accuracy = accuracy.eval(feed_dict={
x:batch[0], y_: batch[1], keep_prob: 1.0})
print("step %d, training accuracy %g"%(i, train_accuracy))
train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})

print("test accuracy %g"%accuracy.eval(feed_dict={
x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))

在这段代码中,我的问题是关于batch = mnist.train.next_batch(100)。当我搜索这个时,这意味着这是小批量的,并且从 MNIST 数据集中随机选择 100 个数据。现在这是我的问题。

  1. 当我想全批测试此代码时,我该怎么办?只需将 mnist.train.next_batch(100) 更改为 mnist.train.next_batch(55000) 即可?

最佳答案

是的,获得一批 55000 个将在 MNIST 的所有数字上训练一个 epoch。

请注意,这是一个坏主意:这可能不适合您的内存。你必须保存 55000 位的权重激活,还有梯度……你的 Python 很可能会崩溃!

通过对一批 100 张随机图像进行 1000 次训练,您会得到很好的结果,并且您的计算机会很高兴!

关于machine-learning - Tensorflow-如何使用完整批处理的 MNIST 数据集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42828669/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com