训练时的实时状态跟踪的重要性 不言而喻。

[Tensorboard] Cookbook - Tensorboard  讲解调节更新频率

直接上代码展示:

import numpy as np
import tensorflow as tf
from random import randint
import datetime
import os
import time import implementation as imp batch_size = imp.batch_size
iterations = 20001
seq_length = 40 # Maximum length of sentence checkpoints_dir = "./checkpoints" def getTrainBatch():
labels = []
arr = np.zeros([batch_size, seq_length])
for i in range(batch_size):
if (i % 2 == 0):
num = randint(0, 11499)
labels.append([1, 0])
else:
num = randint(12500, 23999)
labels.append([0, 1])
arr[i] = training_data[num]
return arr, labels def getTestBatch():
labels = []
arr = np.zeros([batch_size, seq_length])
for i in range(batch_size):
if (i % 2 == 0):
num = randint(11500, 12499)
labels.append([1, 0])
else:
num = randint(24000, 24999)
labels.append([0, 1])
arr[i] = training_data[num]
return arr, labels ############################################################################### # Call implementation
glove_array, glove_dict = imp.load_glove_embeddings()
training_data = imp.load_data(glove_dict)
input_data, labels, optimizer, accuracy, loss, dropout_keep_prob = imp.define_graph(glove_array) ############################################################################### # tensorboard
train_accuracy_op = tf.summary.scalar("training_accuracy", accuracy)
tf.summary.scalar("loss", loss)
summary_op = tf.summary.merge_all() # saver
all_saver = tf.train.Saver() sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer()) logdir_train = "tensorboard/" + datetime.datetime.now().strftime(
"%Y%m%d-%H%M%S-train") + "/"
writer_tr
ain = tf.summary.FileWriter(logdir_train, sess.graph) logdir_test = "tensorboard/" + datetime.datetime.now().strftime(
"%Y%m%d-%H%M%S-test") + "/"
writer_test
= tf.summary.FileWriter(logdir_test, sess.graph) timePoint1 = time.time()
timePoint2 = time.time()
for i in range(iterations):
batch_data, batch_labels = getTrainBatch()
batch_data_test, batch_labels_test = getTestBatch() # Set the dropout_keep_prob
# 1.0: dropout is invalid.
# 0.5: dropout is 0.5
sess.run(optimizer, {input_data: batch_data, labels: batch_labels, dropout_keep_prob:0.8})
if (i % 50 == 0): print("--------------------------------------")
print("Iteration: ", i, round(i/iterations, 2))
print("--------------------------------------") ############################################################## loss_value, accuracy_value, summary = sess.run(
                        [loss, accuracy, summary_op],
                        {input_data: batch_data,
                        labels: batch_labels,
                        dropout_keep_prob:1.0})
writer_train.add_summary(summary, i) print("loss [train]", loss_value)
print("acc [train]", accuracy_value) ############################################################## loss_value_test, accuracy_value_test, summary_test = sess.run(
                        [loss, accuracy, summary_op],
                        {input_data: batch_data_test,
                        labels: batch_labels_test,
                        dropout_keep_prob:1.0})writer_test.add_summary(summary_test, i)
print("loss [test]", loss_value_test)
print("acc [test]", accuracy_value_test) ############################################################## timePoint2 = time.time()
print("Time:", round(timePoint2-timePoint1, 2))
timePoint1 = timePoint2 if (i % 10000 == 0 and i != 0):
if not os.path.exists(checkpoints_dir):
os.makedirs(checkpoints_dir)
save_path = all_saver.save(sess, checkpoints_dir +
"/trained_model.ckpt",
global_step=i)
print("Saved model to %s" % save_path)
sess.close()

总之,不同的summary写入不同的writer对象中。

[TensorBoard] Train and Test accuracy simultaneous tracking的更多相关文章

  1. 论文笔记:Parallel Tracking and Verifying: A Framework for Real-Time and High Accuracy Visual Tracking

    Parallel Tracking and Verifying: A Framework for Real-Time and High Accuracy Visual Tracking  本文目标在于 ...

  2. 本人AI知识体系导航 - AI menu

    Relevant Readable Links Name Interesting topic Comment Edwin Chen 非参贝叶斯   徐亦达老板 Dirichlet Process 学习 ...

  3. 【colab pytorch】使用tensorboard可视化

    import datetime import torch import torch.nn as nn import torch.nn.functional as F import torch.opti ...

  4. Summary on Visual Tracking: Paper List, Benchmarks and Top Groups

    Summary on Visual Tracking: Paper List, Benchmarks and Top Groups 2018-07-26 10:32:15 This blog is c ...

  5. Features for Multi-Target Multi-Camera Tracking and Re-identification论文解读

    解读一:Features for Multi-Target Multi-Camera Tracking and Re-identification Abstract MTMCT:从多个摄像头采集的视频 ...

  6. cvpr2015papers

    @http://www-cs-faculty.stanford.edu/people/karpathy/cvpr2015papers/ CVPR 2015 papers (in nicer forma ...

  7. ICCV 2017论文分析(文本分析)标题词频分析 这算不算大数据 第一步:数据清洗(删除作者和无用的页码)

    IEEE International Conference on Computer Vision, ICCV 2017, Venice, Italy, October 22-29, 2017. IEE ...

  8. 100天搞定机器学习|day40-42 Tensorflow Keras识别猫狗

    100天搞定机器学习|1-38天 100天搞定机器学习|day39 Tensorflow Keras手写数字识别 前文我们用keras的Sequential 模型实现mnist手写数字识别,准确率0. ...

  9. caffe中的BatchNorm层

    在训练一个小的分类网络时,发现加上BatchNorm层之后的检索效果相对于之前,效果会有提升,因此将该网络结构记录在这里,供以后查阅使用: 添加该层之前: layer { name: "co ...

随机推荐

  1. C#高级编程9 第16章 错误和异常

    C#高级编程9 第16章 错误和异常 了解这章可以学会如何处理系统异常以及错误信息. System.Exception类是.NET运行库抛出的异常,可以继承它定义自己的异常类. try块代码包含的代码 ...

  2. p4 环境变量的优先级

    Perforce settings such as port, user, and workspace names using the following methods, listed in ord ...

  3. C#编程(八十)---------- 异常类

    异常类 在C#里,异常处理就是C#为处理错误情况提供的一种机制.它为每种错误情况提供了定制的处理方式,并且把标志错误的代码预处理错误的代码分离开来. 对.net类来说,一般的异常类System.Exc ...

  4. jconsole工具使用

    Jconsole,Java Monitoring and Management Console. Jconsole是JDK自带的监控工具,在JDK/bin目录下可以找到.它用于连接正在运行的本地或者远 ...

  5. 【jQuery Demo】图片瀑布流实现

    瀑布流就是像瀑布一样的网站——丰富的网站内容,特别是绚美的图片会让你流连忘返.你在浏览网站的时候只需要轻轻滑动一下鼠标滚轮,一切的美妙的图片精彩便可呈现在你面前.瀑布流网站是新兴的一种网站模式——她的 ...

  6. RPC简述

    在某种意义上,WebService.REST均是RPC的实现,那么RPC的发展过程如何呢?本文参考了wikipedia,对RPC做一下简要摘记. RPC(RemoteProcedureCall),是进 ...

  7. 每天一个linux命令(2):cd命令

    1.作用 cd(Change Directory 改变目录)命令用来切换工作目录至dirname. 其中dirName表示法可为绝对路径或相对路径.若目录名称省略,则变换至使用者的home direc ...

  8. asp.net core 2.1 post 无法提交参数?

    起 ,是微软二逼升级了.....不是说好了合并Controller 了吗?又倒回去了.................

  9. 解决zabbix的中文乱码

    CentOS7.1 x64上下载了zabbix官方的rpm包,导入后使用yum安装了zabbix 3.2.6,但是启动zabbix server的时候报了个段错误的错,谷歌了一会儿,发现段错误不止一次 ...

  10. Elasticsearch cat api的用法

    文章转自:https://blog.csdn.net/wangpei1949/article/details/82287444