In this article, I will introduce MNIST data set and review the process of training the MINIST data set to get the model by using TensorFlow.
MNIST Data Set
This database is a large database of handwritten digits that is commonly used for training various image processing systems. This database contains 60,000 training images (mnist.train) and 10,000 testing images (mnist.test)
28x28 pixels in one image, we can use 28x28 = 784 dimensions vector to present this matrix.
Mnist.train.xs represents 60000 training images.
Mnist.train.ys represents the label of the 60000 image. There’re 10 labels from 0 to 9. Each label is the real number shown in each image.
Methodology : Softmax Regression
We use softmax regression to classify each type of writing.
1. The model of the learning
2. Cost function
3. Training Algorithm
Use Gradient Descent algorithm, which is backpropagation algorithm.
The backpropagation algorithm looks for the minimum of the error function in weight space using the method of gradient descent.
Using TensorFlow
Step 1:
Initialize & start the model
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
Step 2:
Training the model (Optimize the weights)
for i in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100) // Stochastic training: Randomly use 100 data to train the model.
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
And the train_step is:
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
Step 3:
Evaluate the model
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) //y_ is the correct label
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) // The accuracy of the model
print sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}) // Print out the accuracy