import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
# 载入数据集
mnist = input_data.read_data_sets("MNIST_data", one_hot=True) # 批次大小
batch_size = 64
# 计算一个周期一共有多少个批次
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'):
# 创建一个简单的神经网络:784-10
with tf.name_scope('weights'):
W = tf.Variable(tf.truncated_normal([784,10], stddev=0.1))
with tf.name_scope('biases'):
b = tf.Variable(tf.zeros([10]) + 0.1)
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.losses.mean_squared_error(y, prediction)
with tf.name_scope('train'):
# 使用梯度下降法
train = tf.train.GradientDescentOptimizer(0.3).minimize(loss) with tf.name_scope('accuracy'):
with tf.name_scope('correct_prediction'):
# 结果存放在一个布尔型列表中
correct_prediction = tf.equal(tf.argmax(y,1),tf.argmax(prediction,1))
with tf.name_scope('accuracy'):
# 求准确率
accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32)) with tf.Session() as sess:
# 变量初始化
sess.run(tf.global_variables_initializer())
writer = tf.summary.FileWriter('logs/',sess.graph)
# # 周期epoch:所有数据训练一次,就是一个周期
# for epoch in range(21):
# for batch in range(n_batch):
# # 获取一个批次的数据和标签
# batch_xs,batch_ys = mnist.train.next_batch(batch_size)
# sess.run(train,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))

11.tensorboard网络结构的更多相关文章

  1. tensorboard网络结构

    一.tensorboard网络结构 import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data ...

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

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

  3. Tensorflow目录

    0.Tensorflow安装 1.创建会话,启动会话 2.变量 3.Fech_feed 4.线性回归 5.非线性回归 6.MNIST数据集简单分类 7.交叉熵 8.Dropout 9.正则化 10.优 ...

  4. 【智能家居篇】wifi网络结构(上)

    转载请注明出处:http://blog.csdn.net/Righthek 谢谢! WIFI是什么.相信大家都知道,这里就不作说明了. 我们须要做的是深入了解其工作原理,包含软硬件.网络结构等.先说明 ...

  5. tensorflow学习框架(炼数成金网络版学习记录)

    chapter1 #变量 import tensorflow as tf x = tf.Variable([1,2]) a = tf.constant([3,3]) #增加一个减法op sub = t ...

  6. #Deep Learning回顾#之LeNet、AlexNet、GoogLeNet、VGG、ResNet

    CNN的发展史 上一篇回顾讲的是2006年Hinton他们的Science Paper,当时提到,2006年虽然Deep Learning的概念被提出来了,但是学术界的大家还是表示不服.当时有流传的段 ...

  7. LeNet,AlexNet,GoogleLeNet,VggNet等网络对比

    CNN的发展史 上一篇回顾讲的是2006年Hinton他们的Science Paper,当时提到,2006年虽然Deep Learning的概念被提出来了,但是学术界的大家还是表示不服.当时有流传的段 ...

  8. deep learning 经典网络模型之Alexnet、VGG、Googlenet、Resnet

    CNN的发展史 上一篇回顾讲的是2006年Hinton他们的Science Paper,当时提到,2006年虽然Deep Learning的概念被提出来了,但是学术界的大家还是表示不服.当时有流传的段 ...

  9. 反向传播(Back Propagation)

    反向传播(Back Propagation) 通常在设计好一个神经网络后,参数的数量可能会达到百万级别.而我们利用梯度下降去跟新参数的过程如(1).但是在计算百万级别的参数时,需要一种有效计算梯度的方 ...

随机推荐

  1. VMware虚拟机桥接方式与真实主机共享上网

    原始出处 .http://meiling.blog.51cto.com/6220221/1367695 一.先介绍一下VMware网络设置的三种方式: VMWare提供了三种工作模式,host-onl ...

  2. 20190926 - macOS 下查看进程路径

    首先,从 Activity Monitor 中查看进程 PID,然后使用以下命令查看. ps xuwww -p PID 另一个办法是,使用系统调用 proc_pidpath . #include &l ...

  3. Windows WSL 安装OpenCV

    安装WSL 启动WSL功能 首先启动WSL功能,下面提供两个办法 Powershell --> 管理员权限 --> 运行 Enable-WindowsOptionalFeature -On ...

  4. 【POJ - 3685】Matrix(二分)

    Matrix Descriptions 有一个N阶方阵 第i行,j列的值Aij =i2 + 100000 × i + j2 - 100000 × j + i × j,需要找出这个方阵的第M小值. In ...

  5. Leetcode之动态规划(DP)专题-309. 最佳买卖股票时机含冷冻期(Best Time to Buy and Sell Stock with Cooldown)

    Leetcode之动态规划(DP)专题-309. 最佳买卖股票时机含冷冻期(Best Time to Buy and Sell Stock with Cooldown) 股票问题: 121. 买卖股票 ...

  6. Hbase和Hadoop的内存参数调优 + 前端控制台

    1.hadoop的内存配置调优 mapred-site.xml的内存调整 <property> <name>mapreduce.map.memory.mb</name&g ...

  7. octave

    1. octave, 如何求一元二次方程的解: 例如:· -3x-9y=18  ·   4x+3y=12 命令: >>>  A=[-3 -9; 4 3]; B=[18;12]; &g ...

  8. Linux安装redis logstash

    一.安装redis tar -zxvf redis-3.2.8.tar.gz cd redis-3.2.8 make  && make install PREFIX=/usr/loca ...

  9. memcached命令行、Memcached数据导出和导入

    1.memcached命令行 telnet 127.0.0.1 11211set key2 0 30 2abSTOREDget key2VALUE key2 0 2abEND  如: set key3 ...

  10. quartus ii 粗略使用教程

    重复刚刚做过的下载程序,不选sof文件,选择jic文件 选择program config然后点击start,观察开发板,断电在开启后仍然有效果,想要擦除开发板flash文件,可以点击取消program ...