TensorFlow学习笔记--mnist可视化版本
2017-02-12 16:35
260 查看
主要代码tensorflow的官网上都有,这个版本主要是增加了一些可视化的东西。方便观察一些变量。
注:以下代码为1.0版本下
可以看到一个logs的文件,然后在命令窗口中打以下命令
$ tensorboard --logdir=mnist_logs
打开链接 http://0.0.0.0:6006
注:以下代码为1.0版本下
from tensorflow.examples.tutorials.mnist import input_data import tensorflow as tf sess = tf.InteractiveSession() mnist = input_data.read_data_sets('MNIST_data',one_hot=True) #set parameter learning_rate=0.001 #set placeholder with tf.name_scope('inputs'): x_input = tf.placeholder('float',[None,784],name='x_input') y_input = tf.placeholder('float',[None,10],name='y_input') #set variable with tf.name_scope('weights'): W = tf.Variable(tf.random_normal([784,10]), name='W') tf.summary.histogram('weights', W) with tf.name_scope('b'): b = tf.Variable(tf.random_normal([10]),name='b') tf.summary.histogram('b', b) #set graph with tf.name_scope('layer'): pred_y = tf.nn.softmax(tf.matmul(x_input,W)+b) tf.summary.histogram('out',pred_y) #set cost with tf.name_scope('loss'): loss =-tf.reduce_sum(y_input*tf.log(pred_y)) tf.summary.scalar('loss', loss) with tf.name_scope('train'): train = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss) sess = tf.Session() merged = tf.summary.merge_all() # save the logs train_writer = tf.summary.FileWriter("mnist_logs/train", sess.graph) test_writer = tf.summary.FileWriter("mnist_logs/test", sess.graph) #run with tf.Session() as sess: sess.run(tf.global_variables_initializer()) for i in range(1000): batch_xs,batch_ys = mnist.train.next_batch(100) sess.run(train,feed_dict={x_input:batch_xs,y_input:batch_ys}) if i % 50 == 0: correct_prediction = tf.equal(tf.argmax(pred_y,1),tf.argmax(y_input,1)) correct_rate = tf.reduce_mean(tf.cast(correct_prediction,'float32')) print sess.run(loss,feed_dict={x_input:mnist.test.images,y_input:mnist.test.labels}) print sess.run(correct_rate,feed_dict={x_input:batch_xs,y_input:batch_ys}) train_result = sess.run(merged,feed_dict={x_input:batch_xs,y_input:batch_ys}) train_writer.add_summary(train_result, i) test_result = sess.run(merged,feed_dict={x_input:mnist.test.images,y_input:mnist.test.labels}) test_writer.add_summary(test_result, i)
可以看到一个logs的文件,然后在命令窗口中打以下命令
$ tensorboard --logdir=mnist_logs
打开链接 http://0.0.0.0:6006
相关文章推荐
- Tensorflow学习笔记:基础篇(7)——Mnist手写集改进版(Tensorboard可视化)
- Tensorflow学习笔记:基础篇(3)——Mnist手写集初始版本
- TensorFlow学习笔记--1.0版本下的可视化
- 【深度学习】笔记1_Ubuntu14.04下caffe环境的搭建,无GPU版本以及python可视化环境的配置
- tensorflow学习笔记四:mnist实例--用简单的神经网络来训练和测试
- Tensorboard学习——mnist_with_summaries.py ---- TensorFlow可视化
- 学习笔记TF056:TensorFlow MNIST,数据集、分类、可视化
- TensorFlow官方教程学习笔记之3-用于机器学习专家学习的MNIST数据集(MNIST For ML Beginners)
- [TensorFlow]入门学习笔记(2)-卷积神经网络mnist手写识别
- tensorflow 学习笔记5 结果可视化
- 【深度学习】Tensorflow学习笔记--MNIST
- 关于Ubuntu16.04+Tensorflow学习笔记 MNIST导入
- tensorflow学习笔记五:mnist实例--卷积神经网络(CNN)
- TensorFlow官方教程学习笔记之2-用于机器学习初学者学习的MNIST数据集(MNIST For ML Beginners)
- TensorFlow官方教程学习笔记(三)——MNIST入门(续)
- DeepLearning&Tensorflow学习笔记2__mnist数据集CNN
- TensorFlow官方教程学习笔记(四)——MNIST数据集的读取
- 深度学习框架Caffe学习笔记(4)-MNIST数据集转换成可视化图片
- tensorflow学习笔记五:mnist实例--卷积神经网络(CNN)
- tensorflow 学习笔记9 卷积神经网络(CNN)实现mnist手写识别