我正在学习Udacity深度学习课程,其作业说:“演示过度拟合的极端情况,将您的训练数据限制在几个批次。梯度下降批量步骤Tensorflow
我的问题是:
1) 为什么减少num_steps, num_batches
有什么做过度拟合?我们没有添加任何变量也没有增加W的大小。
在下面的代码中,num_steps曾经是3001,num_batches是128,解决方案是分别将它们减少到101和3。
num_steps = 101
num_bacthes = 3
with tf.Session(graph=graph) as session:
tf.initialize_all_variables().run()
print("Initialized")
for step in range(num_steps):
# Pick an offset within the training data, which has been randomized.
# Note: we could use better randomization across epochs.
#offset = (step * batch_size) % (train_labels.shape[0] - batch_size)
offset = step % num_bacthes
# Generate a minibatch.
batch_data = train_dataset[offset:(offset + batch_size), :]
batch_labels = train_labels[offset:(offset + batch_size), :]
# Prepare a dictionary telling the session where to feed the minibatch.
# The key of the dictionary is the placeholder node of the graph to be fed,
# and the value is the numpy array to feed to it.
feed_dict = {tf_train_dataset : batch_data, tf_train_labels : batch_labels, beta_regul : 1e-3}
_, l, predictions = session.run(
[optimizer, loss, train_prediction], feed_dict=feed_dict)
if (step % 2 == 0):
print("Minibatch loss at step %d: %f" % (step, l))
print("Minibatch accuracy: %.1f%%" % accuracy(predictions, batch_labels))
print("Validation accuracy: %.1f%%" % accuracy(
valid_prediction.eval(), valid_labels))
print("Test accuracy: %.1f%%" % accuracy(test_prediction.eval(), test_labels))
此代码是从溶液中的摘录:https://github.com/rndbrtrnd/udacity-deep-learning/blob/master/3_regularization.ipynb
2)可有人解释的梯度下降“偏移”概念?为什么我们必须使用它?
3)我已经用num_steps进行了实验,发现如果增加num_steps,精度会提高。为什么?我应该如何解读num_step和学习率?