TensorBoard-可视化简单例子
2017-04-19 10:03
288 查看
一、代码例子
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 18 18:50:24 2017
@author: YDD
"""
'''
生成一个文件,保存在‘logs/’文件里面(此处我的logs为:G:\Spyder_文件集\logs)
然后在命令行终端(cmd)中运行该文件(tensorboard --logdi='logs/')回车,拷贝网址(http://169.254.61.28:6006),选择GRAPH,即可显示
'''
import tensorflow as tf
#import numpy as np
#import matplotlib.pyplot as plt
sess = tf.Session()
def add_layer(inputs, in_size,out_size,activation_function=None):
with tf.name_scope('layer'):
with tf.name_scope('weights'):
Weights = tf.Variable(tf.random_normal([in_size,out_size]))#随机初始值的一个矩阵。
with tf.name_scope('biases'):
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1) #初始值都是0.1的一个列表.
with tf.name_scope('Wx_plus_b'):
Wx_plus_b = tf.matmul(inputs, Weights) + biases #未被激活的值,存在Wx_plus_b中。
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)
return outputs
#自己定义了所有的数据。
#x_data = np.linspace(-1,1,300)[:,np.newaxis] #建造输入,-1到1区间300个单位【维度】,一个特性有300个例子。
#noise = np.random.normal(0,0.05,x_data.shape) #噪声,方差是0.05,格式和x_data一样。
#y_data = np.square(x_data)-0.5 + noise #输出y=x^2 -0.5+noise.
with tf.name_scope('inputs'):
xs = tf.placeholder(tf.float32,[None,1],name='x_input')
ys = tf.placeholder(tf.float32,[None,1],name='y_input')
#建立一个隐藏层hidden1(10个神经元),一个输出层prediction(1个神经元)
hidden1 = add_layer(xs,1,10,activation_function=tf.nn.relu) #激活函数选择tf.nn.relu。(可尝试其他激活函数,选择误差结果较小最好)
prediction = add_layer(hidden1,10,1,activation_function=None)
with tf.name_scope('loss'):
loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys-prediction),
reduction_indices=[1])) #求一个预测值的平方误差,然后将所有的平方误差求和,最后求和的一个平均值。
with tf.name_scope('train_step'):
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss) #学习的速率为0.1.
# 这里注意和教程有点差别!!#选定可视化存储目录
writer = tf.summary.FileWriter("logs/",sess.graph)
init = tf.global_variables_initializer()
sess.run(init)
二、运行代码,生成文件
三、命令行终端,找到该文件路径下,运行文件
四、复制网址,并网页打开查看可视化结果
(参考 http://v.youku.com/v_show/id_XMTYxMTYwMjEwMA==.html?f=27327189&o=0&spm=a2h1n.8251843.playList.5!17~5~A)
8cf5
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 18 18:50:24 2017
@author: YDD
"""
'''
生成一个文件,保存在‘logs/’文件里面(此处我的logs为:G:\Spyder_文件集\logs)
然后在命令行终端(cmd)中运行该文件(tensorboard --logdi='logs/')回车,拷贝网址(http://169.254.61.28:6006),选择GRAPH,即可显示
'''
import tensorflow as tf
#import numpy as np
#import matplotlib.pyplot as plt
sess = tf.Session()
def add_layer(inputs, in_size,out_size,activation_function=None):
with tf.name_scope('layer'):
with tf.name_scope('weights'):
Weights = tf.Variable(tf.random_normal([in_size,out_size]))#随机初始值的一个矩阵。
with tf.name_scope('biases'):
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1) #初始值都是0.1的一个列表.
with tf.name_scope('Wx_plus_b'):
Wx_plus_b = tf.matmul(inputs, Weights) + biases #未被激活的值,存在Wx_plus_b中。
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)
return outputs
#自己定义了所有的数据。
#x_data = np.linspace(-1,1,300)[:,np.newaxis] #建造输入,-1到1区间300个单位【维度】,一个特性有300个例子。
#noise = np.random.normal(0,0.05,x_data.shape) #噪声,方差是0.05,格式和x_data一样。
#y_data = np.square(x_data)-0.5 + noise #输出y=x^2 -0.5+noise.
with tf.name_scope('inputs'):
xs = tf.placeholder(tf.float32,[None,1],name='x_input')
ys = tf.placeholder(tf.float32,[None,1],name='y_input')
#建立一个隐藏层hidden1(10个神经元),一个输出层prediction(1个神经元)
hidden1 = add_layer(xs,1,10,activation_function=tf.nn.relu) #激活函数选择tf.nn.relu。(可尝试其他激活函数,选择误差结果较小最好)
prediction = add_layer(hidden1,10,1,activation_function=None)
with tf.name_scope('loss'):
loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys-prediction),
reduction_indices=[1])) #求一个预测值的平方误差,然后将所有的平方误差求和,最后求和的一个平均值。
with tf.name_scope('train_step'):
train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss) #学习的速率为0.1.
# 这里注意和教程有点差别!!#选定可视化存储目录
writer = tf.summary.FileWriter("logs/",sess.graph)
init = tf.global_variables_initializer()
sess.run(init)
二、运行代码,生成文件
三、命令行终端,找到该文件路径下,运行文件
四、复制网址,并网页打开查看可视化结果
(参考 http://v.youku.com/v_show/id_XMTYxMTYwMjEwMA==.html?f=27327189&o=0&spm=a2h1n.8251843.playList.5!17~5~A)
8cf5
相关文章推荐
- 简单卷积神经网络的tensorboard可视化
- 超简单tensorflow入门优化程序&&tensorboard可视化
- TensotFlow 应用实例:08-使用tensorboard可视化神经网络结构和训练结果
- tensorflow tensorboard可视化并保存训练结果
- Windows10下TensorBoard可视化实例(附调整后代码)
- tensorflow可视化即tensorboard可视化无法加载数据的原因及其解决方案如下
- Tensorboard可视化好帮手2
- Tensorflow实战学习(七)【Tensor、Graph、Op、Variable、占位符、Session、名称作用域、Board综合例子】
- TensorBoard可视化助手
- 【tensorflow学习】使用tensorboard实现数据可视化
- TF:TF之Tensorboard实践:将神经网络Tensorboard形式得到events.out.tfevents文件+dos内运行该文件本地服务器输出到网页可视化—Jason niu
- TensorFlow基础教程:tensorboard训练过程可视化
- TensorFlow-6-TensorBoard 可视化学习
- Tensorflow的可视化工具Tensorboard
- tensorflow6---tensorboard可视化简易教程(一看就懂!)
- TensorFlow实战15:TensorBoard的使用(tensorflow的可视化工具)
- TensorFlow高级API(tf.contrib.learn)及可视化工具TensorBoard的使用
- tensorflow中可视化tensorboard的启动
- tensorflow(5) Tensorboard可视化
- TensorFlow学习笔记(四):Tensorflow网络构建和TensorBoard进行训练过程可视化