tensorflow23《TensorFlow实战Google深度学习框架》笔记-09-04 TensorBoard 监控指标可视化 code
来源:互联网 发布:淘宝中年女模特好漂亮 编辑:程序博客网 时间:2024/05/20 23:37
# 《TensorFlow实战Google深度学习框架》09 TensorBoard可视化# win10 Tensorflow1.0.1 python3.5.3# CUDA v8.0 cudnn-8.0-windows10-x64-v5.1# filename:ts09.04.py # 监控指标可视化import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data# 1. 生成变量监控信息并定义生成监控信息日志的操作# C:\Python35>tensorboard --port=6006 --debug --logdir=c:/python35/tensorlog/show04SUMMARY_DIR = "c:/python35/tensorlog/show04"BATCH_SIZE = 100TRAIN_STEPS = 3000def 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)# 2. 生成一层全链接的神经网络def nn_layer(input_tensor, input_dim, output_dim, layer_name, act=tf.nn.relu): with tf.name_scope(layer_name): 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 activationsdef main(): mnist = input_data.read_data_sets("../../datasets/MNIST_data", one_hot=True) with tf.name_scope('input'): x = tf.placeholder(tf.float32, [None, 784], name='x-input') y_ = tf.placeholder(tf.float32, [None, 10], name='y-input') with tf.name_scope('input_reshape'): image_shaped_input = tf.reshape(x, [-1, 28, 28, 1]) tf.summary.image('input', image_shaped_input, 10) hidden1 = nn_layer(x, 784, 500, 'layer1') y = nn_layer(hidden1, 500, 10, 'layer2', act=tf.identity) with tf.name_scope('cross_entropy'): cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=y, labels=y_)) tf.summary.scalar('cross_entropy', cross_entropy) with tf.name_scope('train'): train_step = tf.train.AdamOptimizer(0.001).minimize(cross_entropy) with tf.name_scope('accuracy'): with tf.name_scope('correct_prediction'): correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1)) with tf.name_scope('accuracy'): accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) tf.summary.scalar('accuracy', accuracy) merged = tf.summary.merge_all() with tf.Session() as sess: summary_writer = tf.summary.FileWriter(SUMMARY_DIR, sess.graph) tf.global_variables_initializer().run() for i in range(TRAIN_STEPS): xs, ys = mnist.train.next_batch(BATCH_SIZE) # 运行训练步骤以及所有的日志生成操作,得到这次运行的日志。 summary, _ = sess.run([merged, train_step], feed_dict={x: xs, y_: ys}) # 将得到的所有日志写入日志文件,这样TensorBoard程序就可以拿到这次运行所对应的 # 运行信息。 summary_writer.add_summary(summary, i) summary_writer.close()if __name__ == '__main__': main()
0 0
- tensorflow23《TensorFlow实战Google深度学习框架》笔记-09-04 TensorBoard 监控指标可视化 code
- tensorflow20《TensorFlow实战Google深度学习框架》笔记-09-01 TensorBoard可视化测试 code
- tensorflow21《TensorFlow实战Google深度学习框架》笔记-09-02 TensorBoard命名空间 code
- tensorflow22《TensorFlow实战Google深度学习框架》笔记-09-03 TensorBoard改造后的mnist_train code
- tensorflow11 《TensorFlow实战Google深度学习框架》笔记-05-04mnist-nn最佳实践code
- tensorflow19《TensorFlow实战Google深度学习框架》笔记-08-04 预测正弦函数 code
- Tensorflow实战Google深度学习框架 笔记
- tensorflow26《TensorFlow实战Google深度学习框架》笔记-10-03 分布式TensorFlow code
- tensorflow03 《TensorFlow实战Google深度学习框架》笔记-04-01
- tensorflow14《TensorFlow实战Google深度学习框架》笔记-06-03 迁移学习 code
- tensorflow08 《TensorFlow实战Google深度学习框架》笔记-05-01minist数字识别问题code
- tensorflow09 《TensorFlow实战Google深度学习框架》笔记-05-02变量管理(命名空间)code
- tensorflow10 《TensorFlow实战Google深度学习框架》笔记-05-03模型持久化code
- tensorflow12《TensorFlow实战Google深度学习框架》笔记-06-01卷积层、池化层样例code
- tensorflow13《TensorFlow实战Google深度学习框架》笔记-06-02mnist LeNet5卷积神经网络 code
- tensorflow15《TensorFlow实战Google深度学习框架》笔记-07图像数据处理 code
- tensorflow16《TensorFlow实战Google深度学习框架》笔记-08-01 RNN前向传播 code
- tensorflow18《TensorFlow实战Google深度学习框架》笔记-08-03 SKlearn封装例子 code
- 使用msconfig命令时注意
- Shader编程学习笔记(二)—— Shader和渲染管线
- Spring整合Mybatis
- 导入项目的时候,提示说@override The method of type must override a superclass method解决方式的错误
- 老陈---谈Delphi中SSL协议的应用[转]
- tensorflow23《TensorFlow实战Google深度学习框架》笔记-09-04 TensorBoard 监控指标可视化 code
- Shader编程学习笔记(三)—— 三大主流编程语言 HLSL/GLSL/Cg
- 数据结构之概述(数据和算法基本概念,时间复杂度)
- Java基础加强:细说JDK动态代理的实现原理
- 【C语言】一个关于if的小问题
- [机器学习]机器学习笔记整理12-线性回归概念理解
- 优雅的使用Laravel之phpstorm配置
- coreseek分词配置
- 【C语言】优先级和求值顺序