本文學(xué)習(xí)Neural Networks and Deep Learning 在線免費(fèi)書籍,用python構(gòu)建神經(jīng)網(wǎng)絡(luò)識別手寫體的一個(gè)總結(jié)。

代碼主要包括兩三部分:
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)化為計(jì)算格式"""
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萬個(gè)數(shù)據(jù)分別逐個(gè)取出化成(784,1),逐個(gè)排列
n = [np.reshape(x, (784, 1)) for x in t_d[0]] # 將5萬個(gè)數(shù)據(jù)分別逐個(gè)取出化成(784,1),逐個(gè)排列
# 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萬個(gè)數(shù)據(jù)分別逐個(gè)取出化成(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萬個(gè)數(shù)據(jù)分別逐個(gè)取出化成(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 #浮點(diǎn)計(jì)算
return label
網(wǎng)頁名稱:python構(gòu)建深度神經(jīng)網(wǎng)絡(luò)(DNN)-創(chuàng)新互聯(lián)
網(wǎng)頁URL:http://www.chinadenli.net/article32/desjsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、品牌網(wǎng)站設(shè)計(jì)、品牌網(wǎng)站制作、小程序開發(fā)、云服務(wù)器、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容