tensorflow构建手写数字图像识别---softmax算法
2017-10-11 21:40
495 查看
tensorflow构建手写数字图像识别—softmax算法,摘自tensorflow中文社区
正确率91%
import input_data import tensorflow as tf mnist=input_data.read_data_sets("MNIST_data/", one_hot=True) #添加x作为占位符 x=tf.placeholder("float", [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("float", [None,10]) #定义计算交叉熵公式 cross_entropy=-tf.reduce_sum(y_*tf.log(y)) #定义训练方式,梯度下降,目标让交叉熵减少 train_step=tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) #初始化变量 init=tf.initialize_all_variables() sess=tf.Session() sess.run(init #循环训练1000次,每次取100个数据,run train_step方法,用batch_xs, batch_ys填充占位符 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}) #tf.argmax(y,1):取出y数组中为1的序号,对比正确的计算准确率 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}))
正确率91%
相关文章推荐
- tensorflow1.1/构建卷积神经网络识别手写数字
- tensorflow构建RNN识别mnist手写数字
- [TensorFlow实战] 构建LeNet实现手写数字识别
- 通过摄像头捕获图像用tensorflow做手写数字识别
- TensorFlow代码实现(一)[MNIST手写数字识别]
- tensorflow 入门小例子(mnist手写数字识别)
- TensorFlow笔记之一:MNIST手写数字识别
- TensorFlow笔记(一)---Softmax Regression识别手写数字
- TensorFlow学习笔记之源码分析(2)----手写数字识别mnist example
- TensorFlow学习_02_CNN卷积神经网络_Mnist手写数字识别
- Python(TensorFlow框架)实现手写数字识别系统
- TensorFlow 卷积神经网络之MNIST 手写数字识别
- tensorflow入门2 几个函数的总结和手写数字识别
- python Tensorflow三层全连接神经网络实现手写数字识别
- python实现识别手写数字 python图像识别算法
- TensorFlow学习(2):非线性回归和简单的MNIST手写数字识别
- 新手上手Tensorflow之手写数字识别应用(2)
- Tensorflow - Tutorial (2) : 利用softmax回归进行手写数字识别
- tensorflow实战(一)TensorFlow实现 softmax Regression 识别手写数字
- TensorFlow下进行MNIST手写数字识别实例,从最简单的两层到LeNet5