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 ...
随机推荐
- P5471- K-D tree优化建图-弹跳
P5471- K-D tree优化建图-弹跳 优化建图是一种思想. 题意 有\(n\)个城市分布在小鸟岛上,有\(m\)个弹弓分布在这些城市里.因为弹弓体积大,固定麻烦,所以每个弹弓只能把小鸟弹飞到一 ...
- Flask 之linux部署
1.装python > `[root ~]# yum install gcc [root ~]# wget https://www.python.org/ftp/python/3.6.5/Pyt ...
- Docker run 命令参数及使用
Docker run 命令参数及使用 Docker run :创建一个新的容器并运行一个命令 语法 docker run [OPTIONS] IMAGE [COMMAND] [ARG...] OPTI ...
- Couchdb 垂直权限绕过漏洞(CVE-2017-12635)
影响版本:小于 1.7.0 以及 小于 2.1.1 首先,发送如下数据包: 修改数据包 { "type": "user", "name": ...
- 过渡——transition
① 设置参与过渡的属性 transition-property: ; all / transform / 参与过渡的属性 ② 设置过渡的时长 transition-duration: s ...
- Netty入门(三):EventLoop
前言 Netty系列索引: 1.Netty入门(一):ByteBuf 2.Netty入门(二):Channel IO相关: 1.Java基础(一):I/O多路复用模型及Linux中的应用 上文提到,早 ...
- 字节跳动上传了一份“面试官版Android面试小册”,不讲一句废话,全是精华
前言 金三银四马上就到了,很多粉丝朋友私信希望我出一篇面试专题或者分享面试相关的笔记来学习,这不今天就给大家安排上了?(都是干货,错过就是亏.) 下面的面试笔记都是精心整理好免费分享给大家的,希望新朋 ...
- Markdown 学习(语法)
标题 井号加空格(# ) 几个#就是几级标题 字体 粗体 (两边两个*) 斜体 (两边一个*) 斜体加粗 (两边三个*) 中间斜线 (两个波浪号~) 引用 选择引用,一个箭头 > 加空格 分割线 ...
- Docker部署Jenkins 2.285版持续部署集成实践(1)
抓取Jenkins镜像 docker pull jenkins/jenkins 创建映射本地路径: 运行Jenkins实例 docker for windows: docker run -it -p ...
- WPF listbox 实现动态滚轮下拉定位
private ObservableCollection<keymodel> _listlua; public ObservableCollection<keymodel> l ...