首页 文章

用于MNIST手写数字的Tensor Flow的CNN训练的振荡精度

提问于
浏览
5

我正在按照教程"Deep MNIST for Experts",https://www.tensorflow.org/versions/r0.11/tutorials/mnist/pros/index.html#deep-mnist-for-experts

使用卷积神经网络,我得到93.49%的准确率 . 这实际上很低,我正在努力改进它,但我有一个疑问 . 根据教程,

for i in range(20000):
   batch = mnist.train.next_batch(50)
   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})

在每100次迭代之后记录列车精度并且看到准确性,它保持振荡,如增加然后减少 .

step 100, training accuracy 0.1
step 200, training accuracy 0.13
step 300, training accuracy 0.12
step 400, training accuracy 0.08
step 500, training accuracy 0.12
step 600, training accuracy 0.05
step 700, training accuracy 0.09
step 800, training accuracy 0.1
step 900, training accuracy 0.12
step 1000, training accuracy 0.09
step 1100, training accuracy 0.11
step 1200, training accuracy 0.09
step 1300, training accuracy 0.11
step 1400, training accuracy 0.06
step 1500, training accuracy 0.09
step 1600, training accuracy 0.14
step 1700, training accuracy 0.07
step 1800, training accuracy 0.08
......
step 19800, training accuracy 0.14
step 19900, training accuracy 0.07

有什么理由吗?还是正常的?那为什么呢?另外,我可以改变什么样的变量来提高最终的准确性?我已经尝试过改变学习率变量了 .

1 回答

  • 5

    振荡精度通常由太高的 learning_rate 引起 . 我的第一个提示确实是降低了 learning_rate ,你是否测试了 logarithmic scale 的多个学习率,例如0.1,0.05,0.02,0.01,0.005,0.002,...?

    大幅度使用 smaller learning rates 应该消除振荡精度 . 同时检查Kaggle上的this answerlinked document以便更好地理解 .

    EDIT:

    根据评论中的注释:每批次测量此准确度 . 由于您每次都在比较不同批次的精度(一个简单的批次与一个更难的批次),因此您的准确性没有单调增加是正常的 . 您可以进一步减少振荡:

    • increasing the batch size ,波动应该减少:不同例子的难度的影响将被平均 .

    • 您还可以通过一组常量示例计算训练精度:

    • 使用 validation set

    • Averaging 一个时期内所有批次的批次准确度

    • 在每个训练步骤之后实际计算训练集中的 accuracy over all examples . 如果你有一个大的训练集,这个偏离课程对训练时间有很大的影响 .

相关问题