TensorFlow(七):tensorboard网络执行
# MNIST数据集 手写数字
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data # 参数概要
def variable_summaries(var):
with tf.name_scope('summaries'):
mean=tf.reduce_mean(var)
tf.summary.scalar('mean',mean)# 平均值
with tf.name_scope('stddev'):
stddev=tf.sqrt(tf.reduce_mean(tf.square(var-mean)))
tf.summary.scalar('stddev',stddev)# 标准差
tf.summary.scalar('max',tf.reduce_max(var)) # 最大值
tf.summary.scalar('min',tf.reduce_min(var)) # 最小值
tf.summary.histogram('histogram',var) # 直方图 # 载入数据集
mnist=input_data.read_data_sets('MNIST_data',one_hot=True) # 每个批次的大小
batch_size=100
# 计算一共有多少个批次
n_batch=mnist.train.num_examples//batch_size # 命名空间
with tf.name_scope('input'):
# 定义两个placeholder
x=tf.placeholder(tf.float32,[None,784],name='x-input')
y=tf.placeholder(tf.float32,[None,10],name='y-input') with tf.name_scope('layer'):
# 创建一个简单的神经网络
with tf.name_scope('wights'):
W=tf.Variable(tf.zeros([784,10]),name='W')
variable_summaries(W)
with tf.name_scope('biases'):
b=tf.Variable(tf.zeros([10]),name='b')
variable_summaries(b)
with tf.name_scope('wx_plus_b'):
wx_plus_b=tf.matmul(x,W)+b
with tf.name_scope('softmax'):
prediction=tf.nn.softmax(wx_plus_b) with tf.name_scope('loss'):
# 二次代价函数
loss=tf.reduce_mean(tf.square(y-prediction))
tf.summary.scalar('loss',loss) # 一个值就不用调用函数了
with tf.name_scope('train'):
# 使用梯度下降法
train_step=tf.train.GradientDescentOptimizer(0.2).minimize(loss) # 初始化变量
init=tf.global_variables_initializer() with tf.name_scope('accuracy'):
with tf.name_scope('correct_prediction'):
# 求最大值在哪个位置,结果存放在一个布尔值列表中
correct_prediction=tf.equal(tf.argmax(y,1),tf.argmax(prediction,1))# argmax返回一维张量中最大值所在的位置
with tf.name_scope('accuracy'):
# 求准确率
accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32)) # cast作用是将布尔值转换为浮点型。
tf.summary.scalar('accuracy',accuracy) # 一个值就不用调用函数了 # 合并所有的summary
merged=tf.summary.merge_all() with tf.Session() as sess:
sess.run(init)
writer=tf.summary.FileWriter('logs/',sess.graph) # 写入文件 for epoch in range(10):
for batch in range(n_batch):
batch_xs,batch_ys=mnist.train.next_batch(batch_size)
summary,_=sess.run([merged,train_step],feed_dict={x:batch_xs,y:batch_ys}) # 添加样本点
writer.add_summary(summary,epoch)
#求准确率
acc=sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels})
print('Iter:'+str(epoch)+',Testing Accuracy:'+str(acc))
准确率

可以修改代码,增加训练时每个点的样本。
TensorFlow(七):tensorboard网络执行的更多相关文章
- tensorflow之tensorboard
参考https://www.cnblogs.com/felixwang2/p/9184344.html 边学习,边练习 # https://www.cnblogs.com/felixwang2/p/9 ...
- 网络知识--OSI七层网络与TCP/IP五层网络架构及二层/三层网络
作为一个合格的运维人员,一定要熟悉掌握OSI七层网络和TCP/IP五层网络结构知识. 废话不多说!下面就逐一展开对这两个网络架构知识的说明:一.OSI七层网络协议OSI是Open System Int ...
- 网络知识梳理--OSI七层网络与TCP/IP五层网络架构及二层/三层网络(转)
reference:https://www.cnblogs.com/kevingrace/p/5909719.html https://www.cnblogs.com/awkflf11/p/9190 ...
- Tensorflow 笔记 -- tensorboard 的使用
Tensorflow 笔记 -- tensorboard 的使用 TensorFlow提供非常方便的可视化命令Tensorboard,先上代码 import tensorflow as tf a = ...
- Tensorflow 之 TensorBoard可视化Graph和Embeddings
windows下使用tensorboard tensorflow 官网上的例子程序都是针对Linux下的:文件路径需要更改 tensorflow1.1和1.3的启动方式不一样 :参考:Running ...
- Alamofire源码解读系列(七)之网络监控(NetworkReachabilityManager)
Alamofire源码解读系列(七)之网络监控(NetworkReachabilityManager) 本篇主要讲解iOS开发中的网络监控 前言 在开发中,有时候我们需要获取这些信息: 手机是否联网 ...
- ISO/OSI七层网络参考模型、TCP/IP四层网络模型和教学五层网络模型
一.说明 直接的原因是昨晚<计算机网络(自顶向下方法)>到货了,以为能讲得有些不一样,但看完整本也就是老调地讲过来讲应用层.传输层.网络层.网络接口层.感觉比之谢希仁的<计算机网络& ...
- 红帽学习笔记[RHCSA] 第七课[网络配置相关]
第七课[网络配置相关] 在Vmware中添加网卡 编辑 -> 编辑虚拟网络 -> 添加网络->随便选择一个如VMnet2-> 选择仅主机模式 -> 勾掉使用本地DHCP服 ...
- TensorFlow创建DeepDream网络
TensorFlow创建DeepDream网络 Google 于 2014 年在 ImageNet 大型视觉识别竞赛(ILSVRC)训练了一个神经网络,并于 2015 年 7 月开放源代码. 该网络学 ...
随机推荐
- ifconfig介绍
[root@controller01 ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNK ...
- .ajaxStart() / .ajaxStop() —— ajax请求开始时 / 结束时触发
一..ajaxStart()——ajax请求开始时触发 描述:ajax请求开始时触发 .ajaxStart()的回调函数,全局的,所有的ajax都可以用 写法:元素.ajaxStart(functi ...
- 在论坛中出现的比较难的sql问题:14(存储过程问题 存储过程参数、存储过程内的参数)
原文:在论坛中出现的比较难的sql问题:14(存储过程问题 存储过程参数.存储过程内的参数) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的 ...
- .net通过网络路径下载文件至本地
获取网络文件,通过流保存文件,由于上一版存在数据丢失情况,稍微调整了以下. //网络路径文件 string pathUrl = "http://localhost:805/春风吹.mp3&q ...
- activemq BytesMessage || TextMessage
需求:使用 python 程序向 activemq 的主题推送数据,默认推送的数据类型是 BytesMessage,java 程序那边接收较为麻烦,改为推送 TextMessage 类型的数据 解决方 ...
- 基于re模块的计算器
最终计算器需求: 实现加减乘除及拓号优先级解析 用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - ...
- iOS退出APP
强制退出有四种: exit(); abort(); assert(); 主动制造一个崩溃: exit() 1.附加了关闭打开文件与返回状态码给执行环境,并调用你用atexit注册的返回函数: 2.警告 ...
- javascript_05-操作符
一元运算符 a++和++a //5 2 3 var a =1; var b = ++a + ++a; console.log(b) //4 1 3 var a =1; var b = a++ + ++ ...
- 1.Git & GitHup
1.常见的版本控制(管理代码的版本迭代)工具: @ svn:集中式版本控制系统: SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以首先要从中央服务器哪里 ...
- Nginx的平滑升级记录---适用于编译安装的Nginx
一.查看自己的Nginx的版本号 [root@localhost sbin]# cd /usr/local/nginx/sbin/ [root@localhost sbin]# ls nginx [r ...