[TensorBoard] Train and Test accuracy simultaneous tracking
训练时的实时状态跟踪的重要性 不言而喻。
[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_train = 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的更多相关文章
- 论文笔记: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 本文目标在于 ...
- 本人AI知识体系导航 - AI menu
Relevant Readable Links Name Interesting topic Comment Edwin Chen 非参贝叶斯 徐亦达老板 Dirichlet Process 学习 ...
- 【colab pytorch】使用tensorboard可视化
import datetime import torch import torch.nn as nn import torch.nn.functional as F import torch.opti ...
- 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 ...
- Features for Multi-Target Multi-Camera Tracking and Re-identification论文解读
解读一:Features for Multi-Target Multi-Camera Tracking and Re-identification Abstract MTMCT:从多个摄像头采集的视频 ...
- cvpr2015papers
@http://www-cs-faculty.stanford.edu/people/karpathy/cvpr2015papers/ CVPR 2015 papers (in nicer forma ...
- ICCV 2017论文分析(文本分析)标题词频分析 这算不算大数据 第一步:数据清洗(删除作者和无用的页码)
IEEE International Conference on Computer Vision, ICCV 2017, Venice, Italy, October 22-29, 2017. IEE ...
- 100天搞定机器学习|day40-42 Tensorflow Keras识别猫狗
100天搞定机器学习|1-38天 100天搞定机器学习|day39 Tensorflow Keras手写数字识别 前文我们用keras的Sequential 模型实现mnist手写数字识别,准确率0. ...
- caffe中的BatchNorm层
在训练一个小的分类网络时,发现加上BatchNorm层之后的检索效果相对于之前,效果会有提升,因此将该网络结构记录在这里,供以后查阅使用: 添加该层之前: layer { name: "co ...
随机推荐
- 关于Mysql安装启动的若干问题解决
Mysql由于其免费,高效的特点一直是大学,培训班的主力数据库管理软件.但是对于初学者而言可能没有那么友好,一是没有windows软件通用的那套可视化操作,基本上初期在不搭配navicat的状态下只能 ...
- poj--1088--DFS(记忆化搜索之经典)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 68057 Accepted: 25039 Description ...
- 针对UDP丢包问题,进行系统层面和程序层面调优
转自:https://blog.csdn.net/xingzheouc/article/details/49946191 1. UDP概念 用户数据报协议(英语:User Datagram Proto ...
- 奇怪吸引子---QiChen
奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...
- MySql之插入操作
一:插入一行数据 INSERT INTO tableName(列名...) VALUES(对应列名的值); 二:插入多行 INSERT INTO tableName(列名...) VALUES(对应列 ...
- ceph 生成rpm包
概述 从ceph的源码build出rpm包: #git clone --recursive https://github.com/ceph/ceph.git #./instal-dep.sh 以上两点 ...
- 【Android】解析Android的路径
目录结构: contents structure [+] 内部路径 外部路径 Assets目录 Android中的路径主要分为内部路径和外部路径. 一.内部路径 常见的内部存储路径有: File f1 ...
- Linux说明书 - man浅谈
原文链接: http://www.cnblogs.com/xuxn/archive/2011/08/26/linux-manual-man-command.html 所有学过Linux的同学都应该知道 ...
- Windows 7 设置允许多用户同时远程桌面连接
有时候我们服务器安装的是Win7系统,远程登录桌面时,即使登录的是不同的管理账号,还是会提示把远程登录的人给踢下来.即系统只允许存在一个远程会话窗,不管是不是相同的用户. 下面讲解如何设置Win7让多 ...
- struts2:OGNL表达式,遍历List、Map集合;投影的使用
OGNL是Object-Graph Navigation Language的缩写,它是一种功能强大的表达式语言(Expression Language,简称为EL),通过它简单一致的表达式语法,可以存 ...