This aritcle is a memo about MNIST For ML Beginners to Learn TensorFlow.
๐ฝ Download You can download MNIST data as follows:
from tensorflow.examples.tutorials.mnist import input_datamnist = input_data.read_data_sets("MNIST_data/" , one_hot=True )
๐ฐ Dataset Types
data_sets.train : 55000 images and labels, for primary training.
data_sets.validation : 5000 images and labels, for iterative validation of training accuracy.
data_sets.test : 10000 images and labels, for final testing of trained accuracy.
๐ค Data Point
xs : a handwritten digit : 784(=28x28)
ys : a corresponding label : mnist.train.labels (1 hot vectors)
For example, 3 would be [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
๐ Softmax Regression
First Step : We add up the evidence of our input being in certain classes
Sencond Step: We convert that evidence into probabilities
import tensorflow as tfx = 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)
๐ Training To implement cross-entropy:
y_ = tf.placeholder(tf.float32, [None , 10 ]) cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1 ])) train_step = tf.train.GradientDescentOptimizer(0.5 ).minimize(cross_entropy) init = tf.initialize_all_variables() sess = tf.Session() sess.run(init) 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})
๐ Evaluation 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}))
๐ป Output $ python mnist_beginner.py #=> Extracting MNIST_data/train-images-idx3-ubyte.gz #=> Extracting MNIST_data/train-labels-idx1-ubyte.gz #=> Extracting MNIST_data/t10k-images-idx3-ubyte.gz #=> Extracting MNIST_data/t10k-labels-idx1-ubyte.gz #=> 0.9197
๐ Special Thanks
๐ฝ Sample Code
๐ฏ Japanese Description for TensorFlow MNIST For ML Beginners
๐ฅ Recommended VPS Service
VULTR provides high performance cloud compute environment for you.
Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour).
In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results !!