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基础见前博客 简介 传统的验证码识别算法一般需要把验证码分割为单个字符,然后逐个识别.本教程将验证码识别问题转化为分类的问题,实现对验证码进行整体识别. 步骤简介 本教程一共分为四 ...
随机推荐
- JAVAEE 和项目开发(第六课:服务器的安装和目录介绍和闪退解决办法)
课程介绍: 在学习了 HTTP 协议后,我们对浏览器和服务器的交互流程以及规范有了一定程度的认知,并也有了自己的理解.但是不少同学对服务器的概念还是有些模糊的,那么本节课就针对服务器进行介绍,我们一起 ...
- Mac Go 环境变量配置
GOPATH 是工作目录,就是你打代码,代码的存放目录 GOROOT 是Go的安装目录,我下载的是免安装版的 现在的Go环境变量就是设置成这个样子, 终于Bee不会报错了!!!
- [安洵杯 2019]easy_web
0x00 知识点 md5强类型的绕过 方法比较固定: POST: a=%4d%c9%68%ff%0e%e3%5c%20%95%72%d4%77%7b%72%15%87%d3%6f%a7%b2%1b%d ...
- org.springframework.test.context.junit4.SpringJUnit4ClassRunner
项目中有了spring-test的依赖,里面确实也有 org.springframework.test.context.junit4.SpringJUnit4ClassRunner 此类,但是项目就是 ...
- CF #610Div2 B2.K for the Price of One (Hard Version) (dp解法 && 贪心解法)
原题链接:http://codeforces.com/contest/1282/problem/B2题目大意:刚开始有 p 块钱,商店有 n 件物品,你每次可以只买一件付那一件的钱,也可以买 k 件只 ...
- eclipse中tomcat添加或移除web项目出错,显示无资源能被添加或移除
错误截图 之前一直都能正常使用,今天莫名其妙出现这个错误 解决办法 https://blog.csdn.net/u012956987/article/details/79134474 右击项目,在属性 ...
- C语言中getopt()和getopt_long()函数的用法
一.参考文章 1.C语言中getopt()和getopt_long()函数的用法 2.linux 中解析命令行参数 (getopt_long用法) 二.调试经验
- vmbox 导入虚拟电脑之后无法上网
先执行 ip addr 查看有没有分配ip 用root执行dhclient -v命令去通过DHCP协议获取一个ip,在下图的最后一行可以看到ip已经分配成功dhclient命令可以用来释放你的电脑的I ...
- 【每日Scrum】第八天冲刺
一.计划会议内容 继续昨天的设计 二.任务看板 任务看板 已完成:登录与个人界面布局实现 进行中:UI设计美化,,地图主界面 待进行:功能整合,连接数据库 三.scrum讨论照片 四.产品的状态 无 ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习:Math(算数) 对象
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...