参考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. V8 是怎么跑起来的 —— V8 中的对象表示

    V8 是怎么跑起来的 —— V8 中的对象表示 ThornWu The best is yet to come 30 人赞同了该文章 本文创作于 2019-04-30,2019-12-20 迁移至此本 ...

  2. [LOJ113] 最大异或和 - 线性基

    虽然是SB模板但还真是第一次手工(然而居然又被运算符优先级调戏了) #include <bits/stdc++.h> using namespace std; #define int lo ...

  3. 【算法学习记录-排序题】【PAT A1016】Phone Bills

    A long-distance telephone company charges its customers by the following rules: Making a long-distan ...

  4. Solr与对应Jdk版本的关系

    Solr各版本下载地址:http://archive.apache.org/dist/lucene/solr/ 下载的包里面的CHANGES.txt 有当前版本需要的说明.

  5. Python | 字符串拆分和拼接及常用操作

    一.字符串拆分 str = "hola ha1 ha2 china ha3 " # partition 从左侧找到第一个目标,切割成三组数据的[元组] str1 = str.par ...

  6. dfs题型二(迷宫问题)

    取自:<王道论坛计算机考研机试指南>6.5节 例 6.7 Temple of the bone(九度 OJ 1461)时间限制:1 秒 内存限制:32 兆 特殊判题:否题目描述:The d ...

  7. 安装Docker:解决container-selinux >= 2.9问题

    1.安装Docker要求Centos内核版本高于3.10:通过uname  -r查看当前系统的内核版本 uname  -r 2.使用root登陆系统,确保yum包保持更新到最新: sudo yum  ...

  8. (c#)删除链表中的节点

    题目 解: 解析: n1→n2→n3→n4删除n2即将n2更改成n3n1→n3(n2)→n4

  9. 杭电oj初体验之 Code

    PLA算法: https://blog.csdn.net/red_stone1/article/details/70866527 The problem: Analysis: 题目链接可见:https ...

  10. 十大常见web漏洞及防范

    十大常见web漏洞 一.SQL注入漏洞 SQL注入攻击(SQL Injection),简称注入攻击.SQL注入,被广泛用于非法获取网站控制权,是发生在应用程序的数据库层上的安全漏洞.在设计程序,忽略了 ...