TensorFlow learning --- getting started (1) ----- MNIST machine learning,
References: http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html
Data: http://wiki.jikexueyuan.com/project/tensorflow-zh/tutorials/mnist_download.html
Environment: windows + Python3.5 + tensorflow
Python code
From tensorflow. examples. tutorials. mnist import input_data # load training data MNIST_data_folder = r "D: \ WorkSpace \ tensorFlow \ data" mnist = input_data.read_data_sets (MNIST_data_folder, one_hot = True) # print (mnist. train. next_batch (1) import tensorflow as tf # create an abstract model 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]) # defines the loss function and Training Method cross_entropy =-tf. reduce_sum (y _ * tf. log (y) # The loss function is cross entropy train_step = tf. train. gradientDescentOptimizer (0.01 ). minimize (cross_entropy) # gradient descent method, with a learning rate of 0.01 # training objective: to minimize the loss function 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}) correct_prediction = tf. equal (tf. argmax (y, 1), tf. argmax (y _, 1) accuracy = tf. performance_mean (tf. cast (correct_prediction, "float") print (sess. run (accuracy, feed_dict = {x: mnist. test. images, y _: mnist. test. labels }))