tf.summary + tensorboard 用来把graph图中的相关信息,如结构图、学习率、准确率、Loss等数据,写入到本地硬盘,并通过浏览器可视化之。

整理的代码如下:

import tensorflow as tf

x_train = [1, 2, 3, 6, 8]
y_train = [4.8, 8.5, 10.4, 21.0, 25.3] x = tf.placeholder(tf.float32, name='x')
y = tf.placeholder(tf.float32, name='y') W = tf.Variable(1, dtype=tf.float32, name='W')
b = tf.Variable(0, dtype=tf.float32, name='b') linear_model = W * x + b with tf.name_scope("loss-model"):
loss = tf.reduce_sum(tf.square(linear_model - y))
acc = tf.sqrt(loss)
tf.summary.scalar("loss", loss)
tf.summary.scalar("acc", acc) with tf.name_scope("Parameters"):
tf.summary.scalar("W", W)
tf.summary.scalar("b", b) tf.summary.histogram('histogram/norm', tf.random_normal(shape=[100], mean=10*b, stddev=1),)
tf.summary.image("image", tf.random_uniform([6,10,10,3]), max_outputs=10) train_step = tf.train.GradientDescentOptimizer(0.001).minimize(loss) sess = tf.Session()
sess.run(tf.global_variables_initializer()) # 收集所有的操作数据
merged = tf.summary.merge_all() # 创建writer对象
writer = tf.summary.FileWriter('./logs', sess.graph) # 训练
for i in range(300):
summary, _ = sess.run([merged, train_step], {x: x_train, y: y_train})
if i%10 == 0:
writer.add_summary(summary, i) curr_W, curr_b, curr_loss, curr_acc = sess.run([W, b, loss, acc], {x: x_train, y: y_train})
print("After train W: %f, b: %f, loss: %f, acc: %f" % (curr_W, curr_b, curr_loss, curr_acc))

运行结束后,可以看到logs文件夹如下所示:

在当前目录,运行tensorboard --logdir=./logs --port 6006,浏览器打开,得到如下页面

其中,颜色越深的切片越老,颜色越浅的切片越新。

参考:

https://www.jianshu.com/p/0ad3761e3614

https://blog.csdn.net/akadiao/article/details/79551180

https://blog.csdn.net/dcrmg/article/details/79810142

tensorflow summary demo with linear-model的更多相关文章

  1. TensorFlow Lite demo——就是为嵌入式设备而存在的,底层调用NDK神经网络API,注意其使用的tf model需要转换下,同时提供java和C++ API,无法使用tflite的见后

    Introduction to TensorFlow Lite TensorFlow Lite is TensorFlow’s lightweight solution for mobile and ...

  2. 从线性模型(linear model)衍生出的机器学习分类器(classifier)

    1. 线性模型简介 0x1:线性模型的现实意义 在一个理想的连续世界中,任何非线性的东西都可以被线性的东西来拟合(参考Taylor Expansion公式),所以理论上线性模型可以模拟物理世界中的绝大 ...

  3. Bayesian generalized linear model (GLM) | 贝叶斯广义线性回归实例

    一些问题: 1. 什么时候我的问题可以用GLM,什么时候我的问题不能用GLM? 2. GLM到底能给我们带来什么好处? 3. 如何评价GLM模型的好坏? 广义线性回归啊,虐了我快几个月了,还是没有彻底 ...

  4. Note for video Machine Learning and Data Mining——Linear Model

    Here is the note for lecture three. the linear model Linear model is a basic and important model in ...

  5. Simple tutorial for using TensorFlow to compute a linear regression

    """Simple tutorial for using TensorFlow to compute a linear regression. Parag K. Mita ...

  6. 2. Linear Model

    1. 基本形式 给定由$d$个属性描述的示例 $\textbf{x} =(x_1;x_2;...,x_n)$,其中$x_i$是$x$在第$i$个属性上的取值,线性模型(linear model)试图学 ...

  7. Tensorflow Summary用法

    本文转载自:https://www.cnblogs.com/lyc-seu/p/8647792.html Tensorflow Summary用法 tensorboard 作为一款可视化神器,是学习t ...

  8. 广义线性模型(Generalized Linear Model)

    广义线性模型(Generalized Linear Model) http://www.cnblogs.com/sumai 1.指数分布族 我们在建模的时候,关心的目标变量Y可能服从很多种分布.像线性 ...

  9. [机器学习]Generalized Linear Model

    最近一直在回顾linear regression model和logistic regression model,但对其中的一些问题都很疑惑不解,知道我看到广义线性模型即Generalized Lin ...

随机推荐

  1. MySql存储过程的创建与使用及在thinkphp中如何调用笔记

    学习sql的存储过程,笔记总结如下: MySQL默认将分号,即";"作为语句的分隔符.如果是这样的话,则一个存储过程将很难正常创建,因为它的BEGIN和END之间可以是任意数量的S ...

  2. c语言学习篇二【基础语法】

    一.定义常量: 使用 #define 预处理器. 使用 const 关键字. #include <stdio.h> int main() { const int LENGTH = 10;/ ...

  3. redis的单线程

    一.redis为什么这么快 1.完全基于内存,绝大部分请求是纯粹的内存操作,非常快速.数据存在内存中,类似于HashMap,HashMap的优势就是查找和操作的时间复杂度都是O(1):2.数据结构简单 ...

  4. GhostScript 沙箱绕过(命令执行)漏洞(CVE-2018-19475)

    影响范围 Ghostscript 9.24之前版本 将POC作为图片上传,执行命令,抓包 POST /index.php HTTP/1.1 Host: target Accept-Encoding: ...

  5. 用好WinSCP,无惧Linux命令

    很多人惧怕Linux系统的命令操作模式.实际上对于普通用户来说用到命令的概率非常小. 我们在实践过程中发现管理Linux系统,最多使用如下两个工具: WinSCP(必用):可视化界面工具,实现文件管理 ...

  6. ASPX页面传参中文乱码处理

    前端 function() { var msg='这是一段中文参数'; window.location.href="New.aspx?name="+escape(msg); } 后 ...

  7. 2020年度钻石C++C学习笔记(2)--《博学谷》

    2020年度钻石C++C--<博学谷> 1.以下标示符中命名合法的是A A.__A__ B.ab.c C.@rp D.2Y_ 2.设 a 和 b 均为 double 型变量,且a=5.5. ...

  8. 一个故事看懂HTTPS

    我是一个浏览器,每到夜深人静的时候,主人就打开我开始学习. 为了不让别人看到浏览记录,主人选择了"无痕模式". 但网络中总是有很多坏人,他们通过抓包截获我和服务器的通信,主人干了什 ...

  9. Docker部署netcore web实践

    1. 新建一个netcore的项目 2. 我们到项目的生成输出目录下,创建一个Dockerfile文件 3. 编辑Dockerfile文件 备注:红线圈住的地方,就是你生成的netcore的程序名称 ...

  10. Create Shortcut for SSH Hosts

    You frequently visit host 10.0.7.141 for example. It's a waste to type "ssh gcp@10.0.7.141" ...