参考https://www.cnblogs.com/felixwang2/p/9184344.html

边学习,边练习

 # https://www.cnblogs.com/felixwang2/p/9184344.html
# TensorFlow(七):tensorboard网络执行
# MNIST数据集 手写数字
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data # 参数概要
def variable_summaries(var):
with tf.name_scope('summaries'):
mean=tf.reduce_mean(var)
tf.summary.scalar('mean',mean)# 平均值
with tf.name_scope('stddev'):
stddev=tf.sqrt(tf.reduce_mean(tf.square(var-mean)))
tf.summary.scalar('stddev',stddev)# 标准差
tf.summary.scalar('max',tf.reduce_max(var)) # 最大值
tf.summary.scalar('min',tf.reduce_min(var)) # 最小值
tf.summary.histogram('histogram',var) # 直方图 # 载入数据集
mnist=input_data.read_data_sets('MNIST_data',one_hot=True) # 每个批次的大小
batch_size=100
# 计算一共有多少个批次
n_batch=mnist.train.num_examples//batch_size # 命名空间
with tf.name_scope('input'):
# 定义两个placeholder
x=tf.placeholder(tf.float32,[None,784],name='x-input')
y=tf.placeholder(tf.float32,[None,10],name='y-input') with tf.name_scope('layer'):
# 创建一个简单的神经网络
with tf.name_scope('wights'):
W=tf.Variable(tf.zeros([784,10]),name='W')
variable_summaries(W)
with tf.name_scope('biases'):
b=tf.Variable(tf.zeros([10]),name='b')
variable_summaries(b)
with tf.name_scope('wx_plus_b'):
wx_plus_b=tf.matmul(x,W)+b
with tf.name_scope('softmax'):
prediction=tf.nn.softmax(wx_plus_b) with tf.name_scope('loss'):
# 二次代价函数
loss=tf.reduce_mean(tf.square(y-prediction))
tf.summary.scalar('loss',loss) # 一个值就不用调用函数了
with tf.name_scope('train'):
# 使用梯度下降法
train_step=tf.train.GradientDescentOptimizer(0.2).minimize(loss) # 初始化变量
init=tf.global_variables_initializer() with tf.name_scope('accuracy'):
with tf.name_scope('correct_prediction'):
# 求最大值在哪个位置,结果存放在一个布尔值列表中
correct_prediction=tf.equal(tf.argmax(y,1),tf.argmax(prediction,1))# argmax返回一维张量中最大值所在的位置
with tf.name_scope('accuracy'):
# 求准确率
accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32)) # cast作用是将布尔值转换为浮点型。
tf.summary.scalar('accuracy',accuracy) # 一个值就不用调用函数了 # 合并所有的summary
merged=tf.summary.merge_all() gpu_options = tf.GPUOptions(allow_growth=True)
with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess:
sess.run(init)
writer=tf.summary.FileWriter('logs/',sess.graph) # 写入文件 for epoch in range(10):
for batch in range(n_batch):
batch_xs,batch_ys=mnist.train.next_batch(batch_size)
summary,_=sess.run([merged,train_step],feed_dict={x:batch_xs,y:batch_ys}) # 添加样本点
writer.add_summary(summary,epoch)
#求准确率
acc=sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels})
print('Iter:'+str(epoch)+',Testing Accuracy:'+str(acc))

在命令窗口,使用命令 tensorboard --logdir=F:\document\spyder-py3\study_tensor\logs

生成一个地址可以查看训练中间数据

PS F:\document\spyder-py3\study_tensor> tensorboard --logdir=F:\document\spyder-py3\study_tensor\logs
f:\programdata\anaconda3\envs\py35\lib\site-packages\h5py\__init__.py:: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
TensorBoard 1.10. at http://KOTIN:6006 (Press CTRL+C to quit)

在网页输入

http://KOTIN:6006
或者输入 http://localhost:6006
就可以看到生成的状态图:


tensorflow之tensorboard的更多相关文章

  1. Tensorflow 笔记 -- tensorboard 的使用

    Tensorflow 笔记 -- tensorboard 的使用 TensorFlow提供非常方便的可视化命令Tensorboard,先上代码 import tensorflow as tf a = ...

  2. Tensorflow 之 TensorBoard可视化Graph和Embeddings

    windows下使用tensorboard tensorflow 官网上的例子程序都是针对Linux下的:文件路径需要更改 tensorflow1.1和1.3的启动方式不一样 :参考:Running ...

  3. 学习TensorFlow,TensorBoard可视化网络结构和参数

    在学习深度网络框架的过程中,我们发现一个问题,就是如何输出各层网络参数,用于更好地理解,调试和优化网络?针对这个问题,TensorFlow开发了一个特别有用的可视化工具包:TensorBoard,既可 ...

  4. 学习笔记CB013: TensorFlow、TensorBoard、seq2seq

    tensorflow基于图结构深度学习框架,内部通过session实现图和计算内核交互. tensorflow基本数学运算用法. import tensorflow as tf sess = tf.S ...

  5. 【Tensorflow】tensorboard

    tbCallBack = tf.keras.callbacks.TensorBoard(log_dir='./log' , histogram_freq=0, write_graph=True, wr ...

  6. Windows系统,Tensorflow的Tensorboard工具细节问题

    随着跟着TensorFlow视频学习,学到Tensorboard可视化工具这里的时候. 在windows,cmd里面运行,tensorboard --logdir=你logs文件夹地址  这行代码,一 ...

  7. 莫烦tensorflow(6)-tensorboard

    import tensorflow as tfimport numpy as np def add_layer(inputs,in_size,out_size,n_layer,activation_f ...

  8. 基于TensorFlow进行TensorBoard可视化

    # -*- coding: utf-8 -*- """ Created on Thu Nov 1 17:51:28 2018 @author: zhen "&q ...

  9. tensorflow 之tensorboard 对比不同超参数训练结果

    我们通常使用tensorboard 统计我们的accurate ,loss等,并绘制曲线,通常是使用一次训练中的, 但是,机器学习中通常要对比不同的 ‘超参数’给模型训练和预测能力的不同这时候如何整合 ...

随机推荐

  1. Andre Weil的一生

    在20世纪的数学家中,Andre Weil(1906-1998)以其渊博的学识.坎坷的经历和超凡的人格魅力成为引人注目的一员. 他无疑是20世纪最伟大的数学家之一.国际数学家大会把数学划分为19个大的 ...

  2. 汉语诗词 LaTeX 排版样式

    清世何须忧庙廊——汉语诗词 LaTeX 排版样式 作者想一些中国古典诗歌,发现大多数早期的例子都是为了英文诗而创作的环境. 下面是作者给出唐诗选集的布局实例. 它不是一般解决方案,而只是一个特定的例子 ...

  3. ubuntu中安装和卸载apache2

    1. 安装apache2 安装命令: sudo apt-get install apache2 启动/停止/重启apache2: service apache2 start/stop/restart ...

  4. Codeforces Round #614 (Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...

  5. Python_递归函数

    楔子 在讲今天的内容之前,我们先来讲一个故事,讲的什么呢?从前有座山,山里有座庙,庙里有个老和尚讲故事,讲的什么呢?从前有座山,山里有座庙,庙里有个老和尚讲故事,讲的什么呢?从前有座山,山里有座庙,庙 ...

  6. C#泛型应用及原理

    https://blog.csdn.net/ananlele_/article/details/97623254 https://blog.csdn.net/kebi007/article/detai ...

  7. 图的最短路径算法Dijkstra算法模板

    Dijkstra算法:伪代码 //G为图,一般设为全局变量,数组d[u]为原点到达个点的额最短路径, s为起点 Dijkstra(G, d[u], s){ 初始化: for (循环n次){ u = 是 ...

  8. 在x64的Ubuntu系统下安装64bit的交叉编译工具aarch64-linux-gnu-gcc【转】

    sudo apt-cache search aarch64 查看哪些版本可以安装: sudo apt--aarch64-linux-gnu 安装一个gcc开头的5版本的支持64bit ARM linu ...

  9. C++算法导论第九章O(n)期望选择序列第i小的数字

    #include<iostream> #include<vector> #include<algorithm> #include<time.h> usi ...

  10. QT+VS后中文字符乱码问题

    在VS中写QT项目会出现中文乱码现象,尤其是控件的中文乱码以及qDebug()时候中文乱码通用的解决办法: 在头文件(.h)前面加上如下代码: #ifdef WIN32 #pragma executi ...