一、TensorBoard可视化工具

TensorBoard实现形式为web应用程序,这为提供分布式、跨系统的图形界面服务带来了便利。

1.使用流程

SummaryOps->Session--(input)-->FileWriter---(add)--->Event file---(load)-->TensorBoard

import tensorflow as tf

with tf.name_scope('graph') as scope:
matrix1 = tf.constant([[3., 3.]],name ='matrix1') #1 row by 2 column
matrix2 = tf.constant([[2.],[2.]],name ='matrix2') # 2 row by 1 column
product = tf.matmul(matrix1, matrix2,name='product') sess = tf.Session() writer = tf.summary.FileWriter("/data/logs/", sess.graph) #第一个参数指定生成文件的目录。 init = tf.global_variables_initializer() sess.run(init)

命令行执行 tensorboard --logdir=/data/logs

打开localhost:6006

如图所示,tf.summary 模块的功能

2.可视化数据流图

通过with tf.name_scope('sc_name'):定义一个名字可以把一些列操作定义为一个节点,在图上展示为一个节点

点击加号可以展示节点内详情

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('/Users/quxiaoyuan/work/data/mnist',one_hot=True)
with tf.name_scope('input'):
x = tf.placeholder(tf.float32,[None,784],name='x-input')
y_ = tf.placeholder(tf.float32,[None,10],name='y-input')
with tf.name_scope('softmax_layer'):
with tf.name_scope('weights'):
weights = tf.Variable(tf.zeros([784,10]))
with tf.name_scope('biases'):
biases = tf.Variable(tf.zeros([10]))
with tf.name_scope('Wx_plus_b'):
y = tf.matmul(x,weights) + biases with tf.name_scope('cross_entropy'):
diff = tf.nn.softmax_cross_entropy_with_logits(labels=y_,logits=y)
with tf.name_scope('total'):
cross_entropy = tf.reduce_mean(diff)
tf.summary.scalar('cross_entropy',cross_entropy)
with tf.name_scope('train'):
train_step = tf.train.AdamOptimizer(0.001).minimize(cross_entropy) with tf.name_scope('accuracy'):
with tf.name_scope('correct_prediction'):
correct_prediction = tf.equal(tf.argmax(y,1),tf.argmax(y_,1))
with tf.name_scope('accuracy'):
accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32))

3.ft.summary操作

add_summay生成折线图

with tf.name_scope('cross_entropy'):
diff = tf.nn.softmax_cross_entropy_with_logits(labels=y_,logits=y)
with tf.name_scope('total'):
cross_entropy = tf.reduce_mean(diff)
tf.summary.scalar('cross_entropy',cross_entropy) with tf.name_scope('train'):
train_step = tf.train.AdamOpimizer(0.01).minimize(cross_entropy) with tf.name_scope('accuracy'):
with tf.name_scope('correct_prediction'):
correct_prediction = tf.equal(tf.argmax(y,1),tf.argmax(y_,1))
with tf.name_scope('accuracy'):
accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
tf.summary.scalar('accuracy',accuracy) merged = tf.summary.merge_all()
for i in range(FLAGS.max_step):
if i % FLAGS.max_step == 0:
summary, acc = sess.run([merged,accuracy],feed_dict=feed_dict(False))
witer.add_summary(summary,i)

histogram生成数据分布图

with tf.name_scope('softmax_layer'):
with tf.name_scope('weights'):
weights = tf.Variable(tf.zeros([784,10]))
tf.summary.histogram('weights',weights)

tf.summary.image生成图像

with tf.name_scope('input'):
x = tf.placeholder(tf.float32,[None,784],name='x-input')
y_ = tf.placeholder(tf.float32,[None,10],name='y-input') with tf.name_scope('input_reshape'):
image_shaped_input = tf.reshape(x,[-1,28,28,1])
tf.summary.image('input',image_shaped_input,10)

tensorflow(六)的更多相关文章

  1. TensorFlow(六):tensorboard网络结构

    # MNIST数据集 手写数字 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # ...

  2. TF Boys (TensorFlow Boys ) 养成记(六)

    圣诞节玩的有点嗨,差点忘记更新.祝大家昨天圣诞节快乐,再过几天元旦节快乐. 来继续学习,在/home/your_name/TensorFlow/cifar10/ 下新建文件夹cifar10_train ...

  3. 第四百一十六节,Tensorflow简介与安装

    第四百一十六节,Tensorflow简介与安装 TensorFlow是什么 Tensorflow是一个Google开发的第二代机器学习系统,克服了第一代系统DistBelief仅能开发神经网络算法.难 ...

  4. TF Boys (TensorFlow Boys ) 养成记(六): CIFAR10 Train 和 TensorBoard 简介

    圣诞节玩的有点嗨,差点忘记更新.祝大家昨天圣诞节快乐,再过几天元旦节快乐. 来继续学习,在/home/your_name/TensorFlow/cifar10/ 下新建文件夹cifar10_train ...

  5. TensorFlow从1到2(六)结构化数据预处理和心脏病预测

    结构化数据的预处理 前面所展示的一些示例已经很让人兴奋.但从总体看,数据类型还是比较单一的,比如图片,比如文本. 这个单一并非指数据的类型单一,而是指数据组成的每一部分,在模型中对于结果预测的影响基本 ...

  6. 第六节,TensorFlow编程基础案例-保存和恢复模型(中)

    在我们使用TensorFlow的时候,有时候需要训练一个比较复杂的网络,比如后面的AlexNet,ResNet,GoogleNet等等,由于训练这些网络花费的时间比较长,因此我们需要保存模型的参数. ...

  7. TensorFlow从入门到理解(六):可视化梯度下降

    运行代码: import tensorflow as tf import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.m ...

  8. 『PyTorch x TensorFlow』第六弹_从最小二乘法看自动求导

    TensoFlow自动求导机制 『TensorFlow』第二弹_线性拟合&神经网络拟合_恰是故人归 下面做了三个简单尝试, 利用包含gradients.assign等tf函数直接构建图进行自动 ...

  9. tensorFlow(六)应用-基于CNN破解验证码

    TensorFlow基础见前博客 简介 传统的验证码识别算法一般需要把验证码分割为单个字符,然后逐个识别.本教程将验证码识别问题转化为分类的问题,实现对验证码进行整体识别. 步骤简介 本教程一共分为四 ...

随机推荐

  1. -webkit-appearance —— webkit外观样式属性

    -webkit-appearance —— webkit外观样式属性 -webkit-appearance 是一个 不规范的属性(unsupported WebKit property),它没有出现在 ...

  2. Assignment写作需要掌握的两种表达方式

    在正式开始写Assignment之前都会进行文献检索和整理,选择适合Assignment选题的文献资料进行阅读和引用.对于文献中与自己的观点高度相关的参考资料要如何具体引用,而不造成抄袭或者增加文章的 ...

  3. vps 跑流量

  4. 8.scrapy的第一个实例

    [目标]要完成的任务如下: ※ 创建一个 Scrap项目.※ 创建一个 Spider来抓取站点和处理数据.※ 通过命令行将抓取的内容导出.※ 将抓取的内容保存的到 MongoDB数据库.======= ...

  5. PAT 2018 春

    A 1140 Look-and-say Sequence 简单模拟.可能要注意字符串第一个字符和最后一个字符的处理. #include <cstdio> #include <iost ...

  6. 分布式CAP定理(转)

    在弄清楚这个问题之前,我们先了解一下什么是分布式的CAP定理. 根据百度百科的定义,CAP定理又称CAP原则,指的是在一个分布式系统中,Consistency(一致性). Availability(可 ...

  7. 开发大型项目必备 98%公司都在用的十佳 Java Web 应用框架

    众所周知,工欲善其事,必先利其器.选择一个好的 Web 应用框架就像一把称手的兵器,可以助大家披荆斩棘. 今天就为大家整理了十佳 Java Web 应用框架,并简单讨论一下它们的优缺点. 第一,大名鼎 ...

  8. Thread--生产者消费者

    2个生产者,2个消费者,库存容量2 package p_c_allWait.copy; import java.util.LinkedList; import java.util.List; publ ...

  9. Vue专题-路由系统

    一切分离都是为了更好的结合,本文详细介绍了前后端分离架构之后,前端如果实现路由控制,即Vue路由系统. Vue路由系统 VueRouter实现原理 VueRouter的实现原理是根据监控锚点值的改变, ...

  10. NOIP 骗分技巧

    目录 第1章 绪论 第2章 从无解出发 \hookrightarrow↪ 2.1 无解情况 \hookrightarrow↪ 2.2 样例——白送的分数 第3章 “艰苦朴素永不忘” \hookrigh ...