美文网首页
2018-11-07如何在现有的tensorflow代码基础上增

2018-11-07如何在现有的tensorflow代码基础上增

作者: ClarenceHoo | 来源:发表于2019-03-29 16:05 被阅读0次

假设我有这么一段代码:
a = np.zeros([ valid_batch])
test_begin = time.time()
for i in range(valid_batch):
offset = (i * batch_size) % (n_valid)
batch_data = valid_data_all[offset:(offset + batch_size)]
images = np.zeros([batch_size, 127, 127, 3])
for j in range(batch_size):
images[j, :, :, :] = batch_data[j, 1]
acc_ = sess.run(acc, feed_dict={image_batch: images})
a[i] = acc_
acc_mean = np.mean(a, axis=1)
acc_mean输出的是平均准确率,现在我想要通过tensorboard来记录下来acc_mean的变化曲线,那么我在代码后面加上如下代码即可:
writer = tf.summary.FileWriter('logs', sess.graph)
x = tf.convert_to_tensor(acc_mean, dtype=tf.float32)
acc_summary = tf.summary.scalar('acc_mean', x)
summary = sess.run(acc_summary)
writer.add_summary(summary ,epoch)
此时在运行完.py文件后,文件夹下的./logs文件夹会产生相关的event文件,
cmd中运行tensorboard --logdir=./logs 会有如下的文字段
TensorBoard 1.10.0 at http://DESKTOP-SM5RK2N:6006 (Press CTRL+C to quit)
其中http://DESKTOP-SM5RK2N:6006就是tensorboard的访问地址,在浏览器中输入地址即可完成

相关文章

网友评论

      本文标题:2018-11-07如何在现有的tensorflow代码基础上增

      本文链接:https://www.haomeiwen.com/subject/phsvxqtx.html