tensorflow(六)
一、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(六)的更多相关文章
- TensorFlow(六):tensorboard网络结构
# MNIST数据集 手写数字 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # ...
- TF Boys (TensorFlow Boys ) 养成记(六)
圣诞节玩的有点嗨,差点忘记更新.祝大家昨天圣诞节快乐,再过几天元旦节快乐. 来继续学习,在/home/your_name/TensorFlow/cifar10/ 下新建文件夹cifar10_train ...
- 第四百一十六节,Tensorflow简介与安装
第四百一十六节,Tensorflow简介与安装 TensorFlow是什么 Tensorflow是一个Google开发的第二代机器学习系统,克服了第一代系统DistBelief仅能开发神经网络算法.难 ...
- TF Boys (TensorFlow Boys ) 养成记(六): CIFAR10 Train 和 TensorBoard 简介
圣诞节玩的有点嗨,差点忘记更新.祝大家昨天圣诞节快乐,再过几天元旦节快乐. 来继续学习,在/home/your_name/TensorFlow/cifar10/ 下新建文件夹cifar10_train ...
- TensorFlow从1到2(六)结构化数据预处理和心脏病预测
结构化数据的预处理 前面所展示的一些示例已经很让人兴奋.但从总体看,数据类型还是比较单一的,比如图片,比如文本. 这个单一并非指数据的类型单一,而是指数据组成的每一部分,在模型中对于结果预测的影响基本 ...
- 第六节,TensorFlow编程基础案例-保存和恢复模型(中)
在我们使用TensorFlow的时候,有时候需要训练一个比较复杂的网络,比如后面的AlexNet,ResNet,GoogleNet等等,由于训练这些网络花费的时间比较长,因此我们需要保存模型的参数. ...
- TensorFlow从入门到理解(六):可视化梯度下降
运行代码: import tensorflow as tf import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.m ...
- 『PyTorch x TensorFlow』第六弹_从最小二乘法看自动求导
TensoFlow自动求导机制 『TensorFlow』第二弹_线性拟合&神经网络拟合_恰是故人归 下面做了三个简单尝试, 利用包含gradients.assign等tf函数直接构建图进行自动 ...
- tensorFlow(六)应用-基于CNN破解验证码
TensorFlow基础见前博客 简介 传统的验证码识别算法一般需要把验证码分割为单个字符,然后逐个识别.本教程将验证码识别问题转化为分类的问题,实现对验证码进行整体识别. 步骤简介 本教程一共分为四 ...
随机推荐
- java向python ,text文件动态传参或传值问题完美解决
由于业务需要对python文件进行参数传递,通过下面两个java方法完美解决此问题,我的思路是:首先我要先把上次写的参数删除,第二我要新的参数写到python文件中. 第一个方法解决了删除上次传递的参 ...
- Swift保存RSA密钥到Keychain
https://www.jianshu.com/p/c1e9bffc76f4 最近项目的需求用到RSA的加密解密,并且需要把公钥信息保存到Keychain里面,网上很多文章都是用Keychain保存账 ...
- UML-持久框架-目标&关键思想
1.目标 1).使用模板方法.状态模式.命令模式来设计部分框架 2).介绍对象-关系(O-R)映射中的一些问题 3).使用虚代理实现的滞后具体化 2.关键思想 1).映射(Mapping) 类--表 ...
- CTF -攻防世界-crypto新手区(1~4)
题目已经提示用base64直接解密就行 base64解密网址 http://tool.oschina.net/encrypt?type=3 题目提示是凯撒密码 http://www.zjslove.c ...
- 学会拒绝,是一种智慧——OO电梯章节优化框架的思考
在本章的三次作业里,每次作业我都有一个主题,分别是:托盘型共享数据.单步电梯运行优化.多部电梯运行优化,因而电梯优化实际是第二.三次作业.虽然后两次作业从性能分上看做得还不错,但阅读其他大佬博客,我深 ...
- SQL基础教程(第2版)第2章 查询基础:练习题
SELECT product_name, regist_date FROM Product WHERE regist_date > '2009-04-28'; ① ~ ③中的 SQL 语句都无法 ...
- [Security] Web Security Essentials
In this course, we'll learn how to exploit and then mitigate several common Web Security Vulnerabili ...
- 编写shell脚本,使用 nohup 让springboot 项目在后台持续运行
1.将springboot项目打成jar放在linux的某个目录下. 2.新建一个nohup.log文件. 3.使用vi命令新建一个start.sh文件并写下以下内容: #!/bin/sh nohup ...
- 一文彻底搞懂Cookie、Session、Token到底是什么
> 笔者文笔功力尚浅,如有不妥,请慷慨指出,必定感激不尽 Cookie 洛:大爷,楼上322住的是马冬梅家吧? 大爷:马都什么? 夏洛:马冬梅. 大爷:什么都没啊? 夏洛:马冬梅啊. 大爷:马什 ...
- 63)对于STL基本概念东西 自己百度(没有整理)
基础知识 看 C++进阶课程讲义的那个word文档