TF:利用是Softmax回归+GD算法实现MNIST手写数字图片识别(10000张图片测试得到的准确率为92%)
生活随笔
收集整理的這篇文章主要介紹了
TF:利用是Softmax回归+GD算法实现MNIST手写数字图片识别(10000张图片测试得到的准确率为92%)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
TF:利用是Softmax回歸+GD算法實現(xiàn)MNIST手寫數(shù)字圖片識別(10000張圖片測試得到的準確率為92%)
?
目錄
設(shè)計思路
全部代碼
?
?
?
設(shè)計思路
?
全部代碼
#TF:利用是Softmax回歸+GD算法實現(xiàn)手寫數(shù)字識別(10000張圖片測試得到的準確率為92%) #思路:對輸入的圖像,計算它屬于每個類別的概率,找出最大概率即為預(yù)測值 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)#讀入MNIST數(shù)據(jù)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?
?
相關(guān)文章
TF:利用是Softmax回歸+GD算法實現(xiàn)MNIST手寫數(shù)字識別(10000張圖片測試得到的準確率為92%)
總結(jié)
以上是生活随笔為你收集整理的TF:利用是Softmax回归+GD算法实现MNIST手写数字图片识别(10000张图片测试得到的准确率为92%)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Algorithm之PrA:PrA之nL
- 下一篇: TF:基于CNN(2+1)实现MNIST