TensorFlow基础笔记(9) Tensorboard可视化显示

参考: http://blog.csdn.net/l18930738887/article/details/55000008

import tensorflow as tf
import numpy as np
def add_layer(inputs, in_size, out_size, n_layer, activation_function=None):
    # add one more layer and return the output of this layer
    layer_name = ‘layer%s‘ % n_layer
    with tf.name_scope(layer_name):
        with tf.name_scope(‘weights‘):
            Weights = tf.Variable(tf.random_normal([in_size, out_size]), name=‘W‘)
            tf.summary.histogram(layer_name + ‘/weights‘, Weights)
        with tf.name_scope(‘biases‘):
            biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name=‘b‘)
            tf.summary.histogram(layer_name + ‘/biases‘, biases)
        with tf.name_scope(‘Wx_plus_b‘):
            Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases)
        if activation_function is None:
            outputs = Wx_plus_b
        else:
            outputs = activation_function(Wx_plus_b, )
        tf.summary.histogram(layer_name + ‘/outputs‘, outputs)
    return outputs
# Make up some real data
x_data = np.linspace(-1,1,300)[:, np.newaxis]
noise = np.random.normal(0, 0.05, x_data.shape)
y_data = np.square(x_data) - 0.5 + noise
# define placeholder for inputs to network
with tf.name_scope(‘inputs‘):
    xs = tf.placeholder(tf.float32, [None, 1],name=‘input_x‘)
    ys = tf.placeholder(tf.float32, [None, 1],name=‘input_y‘)

# add hidden layer
l1 = add_layer(xs, 1, 10, n_layer=1, activation_function=tf.nn.relu)
# add output layer
prediction = add_layer(l1, 10, 1, n_layer=2, activation_function=None)

# the error between prediciton and real data
with tf.name_scope(‘loss‘):
    loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction),
                                        reduction_indices=[1]))
    tf.summary.scalar(‘loss‘, loss)
with tf.name_scope(‘train‘):
    train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)

sess = tf.Session()
merged = tf.summary.merge_all()
# save the logs
writer = tf.summary.FileWriter("logs/", sess.graph)
sess.run(tf.global_variables_initializer())
for i in range(1000):
    # training
    sess.run(train_step, feed_dict={xs: x_data, ys: y_data})
    if i % 50 == 0:
        # to see the step improvement
        result = sess.run(merged,
                          feed_dict={xs: x_data, ys: y_data})
        writer.add_summary(result, i)

到运行python的所在目录下,打一下命令:

$ tensorboard --logdir="logs/"

再在网页中输入链接:127.0.1.1:6006 即可获得展示: 推荐使用friefox浏览器,我电脑上chrom浏览器打不开

时间: 2024-08-29 16:33:23

TensorFlow基础笔记(9) Tensorboard可视化显示的相关文章

TensorFlow基础笔记(0) 参考资源学习文档

1 官方文档 https://www.tensorflow.org/api_docs/ 2 极客学院中文文档 http://www.tensorfly.cn/tfdoc/api_docs/python/array_ops.html 3 TensorFlow基础笔记(2) minist分类学习

Tensorflow学习笔记3:TensorBoard可视化学习

TensorBoard简介 Tensorflow发布包中提供了TensorBoard,用于展示Tensorflow任务在计算过程中的Graph.定量指标图以及附加数据.大致的效果如下所示, TensorBoard工作机制 TensorBoard 通过读取 TensorFlow 的事件文件来运行.TensorFlow 的事件文件包括了你会在 TensorFlow 运行中涉及到的主要数据.关于TensorBoard的详细介绍请参考TensorBoard:可视化学习.下面做个简单介绍. Tensorf

学习TensorFlow,TensorBoard可视化网络结构和参数

在学习深度网络框架的过程中,我们发现一个问题,就是如何输出各层网络参数,用于更好地理解,调试和优化网络?针对这个问题,TensorFlow开发了一个特别有用的可视化工具包:TensorBoard,既可以显示网络结构,又可以显示训练和测试过程中各层参数的变化情况.本博文分为四个部分,第一部分介绍相关函数,第二部分是代码测试,第三部分是运行结果,第四部分介绍相关参考资料. 一. 相关函数 TensorBoard的输入是tensorflow保存summary data的日志文件.日志文件名的形式如:e

学习笔记TF039:TensorBoard

首先向大家和<TensorFlow实战>的作者说句不好意思.我现在看的书是<TensorFlow实战>.但从TF024开始,我在学习笔记的参考资料里一直写的是<TensorFlow实践>,我自己粗心搞错了,希望不至于对大家造成太多误导. TensorBoard,TensorFlow官方可视化工具.展示模型训练过程各种汇总数据.标量(Scalars).图片(Images).音频(audio).计算图(Graphs).数据分布(Distributions).直方图(Hist

tensorflow 基础安装

第1章 TensorFlow基础学习 1.1 1)TensorFlow Python 库安装 1)  pip install wheel 2)  download  tensorflow-.whl file a)     https://ci.tensorflow.org/view/Nightly/job/nightly-matrix-cpu/TF_BUILD_IS_OPT=OPT,TF_BUILD_IS_PIP=PIP,TF_BUILD_PYTHON_VERSION=PYTHON2,label

C# 基础笔记(第一篇)

C#基础 概念:.net与c#.net/dontnet:一般指.net framework框架,一种平台,一种技术c#(charp):一种编程语言,可以开发基于.net的应用. *java既是一种技术又是一种编程语言.                           .net都能干什么?开发桌面应用程序   Winforminternet应用程序    Asp.net/webservice C/S:客户机(Client)/服务器模式(Server)B/S:浏览器(Browser)/务器模式(

我的LINUX基础笔记

Linux系统管理      1 Day   2014.5.23 su -name   切换用户passwd 密码   更改密码gnome-terminal    伪CLI   桌面终端程序1.查看内核版本uname -r    2.查看红帽系统版本cat /etc/redhat-rdlease3.查看LINUX标准分发版信息  lsb_release4.查看网卡的IP,MAX       ifconfig                       ifconfig eth 10.0.0.10

Nginx基础笔记

Nginx基础笔记 资源 安装 ubuntu下 编译安装 基本操作 HTTP基本配置 配置说明 配置文件目录结构 配置文件结构 模块 模块化 index模块 Log模块 Real IP模块 Access模块 Rewrite模块 Proxy模块 upstream模块 其他 配置静态化目录 负载均衡 控制页面缓存 nginx的内置变量 nginx小结 资源 资源 Nginx 官网 Nginx 官方下载地址 Nginx最佳实践配置项目 地址 Nginx Configuration wiki 教程 ag

php代码审计基础笔记

出处: 九零SEC连接:http://forum.90sec.org/forum.php?mod=viewthread&tid=8059 ---------------------------------------------------------- team:xdsec&90sec author:wilson blog:http://blog.wils0n.cn/ 文章链接:wilson's blog_php代码审计基础笔记[求人气~~] ----------------------