hzy46/Deep-Learning-21-Examples

第一章 在验证集上报告正确率 用的数据依然是训练集上的数据.

Opened this issue · 0 comments

    batch = mnist.train.next_batch(50)
    # 每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))

这样修改下就是在验证集上报告正确率:
#定义验证集
validate_data_x = mnist.validation.images
validate_data_y = mnist.validation.labels
# 训练20000步
for i in range(20000):
batch = mnist.train.next_batch(50)
# 每100步报告一次在验证集上的准确度
if i % 100 == 0:
train_accuracy = accuracy.eval(feed_dict={
x: validate_data_x, y_: validate_data_y, keep_prob: 1.0})
print("step %d, training accuracy %g" % (i, train_accuracy))