2016-10-16 陈伟才 人为智能学堂;)
前不久工作被遇一个题目,如何以kettle统计好的数额每天早晨出殡给用户?以前还是每天早恢复手动写邮件然后再续加附件,觉得这么极其死了,就想在用kettle的机关发送邮件。通过查询资料终于实现了是效应,于是就想将出了跟大家享用,拯救那些要每天发送定位数据的基友。
一、TensorBoard简介
手续一样:邮箱授权
TensorFlow拥有强大的希冀计算,但是强大的觊觎计算而为是极端错综复杂的,对于新家的话,很麻烦知晓整个图计算上过程,这毋庸置疑增加了人工智能初家的修窍门。为底,TensorFlow提供的可视化WEB工具套件
倘若采用kettle发送邮件,必须安排你的发件邮箱,因此只要收获授权,我为此的凡163信箱,就将163邮箱来比喻
- –
TensorBoard,以图形化的章程展示及了解机器上之历程,进而拓展优化和调节。
1.登录您的信箱选择安装下的POP3/SMTP/IMAP
二、TensorBoard安装
选择 POP3/SMTP/IMAP
相似安装TensorFlow的长河遭到,同时为会见拿TensorBoard安装好。如仍上篇文章的仍过程,TensorBoard则装至~/tensorflow/bin目录下。我们可以直接开行TensorBoard服务,如下:
2.装授权密码:在邮箱的左边找到“客户端授权密码”,点击“开启”设置授权密码(要铭记密码,后面要因此),授权密码无能够同登录密码一样,这个得短信验证,如果看麻烦可以用QQ邮箱,QQ邮箱好像不用短信验证
# nohup tensorflow/bin/tensorboard –logdir=/root/tensor-board/logs
>/dev/null 2>&1 &
手续二:创建转换任务
启航命令指定了tensorboard
logdir目录,即只要需要经TensorBoard可视化系统监控TensorFlow机器学习,则需以TensorFlow机器学习着指定将相关的log导入到上述logdir中,这样,TensorBoard会从logdir分析相关实施进程,并拿结果显示下。
冲各自的需创建转化任务,我这里就是随便创建一个,从mysql表中抽取数据,过滤后用结果输出及文件被
什么样以TensorFlow中增代码实现可视化监控,并透过TensorBoard展示,在本篇下文会详细描述。
手续三:创建作业调度转换并发送邮件
TensorBoard web工具集将会督查6006端口,即在浏览器被输入
http://127.0.0.1:6006/ 则可以视TensorBoard神秘面纱,如下图所示:
1.可以于start中装置每天只要发送的日(这个深简单就未截图了)
TensorFlow官方给提供了一个交互式的demo让初学者了解TensorBoard,
2.调所以才缔造的变换节点,找到你待调度的换,我刚刚创建的易时kettle
https://www.tensorflow.org/tensorboard/index.html
3.布局并发送邮件
三、TensorBoard APIs
安排地址
- tf.scalar_summary(tags, values, collections=None, name=None)
安排服务器
2.tf.image_summary(tag, tensor, max_images=3, collections=None,
name=None)
部署附件
-
tf.audio_summary(tag, tensor, sample_rate, max_outputs=3,
collections=None, name=None) -
tf.histogram_summary(tag, values, collections=None, name=None)
这么安排好后运行就得接收邮件了,不用每天手动发统计数据了。
上述这组API分别针对标量,图片,音频以及柱状图进行汇总统计,以Protocol
Buffer结构进行表示。
一旦生帮带到你请动动你的粗手硌单赞,谢谢,有啊问题可以留言交流
- tf.merge_all_summaries(key=’summaries’)
该API则是对有类型的统计最终汇总在默认的Graph中。
- class tf.train.SummaryWriter
此类负责用上述APIs收集至之音讯(Protocal
Buffer形式)持久化到磁盘event文件被错过。
下面我们盖MNIST为例,展示什么行使TensorBoard进行可视化信息搜集与显。
四、MNIST TensorBoard版本
脚我们上述同等篇文章被的MNIST例子也示范,增加TensorBoard
Summary,实现TensorBoard可视化。对W,B,cross_entropy,accuracy等变量进行summary,并以收集到之信持久化到/root/tensor-board/logs/mnist_logs目录下之文书。
拖欠次可以从https://github.com/chenweicai/tensorflow-study/blob/master/tf\_softmax\_mnist\_tensorboard.py出下载。
# Softmax Regression using tensorflow.
import tensorflow as tf
# Download the mnist data.
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets(“/tmp/MNIST_data”, one_hot=True)
# Input placeholder, 2-D tensor of floating-point nunbers.
# here None means that a dimension can be of any length.
X = tf.placeholder(tf.float32, [None, 784], name = ‘X-input’)
# New placeholder to input the correct answers.
Y = tf.placeholder(tf.float32, [None, 10], name = ‘Y-input’)
# Initialize both W and b as tensors full of zeros.
# Since we are going to learn W and b, it doesn’t
# matter very much what they initial are.
W = tf.Variable(tf.zeros([784, 10]), name = ‘Weight’)
B = tf.Variable(tf.zeros([10]), name = ‘Bias’)
# Tensorboard histogram summary.
tf.histogram_summary(‘Weight’, W)
tf.histogram_summary(‘Bias’, B)
with tf.name_scope(‘Layer’):
y = tf.nn.softmax(tf.matmul(X, W) + B)
with tf.name_scope(‘Cost’):
cross_entropy = tf.reduce_mean(-tf.reduce_sum(Y * tf.log(y), \
reduction_indices=[1]))
# Tensorboard scalar summary.
tf.scalar_summary(‘Cost’, cross_entropy)
with tf.name_scope(‘Train’):
train_step =
tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
with tf.name_scope(‘Accuracy’):
accuracy = tf.reduce_mean(tf.cast(tf.equal(tf.argmax(y, 1), \
tf.argmax(Y, 1)), tf.float32))
# Tensorboard scalar summary.
tf.scalar_summary(‘Accuracy’, accuracy)
with tf.Session() as sess:
# Merge all summaries.
writer = tf.train.SummaryWriter(‘/root/tensor-board/logs/mnist_logs’,
sess.graph)
merged = tf.merge_all_summaries()
tf.initialize_all_variables().run()
# Training 1000 times, 100 for each loop.
for i in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
_, summary = sess.run([train_step, merged], feed_dict={X:
batch_xs, Y: batch_ys})
# Write summary into files.
writer.add_summary(summary, i)
# Close summary writer.
writer.close()
print(‘Accuracy’, accuracy.eval({X: mnist.test.images, Y:
mnist.test.labels}))
五、TensorBoard可视化
行上述顺序后,在浏览器被输入http://127.0.0.1:6006/,可以看到MNIST相关的信息,如下:
-
EVENTS
-
DISTRIBUTIONS
-
HISTOGRAMS
-
GRAPHS
点击上面节点如’Cost’,’Accurary’,’Layer’的’+’号,就能够进行该节点,能收看更详尽的消息,如下:
自打上图可以看看,通过TensorBoard可视化WEB工具,可以辅助我们针对机器上过程的理解,进而帮我们进行优化改进等。
参考资料
https://github.com/tensorflow/tensorflow/blob/r0.11/tensorflow/tensorboard/README.md
长按二维码关注群众号 ‘人工智能学堂’