python搭建简易神经网络结构

本节使用python环境,在不使用深度学习工具箱情况下搭建一个简单的神经网络结构(非CNN卷积网络)来训练mnist手写体数据库。

网络的结构可以很简单,比如就是([784,200,100,10]),输入维度为784是一个样本大小的28*28,网络包含dropout操作,更多的是理解这种最基础的反向传播机制的实现过程。

完整的项目点击github主页获取

下面看下可运行的包含训练测试的代码:

# -*- coding: utf-8 -*-
"""
@author: chen

"""
import numpy as np
import struct
from datetime import datetime
import matplotlib.pyplot as plt

#读取图像
def read_image(filename):
    binfile = open(filename , 'rb')
    buf = binfile.read()

    index = 0
    magic, numImages , numRows , numColumns = struct.unpack_from('>IIII' , buf , index)
    index += struct.calcsize('>IIII')

    data = np.zeros((numImages,numRows*numColumns))
    for i in range(numImages): 
        im = struct.unpack_from('>784B' ,buf, index)
        index += struct.calcsize('>784B')

        im = np.array(im)
        data[i,:] = im
    return data

#读取图像label
def read_label(filename):
    binfile = open(filename , 'rb')
    buf = binfile.read()

    index = 0
    magic, numLabels = struct.unpack_from('>II' , buf , index)
    index += struct.calcsize('>II')

    data = np.zeros((numLabels,10))
    for i in range(numLabels): 
        label = struct.unpack_from('>B' ,buf, index)[0]

        label = np.array(label)
        data[i,label] = 1

        index += struct.calcsize('>B')
    return data

# 建立与初始化网络参数    
class nn_setup():
    def __init__(self,net,learningRate = 2, epochs = 100, batch = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值