TensorFlow新手实例源码--mnist源码
2017-11-26 01:24
155 查看
环境:python3.5(今[2017.11.25]实测3.6版本无法安装tensorflow)
以下源码已测试通过,准确率约91%
代码如下:
以下源码已测试通过,准确率约91%
代码如下:
import tensorflow.examples.tutorials.mnist.input_data as input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) import tensorflow as tf x = tf.placeholder(tf.float32, [None, 784]) W = tf.Variable(tf.zeros([784,10])) b = tf.Variable(tf.zeros([10])) y = tf.nn.softmax(tf.matmul(x,W) + b) y_ = tf.placeholder(tf.float32, [None,10]) cross_entropy = -tf.reduce_sum(y_*tf.log(y)) train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) for i in range(1000): batch_xs, batch_ys = mnist.train.next_batch(100) sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys}) correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels})) print(sess.run(W)) print(sess.run(b))
相关文章推荐
- TensorFlow 教程 --新手入门--1.3 安装实例
- TensorFlow 教程 --新手入门--1.4 win10环境安装实例
- BigInteger大整数类——实例和源码(相当经典)
- [jtable]多个源码实例
- TensorFlow (RNN)深度学习 双向LSTM(BiLSTM)+CRF 实现 sequence labeling 序列标注问题 源码下载
- OpenStack建立实例完整过程源码详细分析(3)
- jQuery实现的表头固定效果实例【附完整demo源码下载】
- OpenStack建立实例完整过程源码详细分析(5)
- 适应新手---线上生产环境的PHP源码安装(php-httpd)
- [C#]委托实例分析(附源码)
- PHP通过反射动态加载第三方类和获得类源码的实例
- 接上篇 新手学写music widget(可以显示歌曲名称以及专辑图片) 源码附最后
- TensorFlow源码安装
- 病毒程序源码实例剖析-“主页”病毒[1]
- C# WinForm 判断程序是否已经在运行,且只允许运行一个实例,附源码
- Tensorflow GPU 源码安装configure 配置
- 微信小程序实例源码大全
- Java继承初步实例源码
- 『TensorFlow』SSD源码学习_其四:数据介绍及TFR文件生成
- 『TensorFlow』SSD源码学习_其六:标注格式整理