用TensorFlow實現(xiàn)MNIST
原文鏈接:http://tecdat.cn/?p=5681
?

這里,我們用TensorFlow實現(xiàn)一個3層,即輸入層、隱藏層、輸出層的神經(jīng)網(wǎng)絡(luò)。
引入相關(guān)模塊 # tensorflow 自帶mnist模塊
from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets(".", one_hot=True, reshape=False)import tensorflow as tf
這里有個one_hot=True,one_hot表示獨熱編碼,可以看下面的圖片理解意思:

?
one hot encoding
參數(shù)設(shè)置
learning_rate = 0.001training_epochs = 20batch_size = 128display_step = 1# 設(shè)置日志顯示次數(shù)用的n_input = 784# 輸入的大小n_classes = 10# 最后分成10個類別
learning rate是學(xué)習(xí)的速度,每次更新參數(shù)時的步長(速度),太小會造成學(xué)習(xí)速度太慢,太大會造成無法擬合的結(jié)果。
一個 epoch是指整個數(shù)據(jù)集正向反向訓(xùn)練一次。
batch size 是一次拿多少數(shù)據(jù)去訓(xùn)練,具體可以參考What is a batch in TensorFlow? - Stack Overflow。
定義模型

?
?
訓(xùn)練結(jié)果

?
▍需要幫助?聯(lián)系我們
標(biāo)簽: