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

tensorflow使用神經(jīng)網(wǎng)絡實現(xiàn)mnist分類

 更新時間:2018年09月08日 12:01:20   作者:Missayaa  
這篇文章主要為大家詳細介紹了tensorflow使用神經(jīng)網(wǎng)絡實現(xiàn)mnist分類,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了tensorflow神經(jīng)網(wǎng)絡實現(xiàn)mnist分類的具體代碼,供大家參考,具體內(nèi)容如下

只有兩層的神經(jīng)網(wǎng)絡,直接上代碼

#引入包
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
#引入input_data文件
from tensorflow.examples.tutorials.mnist import input_data
#讀取文件
mnist = input_data.read_data_sets('F:/mnist/data/',one_hot=True)

#定義第一個隱藏層和第二個隱藏層,輸入層輸出層
n_hidden_1 = 256
n_hidden_2 = 128
n_input = 784
n_classes = 10

#由于不知道輸入圖片個數(shù),所以用placeholder
x = tf.placeholder("float",[None,n_input])
y = tf.placeholder("float",[None,n_classes])

stddev = 0.1

#定義權重
weights = {
    'w1':tf.Variable(tf.random_normal([n_input,n_hidden_1],stddev = stddev)),
    'w2':tf.Variable(tf.random_normal([n_hidden_1,n_hidden_2],stddev=stddev)),
    'out':tf.Variable(tf.random_normal([n_hidden_2,n_classes],stddev=stddev))    
    }

#定義偏置
biases = {
    'b1':tf.Variable(tf.random_normal([n_hidden_1])),
    'b2':tf.Variable(tf.random_normal([n_hidden_2])),
    'out':tf.Variable(tf.random_normal([n_classes])), 
    }
print("Network is Ready")


#前向傳播
def multilayer_perceptrin(_X,_weights,_biases):
  layer1 = tf.nn.sigmoid(tf.add(tf.matmul(_X,_weights['w1']),_biases['b1']))
  layer2 = tf.nn.sigmoid(tf.add(tf.matmul(layer1,_weights['w2']),_biases['b2']))
  return (tf.matmul(layer2,_weights['out'])+_biases['out'])

#定義優(yōu)化函數(shù),精準度等
pred = multilayer_perceptrin(x,weights,biases)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits = pred,labels=y))
optm = tf.train.GradientDescentOptimizer(learning_rate = 0.001).minimize(cost)
corr = tf.equal(tf.argmax(pred,1),tf.argmax(y,1))
accr = tf.reduce_mean(tf.cast(corr,"float"))
print("Functions is ready")

#定義超參數(shù)
training_epochs = 80
batch_size = 200
display_step = 4

#會話開始
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)

#優(yōu)化
for epoch in range(training_epochs):
  avg_cost=0.
  total_batch = int(mnist.train.num_examples/batch_size)

  for i in range(total_batch):
    batch_xs,batch_ys = mnist.train.next_batch(batch_size)
    feeds = {x:batch_xs,y:batch_ys}
    sess.run(optm,feed_dict = feeds)
    avg_cost += sess.run(cost,feed_dict=feeds)
  avg_cost = avg_cost/total_batch

  if (epoch+1) % display_step ==0:
    print("Epoch:%03d/%03d cost:%.9f"%(epoch,training_epochs,avg_cost))
    feeds = {x:batch_xs,y:batch_ys}
    train_acc = sess.run(accr,feed_dict = feeds)
    print("Train accuracy:%.3f"%(train_acc))
    feeds = {x:mnist.test.images,y:mnist.test.labels}
    test_acc = sess.run(accr,feed_dict = feeds)
    print("Test accuracy:%.3f"%(test_acc))
print("Optimization Finished")

程序部分運行結(jié)果如下:

Train accuracy:0.605
Test accuracy:0.633
Epoch:071/080 cost:1.810029302
Train accuracy:0.600
Test accuracy:0.645
Epoch:075/080 cost:1.761531130
Train accuracy:0.690
Test accuracy:0.649
Epoch:079/080 cost:1.711757494
Train accuracy:0.640
Test accuracy:0.660
Optimization Finished

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 利用Python批量處理多個txt文本的示例代碼

    利用Python批量處理多個txt文本的示例代碼

    這篇文章主要給大家介紹了關于如何利用Python批量處理多個txt文本的方法,文中通過實例代碼介紹的非常詳細,對大家的學習或工作有一定的幫助,需要的朋友可以參考下
    2023-10-10
  • python執(zhí)行精確的小數(shù)計算方法

    python執(zhí)行精確的小數(shù)計算方法

    今天小編就為大家分享一篇python執(zhí)行精確的小數(shù)計算方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-01-01
  • python實現(xiàn)批量nii文件轉(zhuǎn)換為png圖像

    python實現(xiàn)批量nii文件轉(zhuǎn)換為png圖像

    這篇文章主要介紹了python實現(xiàn)批量nii文件轉(zhuǎn)換為png圖像,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-07-07
  • 如何在python中實現(xiàn)capl語言里的回調(diào)函數(shù)(推薦)

    如何在python中實現(xiàn)capl語言里的回調(diào)函數(shù)(推薦)

    CAPL是一種程序語言,其中程序塊的執(zhí)行由事件控制,主要介紹了如何在python中實現(xiàn)capl語言里的回調(diào)函數(shù)及事件函數(shù)的作用,需要的朋友可以參考下
    2022-08-08
  • 利用Python實現(xiàn)批量裁剪圖片

    利用Python實現(xiàn)批量裁剪圖片

    這篇文章主要為大家詳細介紹了如何基于Python如何批量裁剪圖片并保存,文中的示例代碼講解詳細,具有一定的參考價值,有需要的小伙伴可以了解一下
    2023-10-10
  • python中round函數(shù)如何使用

    python中round函數(shù)如何使用

    在本篇文章里小編給大家整理了關于python的round函數(shù)用法總結(jié)內(nèi)容,需要的朋友們可以學習下。
    2020-06-06
  • Python中判斷input()輸入的數(shù)據(jù)的類型

    Python中判斷input()輸入的數(shù)據(jù)的類型

    在pyhton中,經(jīng)常會用到input()語句,但是input()語句輸入的內(nèi)容只能是字符串類型,而我們經(jīng)常要輸入int類型的數(shù)據(jù)等,這個時候就需要用到int()方法給輸入的內(nèi)容強制轉(zhuǎn)換,今天小編給大家介紹下Python中判斷input()輸入的數(shù)據(jù)的類型,感興趣的朋友跟隨小編一起看看吧
    2022-11-11
  • Python第三方模塊apscheduler安裝和基本使用

    Python第三方模塊apscheduler安裝和基本使用

    本文主要介紹了Python第三方模塊apscheduler安裝和基本使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-03-03
  • Python + Flask 實現(xiàn)簡單的驗證碼系統(tǒng)

    Python + Flask 實現(xiàn)簡單的驗證碼系統(tǒng)

    這篇文章主要介紹了Python + Flask 制作一個簡單的驗證碼系統(tǒng),本文圖文并茂給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-10-10
  • 淺談Selenium+Webdriver 常用的元素定位方式

    淺談Selenium+Webdriver 常用的元素定位方式

    這篇文章主要介紹了淺談Selenium+Webdriver 常用的元素定位方式,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-01-01

最新評論

萍乡市| 木兰县| 泸定县| 汽车| 平舆县| 蒙自县| 福鼎市| 贵德县| 塔河县| 嵩明县| 和平县| 南城县| 教育| 凤翔县| 翁牛特旗| 南开区| 马鞍山市| 勐海县| 广安市| 曲松县| 安龙县| 沾益县| 五原县| 广南县| 沽源县| 江孜县| 津市市| 鸡东县| 蒲江县| 乡城县| 天津市| 桓台县| 读书| 将乐县| 磴口县| 叶城县| 乐至县| 敦煌市| 漠河县| 琼结县| 靖江市|