您当前的位置: 首页 >  算法
  • 0浏览

    0关注

    2393博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

TF:利用是Softmax回归+GD算法实现MNIST手写数字图片识别(10000张图片测试得到的准确率为92%)

一个处女座的程序猿 发布时间:2018-09-20 10:58:20 ,浏览量:0

TF:利用是Softmax回归+GD算法实现MNIST手写数字图片识别(10000张图片测试得到的准确率为92%)

 

目录

设计思路

全部代码

 

 

 

设计思路

 

全部代码
#TF:利用是Softmax回归+GD算法实现手写数字识别(10000张图片测试得到的准确率为92%)
#思路:对输入的图像,计算它属于每个类别的概率,找出最大概率即为预测值
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data  


mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)#读入MNIST数据


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_mean(-tf.reduce_sum(y_ * tf.log(y)))                
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)  


sess = tf.InteractiveSession() 
tf.global_variables_initializer().run() 
print('start training...')


for _ 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, tf.float32)) 


print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))  # 0.9185

 

 

相关文章

TF:利用是Softmax回归+GD算法实现MNIST手写数字识别(10000张图片测试得到的准确率为92%)

关注
打赏
1664196048
查看更多评论
立即登录/注册

微信扫码登录

0.0436s