Unable to use summary.merge in tensorboard for separate training and evaluation summaries

余生颓废 提交于 2019-12-04 03:14:24
Kristin H

I figured it out. I need to give the summaries names before merging. The code below solves the problem:

with tf.name_scope('Cost'):
    cross_entropy = tf.reduce_mean(
            tf.nn.softmax_cross_entropy_with_logits(logits=y_logits, labels=y))
    opt = tf.train.AdamOptimizer(learning_rate=0.000003)
    optimizer = opt.minimize(cross_entropy)
    grads = opt.compute_gradients(cross_entropy, [b_fc_loc2])
    cost_sum = tf.summary.scalar('val_cost', cross_entropy)
    training_cost_sum = tf.summary.scalar('train_cost', cross_entropy)


with tf.name_scope('accuracy'):
    correct_prediction = tf.equal(tf.argmax(y_logits, 1), tf.argmax(y, 1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, 'float'))
    train_accuracy = accuracy
    accuracy_sum = tf.summary.scalar('val_accuracy', accuracy)
    training_accuracy_sum = tf.summary.scalar('train_accuracy', accuracy)


with tf.Session() as sess:
    writer = tf.summary.FileWriter('./logs/{}/{}'.format(session_name, run_num), sess.graph)
    sess.run(tf.global_variables_initializer())
    train_merged = tf.summary.merge([training_accuracy_sum, training_cost_sum])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!