中文字幕理论片,69视频免费在线观看,亚洲成人app,国产1级毛片,刘涛最大尺度戏视频,欧美亚洲美女视频,2021韩国美女仙女屋vip视频

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
TF之NN:利用DNN算法(SGD+softmax+cross_entropy)對(duì)mnist手寫數(shù)字圖片識(shí)別訓(xùn)練集(TF自帶函數(shù)下載)實(shí)現(xiàn)87.4%識(shí)別

TF之NN:利用DNN算法(SGD+softmax+cross_entropy)對(duì)mnist手寫數(shù)字圖片識(shí)別訓(xùn)練集(TF自帶函數(shù)下載)實(shí)現(xiàn)87.4%識(shí)別


輸出結(jié)果

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

import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data

print ("packs loaded")
print ("Download and Extract MNIST dataset")
mnist = input_data.read_data_sets('/tmp/data/', one_hot=True)
print
print (" tpye of 'mnist' is %s" % (type(mnist)))
print (" number of trian data is %d" % (mnist.train.num_examples))
print (" number of test data is %d" % (mnist.test.num_examples))


packs loaded
Download and Extract MNIST dataset
tpye of 'mnist' is <class 'tensorflow.contrib.learn.python.learn.datasets.base.Datasets'>
number of trian data is 55000
number of test data is 10000
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data #這是TensorFlow 為了教學(xué)Mnist而提前設(shè)計(jì)好的程序
# number 1 to 10 data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True) #TensorFlow 會(huì)檢測(cè)數(shù)據(jù)是否存在。當(dāng)數(shù)據(jù)不存在時(shí),系統(tǒng)會(huì)自動(dòng)將數(shù)據(jù)下載到MNIST_data/文件夾中。當(dāng)執(zhí)行完語句后,讀者可以自行前往MNIST_data/文件夾下查看上述4 個(gè)文件是否已經(jīng)被正確地下載

def add_layer(inputs, in_size, out_size, activation_function=None,):
    # add one more layer and return the output of this layer
    Weights = tf.Variable(tf.random_normal([in_size, out_size]))
    biases = tf.Variable(tf.zeros([1, out_size]) + 0.1,)
    Wx_plus_b = tf.matmul(inputs, Weights) + biases
    if activation_function is None:
        outputs = Wx_plus_b
    else:
        outputs = activation_function(Wx_plus_b,)
    return outputs

def compute_accuracy(v_xs, v_ys):      global prediction              
    y_pre = sess.run(prediction, feed_dict={xs: v_xs}) 
    correct_prediction = tf.equal(tf.argmax(y_pre,1), tf.argmax(v_ys,1)) 
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))   
    result = sess.run(accuracy, feed_dict={xs: v_xs, ys: v_ys})         
    return result

# define placeholder for inputs to network
xs = tf.placeholder(tf.float32, [None, 784]) 
ys = tf.placeholder(tf.float32, [None, 10]) 

# add output layer
prediction = add_layer(xs, 784, 10,  activation_function=tf.nn.softmax)

# the error between prediction and real data
cross_entropy = tf.reduce_mean(-tf.reduce_sum(ys * tf.log(prediction),
                                              reduction_indices=[1]))      
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy) 
sess = tf.Session()
# important step
sess.run(tf.global_variables_initializer())

for i in range(1000):
    batch_xs, batch_ys = mnist.train.next_batch(100)  
    sess.run(train_step, feed_dict={xs: batch_xs, ys: batch_ys})
    if i % 50 == 0:
        print(compute_accuracy(
            mnist.test.images, mnist.test.labels))

相關(guān)文章
TF之NN:(TF自帶函數(shù)下載MNIST55000訓(xùn)練集圖片)實(shí)現(xiàn)手寫數(shù)字識(shí)別87.4%準(zhǔn)確率識(shí)別:SGD法+softmax法+cross_entropy法

相關(guān)文章
TF之NN:(TF自帶函數(shù)下載MNIST55000訓(xùn)練集圖片)實(shí)現(xiàn)手寫數(shù)字識(shí)別87.4%準(zhǔn)確率識(shí)別:SGD法+softmax法+cross_entropy法
TF之DNN:(TF自帶函數(shù)下載MNIST55000訓(xùn)練集圖片)利用 784 個(gè)神經(jīng)元的三層全連接的DNN對(duì)MNIST手寫數(shù)字識(shí)別實(shí)現(xiàn)98%準(zhǔn)確率

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
教程|沒有博士學(xué)位,照樣玩轉(zhuǎn)TensorFlow深度學(xué)習(xí)
《煉數(shù)成金》.第七課 遞歸神經(jīng)網(wǎng)絡(luò)LSTM的講解,以及LSTM網(wǎng)絡(luò)的使用學(xué)習(xí)筆記
5.8 莫煩 Python RNN LSTM 循環(huán)神經(jīng)網(wǎng)絡(luò) (分類例子)
Tensorflow的采樣方法:candidate sampling(zhuan)
TensorFlow四種Cross Entropy算法實(shí)現(xiàn)和應(yīng)用
TensorFlow 深度學(xué)習(xí)損失函數(shù)tf.nn.softmax_cross_entropy_with_logits
更多類似文章 >>
生活服務(wù)
熱點(diǎn)新聞
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服