本文學(xué)習(xí)Neural Networks and Deep Learning 在線免費書籍,用python構(gòu)建神經(jīng)網(wǎng)絡(luò)識別手寫體的一個總結(jié)。
東昌府網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)2013年開創(chuàng)至今到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。代碼主要包括兩三部分:
1)、數(shù)據(jù)調(diào)用和預(yù)處理
2)、神經(jīng)網(wǎng)絡(luò)類構(gòu)建和方法建立
3)、代碼測試文件
1)數(shù)據(jù)調(diào)用:
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2017-03-12 15:11 # @Author : CC # @File : net_load_data.py # @Software: PyCharm Community Edition from numpy import * import numpy as np import cPickle def load_data(): """載入解壓后的數(shù)據(jù),并讀取""" with open('data/mnist_pkl/mnist.pkl','rb') as f: try: train_data,validation_data,test_data = cPickle.load(f) print " the file open sucessfully" # print train_data[0].shape #(50000,784) # print train_data[1].shape #(50000,) return (train_data,validation_data,test_data) except EOFError: print 'the file open error' return None def data_transform(): """將數(shù)據(jù)轉(zhuǎn)化為計算格式""" t_d,va_d,te_d = load_data() # print t_d[0].shape # (50000,784) # print te_d[0].shape # (10000,784) # print va_d[0].shape # (10000,784) # n1 = [np.reshape(x,784,1) for x in t_d[0]] # 將5萬個數(shù)據(jù)分別逐個取出化成(784,1),逐個排列 n = [np.reshape(x, (784, 1)) for x in t_d[0]] # 將5萬個數(shù)據(jù)分別逐個取出化成(784,1),逐個排列 # print 'n1',n1[0].shape # print 'n',n[0].shape m = [vectors(y) for y in t_d[1]] # 將5萬標(biāo)簽(50000,1)化為(10,50000) train_data = zip(n,m) # 將數(shù)據(jù)與標(biāo)簽打包成元組形式 n = [np.reshape(x, (784, 1)) for x in va_d[0]] # 將5萬個數(shù)據(jù)分別逐個取出化成(784,1),排列 validation_data = zip(n,va_d[1]) # 沒有將標(biāo)簽數(shù)據(jù)矢量化 n = [np.reshape(x, (784, 1)) for x in te_d[0]] # 將5萬個數(shù)據(jù)分別逐個取出化成(784,1),排列 test_data = zip(n, te_d[1]) # 沒有將標(biāo)簽數(shù)據(jù)矢量化 # print train_data[0][0].shape #(784,) # print "len(train_data[0])",len(train_data[0]) #2 # print "len(train_data[100])",len(train_data[100]) #2 # print "len(train_data[0][0])", len(train_data[0][0]) #784 # print "train_data[0][0].shape", train_data[0][0].shape #(784,1) # print "len(train_data)", len(train_data) #50000 # print train_data[0][1].shape #(10,1) # print test_data[0][1] # 7 return (train_data,validation_data,test_data) def vectors(y): """賦予標(biāo)簽""" label = np.zeros((10,1)) label[y] = 1.0 #浮點計算 return label