tensorflow summary demo with linear-model
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的更多相关文章
- 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 ...
- 从线性模型(linear model)衍生出的机器学习分类器(classifier)
1. 线性模型简介 0x1:线性模型的现实意义 在一个理想的连续世界中,任何非线性的东西都可以被线性的东西来拟合(参考Taylor Expansion公式),所以理论上线性模型可以模拟物理世界中的绝大 ...
- Bayesian generalized linear model (GLM) | 贝叶斯广义线性回归实例
一些问题: 1. 什么时候我的问题可以用GLM,什么时候我的问题不能用GLM? 2. GLM到底能给我们带来什么好处? 3. 如何评价GLM模型的好坏? 广义线性回归啊,虐了我快几个月了,还是没有彻底 ...
- 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 ...
- Simple tutorial for using TensorFlow to compute a linear regression
"""Simple tutorial for using TensorFlow to compute a linear regression. Parag K. Mita ...
- 2. Linear Model
1. 基本形式 给定由$d$个属性描述的示例 $\textbf{x} =(x_1;x_2;...,x_n)$,其中$x_i$是$x$在第$i$个属性上的取值,线性模型(linear model)试图学 ...
- Tensorflow Summary用法
本文转载自:https://www.cnblogs.com/lyc-seu/p/8647792.html Tensorflow Summary用法 tensorboard 作为一款可视化神器,是学习t ...
- 广义线性模型(Generalized Linear Model)
广义线性模型(Generalized Linear Model) http://www.cnblogs.com/sumai 1.指数分布族 我们在建模的时候,关心的目标变量Y可能服从很多种分布.像线性 ...
- [机器学习]Generalized Linear Model
最近一直在回顾linear regression model和logistic regression model,但对其中的一些问题都很疑惑不解,知道我看到广义线性模型即Generalized Lin ...
随机推荐
- [考试总结]noip模拟11
菜 这次考试又是骗了一堆分数... 然而其实一个正解都没写... \(T1\) 的方法说实话确实不是很正统.... 然而却 \(A\) 了... 在打完 \(T1\) 后拍了老长时间... 然后就耽搁 ...
- 第一篇 -- Jmeter的安装下载
参考链接:https://blog.csdn.net/wust_lh/article/details/86095924 本篇介绍的是在Windows下安装Jmeter. 一.下载Jmeter 官网下载 ...
- 第二十九篇 -- UDP和TCP
最近在写WIFI模块,所以就想明确一些TCP和UDP的区别,发现以前的理解还是有点误区.现在重新学习. 相同点 UDP协议和TCP协议都是传输层协议 TCP(Transmission Control ...
- Django报错:'Specifying a namespace in include() without providing an app_name '
环境:win10(64)+pycharm2018.3+python3.7 在网页项目中使用include()方法 项目目录中同时存在app/urls.py和proj/urls.py 在proj/url ...
- 群晖NAS网络存储服务器防盗防小偷
群晖NAS网络存储服务器防盗防小偷 根据群晖NAS的实际测量外形尺寸到淘宝网邮购金属 配电箱(弱电箱). 把配电箱(弱电箱)用粗螺丝固定到机柜或墙壁上. 把群晖NAS用密码纯铜挂锁锁在配电箱(弱电箱 ...
- Docker 网络解读
Docker 容器在运行时,会涉及多个容器相互连接,甚至与宿主机上的应用连接的问题.既然需要产生连接,那么就必然要依赖网络. 网络在Docker的技术体系中,是一个不容易搞清楚的要点.因此,希望您读完 ...
- Windows服务器如何磁盘分区,Windows服务器磁盘分区常见的三种
原文来自:https://www.sohu.com/a/272133008_100217178 我怕链接会失效,故转载此篇文章,解析得很透彻,一目了然!记录. -------------------- ...
- 攻防世界Web区部分题解
攻防世界Web区部分题解 前言:PHP序列化就是把代码中所有的 对象 , 类 , 数组 , 变量 , 匿名函数等全部转换为一个字符串 , 提供给用户传输和存储 . 而反序列化就是把字符串重新转换为 ...
- 812考试总结(NOIP模拟37)[数列·数对·最小距离·真相]
前言 考得挺憋屈的... 先是搞了两个半小时的 T1 后来发现假了,又没多想跳了.. 然后一看 T2 这不是队长快跑嘛... 先是根据自己的想法打了一遍(考完之后发现是对的..) 然后回想了一下之前的 ...
- Awesome Notes
Install $ sudo aptitude install awesome Build from source $ aria2c -s 5 http://awesome.naquadah.org/ ...