#训练过程的可视化 ,TensorBoard的应用
#导入模块并下载数据集
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data #设置超参数
max_step=1000
learning_rate=0.001
dropout=0.9 # 用logdir明确标明日志文件储存路径
#训练过程中的数据储存在E:\\MNIST_data\\目录中,通过这个路径指定--log_dir
data_dir='E:\\MNIST_data\\'
log_dir='E:\\mnist_with_summaries\\'
mnist=input_data.read_data_sets(data_dir,one_hot=True)
sess=tf.InteractiveSession() #本句的含义是使图可视化,sess.graph是对图的定义
#使用以上指定的路径创建摘要的文件写入符(FileWrite)
file_write=tf.summary.FileWriter(log_dir,sess.graph) def variable_summaries(var, name):
"""对每一个张量添加多个摘要描述"""
with tf.name_scope('summaries'):
tf.summary.histogram(name, var)
mean = tf.reduce_mean(var)
#均值
tf.summary.scalar('mean/' + name, mean)
stddev = tf.sqrt(tf.reduce_mean(tf.square(var - mean)))
#标准差
tf.summary.scalar('stddev/' + name, stddev)
# 最大值
tf.summary.scalar('max',tf.reduce_max(var))
# 最小值
tf.summary.scalar('min', tf.reduce_min(var))
tf.summary.histogram('histogram', var) def nn_layer(input_tensor, input_dim, output_dim, layer_name, act=tf.nn.relu):
with tf.name_scope(layer_name):
"""为确保计算图中各个层的分组,给每一层添加一个name_scope"""
with tf.name_scope('weights'):
weights = tf.Variable(tf.truncated_normal([input_dim, output_dim], stddev=0.1))
variable_summaries(weights, layer_name + '/weights')
with tf.name_scope('biases'):
biases = tf.Variable(tf.constant(0.0, shape=[output_dim]))
variable_summaries(biases, layer_name + '/biases')
with tf.name_scope('Wx_plus_b'):
preactivate = tf.matmul(input_tensor, weights) + biases
# 激活前的直方图
tf.summary.histogram(layer_name + '/pre_activations', preactivate)
activations = act(preactivate, name='activation')
# 记录神经网络节点输出在经过激活函数之后的分布。
# 激活后的直方图
tf.summary.histogram(layer_name + '/activations', activations)
return activations #构建回归模型,输入原始真实值(group truth),采用sotfmax函数拟合,并定义损失函数和优化器
#定义回归模型
x = tf.placeholder(tf.float32, [None, 784])
activations = nn_layer(x,784,10,"x")
#训练模型
#使用InteractiveSession()创建交互式上下文tf会话,这里的会话是默认
#在tf.Tensor.eval 和tf.Operation.run中都可以使用该会话来运行操作(OP)
sess = tf.InteractiveSession()
#注意:之前的版本中使用的是 tf.initialize_all_variables 作为初始化全局变量,已被弃用,更新后的采用一下命令
tf.global_variables_initializer().run() for _ in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
sess.run(activations, feed_dict={x: batch_xs}) #运行tensorboard命令,打开浏览器,查看模型训练过程中的可视化结果,
#在终端输入下命令:
#tensorboard --logdir=E:\\mnist_with_summaries\\

吴裕雄 python 神经网络——TensorFlow 训练过程的可视化 TensorBoard的应用的更多相关文章

  1. 吴裕雄 python 神经网络——TensorFlow训练神经网络:不使用滑动平均

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 ...

  2. 吴裕雄 python 神经网络——TensorFlow训练神经网络:不使用隐藏层

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 ...

  3. 吴裕雄 python 神经网络——TensorFlow训练神经网络:不使用激活函数

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 ...

  4. 吴裕雄 python 神经网络——TensorFlow训练神经网络:不使用指数衰减的学习率

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 ...

  5. 吴裕雄 python 神经网络——TensorFlow训练神经网络:不使用正则化

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 ...

  6. 吴裕雄 python 神经网络——TensorFlow训练神经网络:全模型

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 ...

  7. 吴裕雄 python 神经网络——TensorFlow训练神经网络:MNIST最佳实践

    import os import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_N ...

  8. 吴裕雄 python 神经网络——TensorFlow训练神经网络:花瓣识别

    import os import glob import os.path import numpy as np import tensorflow as tf from tensorflow.pyth ...

  9. 吴裕雄 python 神经网络——TensorFlow训练神经网络:卷积层、池化层样例

    import numpy as np import tensorflow as tf M = np.array([ [[1],[-1],[0]], [[-1],[2],[1]], [[0],[2],[ ...

随机推荐

  1. 错误:pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

    pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', ...

  2. CentOS安装RabbitMQ-yum

    CentOS安装RabbitMQ----yum安装 一.安装erlang 由于CentOS没有erlang源,需用 第三方源(http://rpmfusion.org/Configuration) 1 ...

  3. K3/Cloud点击按钮打开第三方URL

    public override void AfterBarItemClick(BOS.Core.DynamicForm.PlugIn.Args.AfterBarItemClickEventArgs e ...

  4. 基于Java+HttpClient+TestNG的接口自动化测试框架(八)------ 针对文件的处理

    在实际的接口测试中,有时需要根据情况进行文件的上传和下载.在文件数量比较小的时候,我们当然可以直接处理(比如若干个接口都用一个文件).但是,如果我们上传的文件需要使用不同文件夹里不同的文件,而且数量又 ...

  5. 剑指offer 面试题. 数据流中的中位数

    题目描述 如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值.如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中间两个数的平均值.我们 ...

  6. C++索引从0开始的堆排序算法实现

    更新2019年11月4日 04:26:35 睡不着觉起来寻思寻思干点啥吧,好像好久没写堆排了.于是写了个索引从0开始的堆排,这次把建堆函数略了并在heapsort主函数里,索引从0开始到size-1结 ...

  7. OmniGraffle原型案例 | 某APP产品原型PDF文件分享之二

    1.从 App 首页进入商城 App底部 Tab有社区.商城,我们点击「商城」进入「乐宠商城」,下面简称商城.商城采用的是经典的宫格式导航设计(还有普通列表式.和瀑布流列表式.或两者皆有等),主要有搜 ...

  8. machinekey相关信息

    在session共享时必须将web.config中的machineKey配置为相同的加解密算法 <system.web> <machineKey decryptionKey=&quo ...

  9. 今天我解决的sql中文乱码问题

    昨天我终于把我的网站做好了,在电脑上准备就绪,经过测试一切正常,放上服务器上准备炫耀一下的时候,发现插进数据库的中文字段全都变成???了,检测了下,前台是utf-8,后台是utf-8,在插进数据库前我 ...

  10. 1059 Prime Factors (25分)

    1059 Prime Factors (25分) 1. 题目 2. 思路 先求解出int范围内的所有素数,把输入x分别对素数表中素数取余,判断是否为0,如果为0继续除该素数知道余数不是0,遍历到sqr ...