赞
踩
本文学习Neural Networks and Deep Learning 在线免费书籍(http://neuralnetworksanddeeplearning.com/index.html),用python构建神经网络识别手写体的一个总结。
代码主要包括两三部分:
1) 数据调用和预处理
2) 神经网络类构建和方法建立
3) 代码测试文件
1) 数据调用:
- #!/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():
- """载入解压后的数据,并读取"""
- 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():
- """将数据转化为计算格式"""
- 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万个数据分别逐个取出化成(784,1),逐个排列
- n = [np.reshape(x, (784, 1)) for x in t_d[0]] # 将5万个数据分别逐个取出化成(784,1),逐个排列
- # print 'n1',n1[0].shape
- # print 'n',n[0].shape
- m =
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。