Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize tensorflow mnist Model

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to realize the tensorflow mnist model". In the daily operation, I believe many people have doubts about how to realize the tensorflow mnist model. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to realize the tensorflow mnist model". Next, please follow the editor to study!

All ML or DL models are the steps of the following four fixed routines

1. Get the data you need

two。 Start building a model.

3. Which loss function is used to calculate?

4. Select batch,epoch,feed data

From tensorflow.examples.tutorials.mnist import input_dataimport tensorflow as tfmnist = input_data.read_data_sets ('. / tmp/tensorflow/mnist/input_data',one_hot=True) # download data x = tf.placeholder (tf.float32, [None,784]) # input placeholder yresult = tf.placeholder (tf.float32, [None] 10]) # input data real labelw = tf.Variable (tf.zeros ([784Jing 10])) b = tf.Variable (tf.zeros ([10])) y = tf.nn.softmax (tf.matmul (x) W) + b) # you don't need an excitation function. In fact, cross_entropy =-tf.reduce_sum (yresult * tf.log (y)) # loss value train_setp = tf.train.GradientDescentOptimizer. Minimize (cross_entropy) # gradient descent method init = tf.initialize_all_variables () with tf.Session () as sess: sess.run (init) for i in range (1000): batch_xs Batch_ys = mnist.train.next_batch (100,100) argv1,loss = sess.run ([train_setp,cross_entropy], feed_dict= {x _ train_setp,cross_entropy _ batchhands _ If I% 200 = 0: print (loss) current_prediction = tf.equal (tf.argmax (YPower1), tf.argmax (yresult,1)) # compare real and calculate accuracy = tf.reduce_mean (tf.cast (current_prediction,tf.float32)) # data type conversion and then find the probability on the match result = sess.run (accuracy,feed_dict= {x:mnist.test.images) Yresult:mnist.test.labels}) # test data entry print (str (result * 100) +'%') here The study on "how to implement the tensorflow mnist model" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report