python构建深度神经网络(DNN)

该博客介绍了通过阅读《Neural Networks and Deep Learning》在线书籍,使用Python构建神经网络进行手写体识别的过程。内容涵盖数据调用与预处理、神经网络类的构建和测试代码的编写,最终实现并测试了深度学习模型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文学习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 = [vectors(y) for y in t_d[1]] # 将5万标签(50000,1)化
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值