【发布时间】:2017-10-09 21:03:02
【问题描述】:
我正在使用张量流对卷积神经网络进行第一次测试。我使用编程指南中的队列运行器调整了推荐的方法(请参阅下面的会话定义)。输出是来自 cnn 的最后一个结果(这里只给出最后一步)。 label_batch_vector 是训练标签批次。
output = tf.matmul(h_pool2_flat, W_fc1) + b_fc1
label_batch_vector = tf.one_hot(label_batch, 33)
correct_prediction = tf.equal(tf.argmax(output, 1), tf.argmax(label_batch_vector, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
print_accuracy = tf.Print(accuracy, [accuracy])
# Create a session for running operations in the Graph.
sess = tf.Session()
# Initialize the variables (like the epoch counter).
sess.run(init_op)
# Start input enqueue threads.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
try:
while not coord.should_stop():
# Run training steps or whatever
sess.run(train_step)
sess.run(print_accuracy)
except tf.errors.OutOfRangeError:
print('Done training -- epoch limit reached')
finally:
# When done, ask the threads to stop.
coord.request_stop()
# Wait for threads to finish.
coord.join(threads)
sess.close()
我的问题是为每个批次计算准确性,我希望为每个时期计算它。我需要执行以下操作:初始化一个 epoch_accuracy 张量,对于该 epoch 中计算的每个批次精度,将其添加到 epoch_accuracy。在 epoch 结束时显示计算的训练集精度。但是,我在我实现的这个队列线程中没有找到任何这样的例子(这实际上是 TensorFlow 推荐的方法)。谁能帮忙?
【问题讨论】:
标签: tensorflow