tensorflow之tensorboard
参考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的更多相关文章
- Tensorflow 笔记 -- tensorboard 的使用
Tensorflow 笔记 -- tensorboard 的使用 TensorFlow提供非常方便的可视化命令Tensorboard,先上代码 import tensorflow as tf a = ...
- Tensorflow 之 TensorBoard可视化Graph和Embeddings
windows下使用tensorboard tensorflow 官网上的例子程序都是针对Linux下的:文件路径需要更改 tensorflow1.1和1.3的启动方式不一样 :参考:Running ...
- 学习TensorFlow,TensorBoard可视化网络结构和参数
在学习深度网络框架的过程中,我们发现一个问题,就是如何输出各层网络参数,用于更好地理解,调试和优化网络?针对这个问题,TensorFlow开发了一个特别有用的可视化工具包:TensorBoard,既可 ...
- 学习笔记CB013: TensorFlow、TensorBoard、seq2seq
tensorflow基于图结构深度学习框架,内部通过session实现图和计算内核交互. tensorflow基本数学运算用法. import tensorflow as tf sess = tf.S ...
- 【Tensorflow】tensorboard
tbCallBack = tf.keras.callbacks.TensorBoard(log_dir='./log' , histogram_freq=0, write_graph=True, wr ...
- Windows系统,Tensorflow的Tensorboard工具细节问题
随着跟着TensorFlow视频学习,学到Tensorboard可视化工具这里的时候. 在windows,cmd里面运行,tensorboard --logdir=你logs文件夹地址 这行代码,一 ...
- 莫烦tensorflow(6)-tensorboard
import tensorflow as tfimport numpy as np def add_layer(inputs,in_size,out_size,n_layer,activation_f ...
- 基于TensorFlow进行TensorBoard可视化
# -*- coding: utf-8 -*- """ Created on Thu Nov 1 17:51:28 2018 @author: zhen "&q ...
- tensorflow 之tensorboard 对比不同超参数训练结果
我们通常使用tensorboard 统计我们的accurate ,loss等,并绘制曲线,通常是使用一次训练中的, 但是,机器学习中通常要对比不同的 ‘超参数’给模型训练和预测能力的不同这时候如何整合 ...
随机推荐
- 【转】VS2017离线安装
[转自]https://www.cnblogs.com/feigao/p/8409606.html 第一步:下载离线安装包 https://www.visualstudio.com/zh-hans/d ...
- 后台执行linux命令
/** * * 方法说明:移植执行linux命令 * * @param cmdStr 需要执行的linux命令 * @return 执行命令后的输出(如果是启动一个进程,则可能一直无法返回) * @t ...
- web前端常用库
项目中可能用到的web前端库(持续记录): 1.轻量化货币库:https://github.com/openexchangerates/accounting.js ,美元形式.欧元形式等 2.时间 ...
- ET框架之自写模块SmartTimerModule
1.代码结构图 2.SmartTimer 模块Entity: using System; namespace ETModel { [ObjectSystem] public class SmartTi ...
- JS 获取当天所在月的第一天的日期,最后一天日期,所在周的每天的日期,时间,所在每月日期,时间的计算
/** * 获取当天所在月的最后一天日期,和下一个月的第一天日期 * 调用getMonthDay(d), d默认值为01,d为要设置成的day: */ const getMonthMaxDay = ( ...
- JS jQuery 点击页面漂浮出文字
看到有些网站点击页面任意地方都会弹出文字出来 感觉很炫酷 但其实实现方法很简单 哇哈哈哈~~~ // 调用 ( e, 消失毫秒, 数组, 向上漂浮距离) $(document).click(funct ...
- springboot13(redis缓存)
redis做springboot2.x的缓存 1.首先是引入依赖 <dependency> <groupId>org.springframework.boot</grou ...
- null值与非null只比较大小时,只会返回false
DateTime? time=null; DateTime now=DateTime.Now; null值与非null只比较大小时,只会返回false 无论是大于比较还是小于比较还是等于,都会返回fa ...
- Vue中美元$符号的意思
vue的实例属性和方法 除了数据属性,Vue 实例还暴露了一些有用的实例属性与方法.它们都有前缀 $,以便与用户定义的属性区分开来.例如: var data = { a: 1 } var vm = n ...
- span强制不换行
<nobr>不换行内容</nobr> 无论多少文字均不希望换行显示,超出宽度的内容会显示不出来. <div> <nobr> <span class ...