Tensorflow—tensorboard网络结构
代码:
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data#载入数据集
#当前路径
mnist = input_data.read_data_sets("MNISt_data", one_hot=True)
运行结果:
Extracting MNISt_data/train-images-idx3-ubyte.gz
Extracting MNISt_data/train-labels-idx1-ubyte.gz
Extracting MNISt_data/t10k-images-idx3-ubyte.gz
Extracting MNISt_data/t10k-labels-idx1-ubyte.gz
代码:
#每个批次的大小
#以矩阵的形式放进去
batch_size = 100
#计算一共有多少个批次
n_batch = mnist.train.num_examples // batch_size#命名空间
with tf.name_scope('input'):#定义两个placeholder#28 x 28 = 784x = tf.placeholder(tf.float32, [None, 784], name='x_input')y = tf.placeholder(tf.float32, [None, 10], name='y_input')with tf.name_scope('layer'):#创建一个简单的神经网络#输入层784,没有隐藏层,输出层10个神经元with tf.name_scope('weights'):W = tf.Variable(tf.zeros([784, 10]), name='W')with tf.name_scope('biases'):b = tf.Variable(tf.zeros([1, 10]), name='b')with tf.name_scope('wx_plus_b'): wx_plus_b = tf.matmul(x, W) + bwith tf.name_scope('softmax'):prediction = tf.nn.softmax(wx_plus_b)with tf.name_scope('loss'):#二次代价函数loss = tf.reduce_mean(tf.square(y - prediction))#交叉熵#loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y, logits=prediction))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'):#结果存放在一个布尔型列表中#tf.argmax(y, 1)与tf.argmax(prediction, 1)相同返回True,不同则返回False#argmax返回一维张量中最大的值所在的位置correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(prediction, 1))with tf.name_scope('accuracy'):#求准确率#tf.cast(correct_prediction, tf.float32) 将布尔型转换为浮点型accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))with tf.Session() as sess:sess.run(init)#当前路径logs文件夹writer = tf.summary.FileWriter('logs/', sess.graph)#总共1个周期for epoch in range(1):#总共n_batch个批次for batch in range(n_batch):#获得一个批次batch_xs, batch_ys = mnist.train.next_batch(batch_size)sess.run(train_step, feed_dict={x:batch_xs, y:batch_ys})#训练完一个周期后准确率acc = sess.run(accuracy, feed_dict={x:mnist.test.images, y:mnist.test.labels})print("Iter" + str(epoch) + ", Testing Accuracy" + str(acc))
在命令行:(注意切换到当前路径下)
tensorboard --logdir=logs
效果展示:
Tensorflow—tensorboard网络结构相关推荐
- tensorflow神经网络结构可视化
代码如下: # -*- coding: utf-8 -*- import tensorflow as tf# 图像大小 IMAGE_HEIGHT = 256 IMAGE_WIDTH = 256 MAX ...
- Tensorflow— tensorboard网络运行
代码: import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data#载入数据集 #当前路径 m ...
- TensorFlow学习笔记(十二)TensorFLow tensorBoard 总结
Tensorboard: 如何更直观的观察数据在神经网络中的变化,或是已经构建的神经网络的结构.上一篇文章说到,可以使用matplotlib第三方可视化,来进行一定程度上的可视化.然而Tensorfl ...
- Tensorflow——Tensorboard可视化
1.前言 本节内容会用到浏览器, 而且与 tensorboard 兼容的浏览器是 "Google Chrome". 使用其他的浏览器不保证所有内容都能正常显示. 学会用 Tenso ...
- win7 下anaconda TensorFlow tensorboard使用
第一步在 Spyder(TensorFlow)中输入一下代码: # View more python learning tutorial on my Youtube and Youku channel ...
- tensorflow tensorboard summary的工作特点
自己之前主要使用summary来监督网络的训练,所以没有对summary有太多的使用.最近要用summary的数据进行对比分析并展示,所以了解到summary有以下运行特点 1. 每次训练时运行tf. ...
- 基于python实现resnet_【Tensorflow系列】使用Inception_resnet_v2训练自己的数据集并用Tensorboard监控...
[写在前面] 用Tensorflow(TF)已实现好的卷积神经网络(CNN)模型来训练自己的数据集,验证目前较成熟模型在不同数据集上的准确度,如Inception_V3, VGG16,Inceptio ...
- Tensorflow 可视化 TensorBoard 尝试~
tensorboard --logdir=/home/ubuntu/temp/log 注意:在阅读本文之前,请务必更新你的浏览器.Chrome大法好! 数据.模型可视化是TensorFlow的一项重 ...
- Tensorflow:Tensorboard使用
目录 目录 前言 可视化第一步 实现graphs 后记 前言 TensorFlow是以流动的张量为名的神经网络开发库,所以Google为了让人们更直观的了解流动的张量的含义,他们做了个TensorBo ...
最新文章
- centos transmission 无法开启登录验证
- mysql 浏览器可视窗口_浏览器窗口的可视区域大小指的是哪里?
- 设计模式--享元(Flyweight)模式
- MC34063组成DC-DC电路
- c语言 结构体练习之 实现产品销售记录的相关功能
- 年轻人逃离大城市之后的下一站选哪儿?用数据来为你揭晓
- python魔法属性_python魔法方法-属性转换和类的表示详解
- centos php mongodb 驱动,安装 MongoDB PHP 驱动 在CentOS 6.x和遇到的问题
- HDU-1159-Common Subsequence
- H5调起手机端的摄像头
- k8s部署mysql
- nginx访问php文件an error occurred,nginx提示 An error occurred错误问题解决办法
- 微信公众号登录和获得access_token和发送模板消息
- thinkadmin搜索功能/下拉选项
- FTP上传成功之后却查找不到文件
- int和字符串的类型转换
- Linux Debian11 服务器安装与SSH配置
- 学子随感——遇见长郡浏阳(1)
- 格式工厂安装流程记录
- 基于Panabit免费流控系统的安装与部署