日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

TF之LoR:基于tensorflow利用逻辑回归算LoR法实现手写数字图片识别提高准确率

發(fā)布時(shí)間:2025/3/21 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TF之LoR:基于tensorflow利用逻辑回归算LoR法实现手写数字图片识别提高准确率 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

TF之LoR:基于tensorflow利用邏輯回歸算LoR法實(shí)現(xiàn)手寫數(shù)字圖片識(shí)別提高準(zhǔn)確率

?

?

目錄

輸出結(jié)果

設(shè)計(jì)代碼


?

?

?

?

輸出結(jié)果

?

設(shè)計(jì)代碼

#TF之LoR:基于tensorflow實(shí)現(xiàn)手寫數(shù)字圖片識(shí)別準(zhǔn)確率import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import numpy as np import matplotlib.pyplot as plt mnist = input_data.read_data_sets('MNIST_data', one_hot=True) print(mnist)#設(shè)置超參數(shù) lr=0.001 #學(xué)習(xí)率 training_iters=100 #訓(xùn)練次數(shù) batch_size=100 #每輪訓(xùn)練數(shù)據(jù)的大小,如果一次訓(xùn)練5000張圖片,電腦會(huì)卡死,分批次訓(xùn)練會(huì)更好 display_step=1#tf Graph的輸入 x=tf.placeholder(tf.float32, [None,784]) y=tf.placeholder(tf.float32, [None, 10])#設(shè)置權(quán)重和偏置 w =tf.Variable(tf.zeros([784,10])) b =tf.Variable(tf.zeros([10]))#設(shè)定運(yùn)行模式 pred =tf.nn.softmax(tf.matmul(x,w)+b) # #設(shè)置cost function為cross entropy cost =tf.reduce_mean(-tf.reduce_sum(y*tf.log(pred),reduction_indices=1)) #GD算法 optimizer=tf.train.GradientDescentOptimizer(lr).minimize(cost) #初始化權(quán)重 init=tf.global_variables_initializer() #開始訓(xùn)練 with tf.Session() as sess: sess.run(init)avg_cost_list=[]for epoch in range(training_iters): #輸入所有訓(xùn)練數(shù)據(jù)avg_cost=0.total_batch=int(mnist.train.num_examples/batch_size)for i in range(total_batch): #遍歷每個(gè)batch ……if (epoch+1) % display_step ==0: #顯示每次迭代日志print("迭代次數(shù)Epoch:","%04d" % (epoch+1),"下降值cost=","{:.9f}".format(avg_cost))avg_cost_list.append(avg_cost)print("Optimizer Finished!")print(avg_cost_list)#測(cè)試模型correct_prediction=tf.equal(tf.argmax(pred,1),tf.argmax(y,1))accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))print("Accuracy:",accuracy.eval({x:mnist.test.images[:3000],y:mnist.test.labels[:3000]}))xdata=np.linspace(0,training_iters,num=len(avg_cost_list)) plt.figure() plt.plot(xdata,avg_cost_list,'r')plt.xlabel('訓(xùn)練輪數(shù)')plt.ylabel('損失函數(shù)')plt.title('TF之LiR:基于tensorflow實(shí)現(xiàn)手寫數(shù)字圖片識(shí)別準(zhǔn)確率——Jason Niu') plt.show()

?

?

總結(jié)

以上是生活随笔為你收集整理的TF之LoR:基于tensorflow利用逻辑回归算LoR法实现手写数字图片识别提高准确率的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。