最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python tensorflow實(shí)現(xiàn)mnist手寫(xiě)數(shù)字識(shí)別示例【非卷積與卷積實(shí)現(xiàn)】

 更新時(shí)間:2019年12月19日 08:40:16   作者:nudt_qxx  
這篇文章主要介紹了Python tensorflow實(shí)現(xiàn)mnist手寫(xiě)數(shù)字識(shí)別,結(jié)合實(shí)例形式分析了基于tensorflow模塊使用非卷積與卷積算法實(shí)現(xiàn)手寫(xiě)數(shù)字識(shí)別的具體操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Python tensorflow實(shí)現(xiàn)mnist手寫(xiě)數(shù)字識(shí)別。分享給大家供大家參考,具體如下:

非卷積實(shí)現(xiàn)

import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
data_path = 'F:\CNN\data\mnist'
mnist_data = input_data.read_data_sets(data_path,one_hot=True) #offline dataset
x_data = tf.placeholder("float32", [None, 784]) # None means we can import any number of images
weight = tf.Variable(tf.ones([784,10]))
bias = tf.Variable(tf.ones([10]))
Y_model = tf.nn.softmax(tf.matmul(x_data ,weight) + bias)
#Y_model = tf.nn.sigmoid(tf.matmul(x_data ,weight) + bias)
'''
weight1 = tf.Variable(tf.ones([784,256]))
bias1 = tf.Variable(tf.ones([256]))
Y_model1 = tf.nn.softmax(tf.matmul(x_data ,weight1) + bias1)
weight1 = tf.Variable(tf.ones([256,10]))
bias1 = tf.Variable(tf.ones([10]))
Y_model = tf.nn.softmax(tf.matmul(Y_model1 ,weight1) + bias1)
'''
y_data = tf.placeholder("float32", [None, 10])
loss = tf.reduce_sum(tf.pow((y_data - Y_model), 2 ))#92%-93%
#loss = tf.reduce_sum(tf.square(y_data - Y_model)) #90%-91%
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init) # reset values to wrong
for i in range(100000):
  batch_xs, batch_ys = mnist_data.train.next_batch(50)
  sess.run(train, feed_dict = {x_data: batch_xs, y_data: batch_ys})
  if i%50==0:
    correct_predict = tf.equal(tf.arg_max(Y_model,1),tf.argmax(y_data,1))
    accurate = tf.reduce_mean(tf.cast(correct_predict,"float"))
    print(sess.run(accurate,feed_dict={x_data:mnist_data.test.images,y_data:mnist_data.test.labels}))

卷積實(shí)現(xiàn)

import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
data_path = 'F:\CNN\data\mnist'
mnist_data = input_data.read_data_sets(data_path,one_hot=True) #offline dataset
x_data = tf.placeholder("float32", [None, 784]) # None means we can import any number of images
x_image = tf.reshape(x_data, [-1,28,28,1])
w_conv = tf.Variable(tf.ones([5,5,1,32])) #weight
b_conv = tf.Variable(tf.ones([32]))    #bias
h_conv = tf.nn.relu(tf.nn.conv2d(x_image , w_conv,strides=[1,1,1,1],padding='SAME')+ b_conv)
h_pool = tf.nn.max_pool(h_conv,ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')
w_fc = tf.Variable(tf.ones([14*14*32,1024]))
b_fc = tf.Variable(tf.ones([1024]))
h_pool_flat = tf.reshape(h_pool,[-1,14*14*32])
h_fc = tf.nn.relu(tf.matmul(h_pool_flat,w_fc) +b_fc)
W_fc = w_fc = tf.Variable(tf.ones([1024,10]))
B_fc = tf.Variable(tf.ones([10]))
Y_model = tf.nn.softmax(tf.matmul(h_fc,W_fc) +B_fc)
y_data = tf.placeholder("float32",[None,10])
loss = -tf.reduce_sum(y_data * tf.log(Y_model))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(loss)
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
for i in range(1000):
  batch_xs,batch_ys =mnist_data.train.next_batch(5)
  sess.run(train_step,feed_dict={x_data:batch_xs,y_data:batch_ys})
  if i%50==0:
    correct_prediction = tf.equal(tf.argmax(Y_model,1),tf.argmax(y_data,1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction,"float"))
    print(sess.run(accuracy,feed_dict={x_data:mnist_data.test.images,y_data:mnist_data.test.labels}))

更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python數(shù)學(xué)運(yùn)算技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • python中的單向鏈表實(shí)現(xiàn)

    python中的單向鏈表實(shí)現(xiàn)

    大家好,本篇文章主要講的是python中的單向鏈表實(shí)現(xiàn),感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下
    2022-01-01
  • python引入其他文件夾下的py文件具體方法

    python引入其他文件夾下的py文件具體方法

    在本篇文章里小編給大家整理的是一篇關(guān)于python引入其他文件夾下的py文件具體方法,有興趣朋友們可以跟著學(xué)習(xí)參考下。
    2021-05-05
  • 用python爬蟲(chóng)爬取CSDN博主信息

    用python爬蟲(chóng)爬取CSDN博主信息

    這篇文章主要介紹了如何用python爬蟲(chóng)獲取CSDN博主信息的方法,原理和代碼寫(xiě)的非常詳細(xì),對(duì)大家學(xué)習(xí)Python爬取很有用處,有需要的朋友可以和小編一起看一下
    2021-04-04
  • Python中的min及返回最小值索引的操作

    Python中的min及返回最小值索引的操作

    這篇文章主要介紹了Python中的min及返回最小值索引的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-05-05
  • Python實(shí)現(xiàn)切割mp3片段并降低碼率

    Python實(shí)現(xiàn)切割mp3片段并降低碼率

    MoviePy是一個(gè)基于Python的視頻編輯庫(kù),它提供了創(chuàng)建、編輯、合并、剪輯和轉(zhuǎn)換視頻的功能,所以本文主要介紹如何使用moviepy來(lái)分割音頻流并降低碼率,感興趣的可以了解下
    2023-08-08
  • python爬蟲(chóng)破解字體加密案例詳解

    python爬蟲(chóng)破解字體加密案例詳解

    這篇文章主要介紹了python爬蟲(chóng)破解字體加密案例詳解,本文通過(guò)圖文實(shí)例相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • pytorch網(wǎng)絡(luò)模型構(gòu)建場(chǎng)景的問(wèn)題介紹

    pytorch網(wǎng)絡(luò)模型構(gòu)建場(chǎng)景的問(wèn)題介紹

    這篇文章主要介紹了pytorch網(wǎng)絡(luò)模型構(gòu)建場(chǎng)景的注意點(diǎn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧
    2023-03-03
  • python @property的用法及含義全面解析

    python @property的用法及含義全面解析

    下面小編就為大家分享一篇python @property的用法及含義全面解析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • 詳解python中TCP協(xié)議中的粘包問(wèn)題

    詳解python中TCP協(xié)議中的粘包問(wèn)題

    這篇文章主要介紹了python中TCP協(xié)議中的粘包問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • 關(guān)于Pycharm無(wú)法debug問(wèn)題的總結(jié)

    關(guān)于Pycharm無(wú)法debug問(wèn)題的總結(jié)

    今天小編就為大家分享一篇關(guān)于Pycharm無(wú)法debug問(wèn)題的總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-01-01

最新評(píng)論

瑞昌市| 萍乡市| 英超| 宜川县| 鹤庆县| 虞城县| 祁门县| 始兴县| 昆明市| 子长县| 哈巴河县| 无极县| 长丰县| 甘肃省| 深水埗区| 商河县| 水富县| 怀安县| 宝兴县| 义乌市| 金昌市| 高密市| 澳门| 辉县市| 同心县| 汝阳县| 全椒县| 高清| 三门峡市| 乌兰县| 荔浦县| 应城市| 景洪市| 扎鲁特旗| 乐山市| 新竹县| 衡水市| 彰武县| 梁山县| 喀什市| 陆河县|