TensorFlow learning --- getting started (1) ----- MNIST machine learning,

Source: Internet
Author: User

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 }))

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.