新聞中心
這篇文章主要介紹“tensorflow mnist模型怎么實現(xiàn)”,在日常操作中,相信很多人在tensorflow mnist模型怎么實現(xiàn)問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”tensorflow mnist模型怎么實現(xiàn)”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比蘄春網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式蘄春網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋蘄春地區(qū)。費用合理售后完善,十多年實體公司更值得信賴。
所有的ML模型或者DL 模型 都是下面這四個固定套路的步驟
1.獲取到所需數(shù)據(jù)
2.開始搭建模型
3.計算采用何種loss函數(shù)
4.選擇batch,epoch,feed數(shù)據(jù)
from tensorflow.examples.tutorials.mnist import input_data import tensorflow as tf mnist = input_data.read_data_sets('./tmp/tensorflow/mnist/input_data',one_hot=True) # 下載數(shù)據(jù) x = tf.placeholder(tf.float32,[None,784]) # 輸入占位符 yresult = tf.placeholder(tf.float32,[None,10]) #輸入數(shù)據(jù)真實的label w = tf.Variable(tf.zeros([784,10])) b = tf.Variable(tf.zeros([10])) y = tf.nn.softmax(tf.matmul(x,w) + b) # 用不用激勵函數(shù) 都可以的其實 cross_entropy = -tf.reduce_sum(yresult * tf.log(y)) # loss 值 train_setp = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) #梯度下降法 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) argv1,loss = sess.run([train_setp,cross_entropy],feed_dict={x:batch_xs,yresult:batch_ys}) #如果想知道corss_entropy試試變化值 加入就好。 if i % 200 == 0: print (loss) current_prediction = tf.equal(tf.argmax(y,1),tf.argmax(yresult,1)) # compare real and calculate accuracy = tf.reduce_mean(tf.cast(current_prediction,tf.float32)) # 數(shù)據(jù)類型轉(zhuǎn)換 然后求匹配上的概率 result = sess.run(accuracy,feed_dict={x:mnist.test.images,yresult:mnist.test.labels}) # test數(shù)據(jù)入口 print(str(result * 100) + '%')
到此,關(guān)于“tensorflow mnist模型怎么實現(xiàn)”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
分享文章:tensorflowmnist模型怎么實現(xiàn)
網(wǎng)頁網(wǎng)址:http://www.dlmjj.cn/article/psjgoe.html