function cnn = cnn_initialize(cnn)
%CNN_INIT initialize the weights and biases, and other parameters
%
index = 0;
num_layer = numel(cnn.layer);
for in = 1:num_layer
switch cnn.layer{in}{1}
case 'input'
index = index + 1;
height = cnn.layer{in}{3}(1);
width = cnn.layer{in}{3}(2);
mini_size = cnn.layer{in}{2};
cnn.weights{index} = [];
cnn.biases{index} = [];
cnn.nabla_w{index} = [];
cnn.nabla_b{index} = [];
%n*n*m
cnn.a{index} = [];
cnn.z{index} = [];
cnn.delta{index} = [];
cnn.mini_size = mini_size;
case 'conv'
index = index + 1;
%kernel height, width, number
ker_height = cnn.layer{in}{3}(1);
ker_width = cnn.layer{in}{3}(2);
ker_num = cnn.layer{in}{2};
cnn.weights{index} = grand(ker_height,ker_width,ker_num) - 0.5;
cnn.biases{index} = grand(1,ker_num) - 0.5;
cnn.nabla_w{index} = zeros(ker_height,ker_width,ker_num);
cnn.nabla_b{index} = zeros(1,ker_num);
height = height - ker_height + 1;
width = width - ker_width + 1;
cnn.a{index} = zeros(height,width,mini_size,ker_num);
cnn.z{index} = zeros(height,width,mini_size,ker_num);
cnn.delta{index} = zeros(height,width,mini_size,ker_num);
case 'pool'
index = index + 1;
%kernel height, width, number
ker_height = cnn.layer{in}{3}(1);
ker_width = cnn.layer{in}{3}(2);
cnn.weights{index} = [];
cnn.biases{index} = [];
cnn.nabla_w{index} = [];
cnn.nabla_b{index} = [];
height = height / ker_height;
width = width / ker_width;
cnn.a{index} = zeros(height,width,mini_size,ker_num);
cnn.z{index} = [];
cnn.delta{index} = zeros(height,width,mini_size,ker_num);
case 'flat'
index = index + 1;
cnn.weights{index} = [];
cnn.biases{index} = [];
cnn.nabla_w{index} = [];
cnn.nabla_b{index} = [];
cnn.a{index} = zeros(height*width*ker_num,mini_size);
cnn.z{index} = [];
cnn.delta{index} = zeros(height*width*ker_num,mini_size);
case 'full'
index = index + 1;
%kernel height, width, number
neuron_num = cnn.layer{in}{2};
neuron_num0 = size(cnn.a{in-1},1);
cnn.weights{index} = grand(neuron_num,neuron_num0) - 0.5;
cnn.biases{index} = grand(neuron_num,1) - 0.5;
cnn.nabla_w{index} = zeros(neuron_num,neuron_num0);
cnn.nabla_b{index} = zeros(neuron_num,1);
cnn.a{index} = zeros(neuron_num,mini_size);
cnn.z{index} = zeros(neuron_num,mini_size);
cnn.delta{index} = zeros(neuron_num,mini_size);
case 'output'
index = index + 1;
%kernel height, width, number
neuron_num = cnn.layer{in}{2};
neuron_num0 = size(cnn.a{in-1},1);
cnn.weights{index} = grand(neuron_num,neuron_num0) - 0.5;
cnn.biases{index} = grand(neuron_num,1);
cnn.nabla_w{index} = zeros(neuron_num,neuron_num0);
cnn.nabla_b{index} = zeros(neuron_num,1);
cnn.a{index} = zeros(neuron_num,mini_size);
cnn.z{index} = zeros(neuron_num,mini_size);
cnn.delta{index} = zeros(neuron_num,mini_size);
otherwise
end
end
end
没有合适的资源?快使用搜索试试~ 我知道了~
MNIST手写字体识别(CNN+BP两种实现)-Matlab程序
共44个文件
m:37个
png:6个
mat:1个
5星 · 超过95%的资源 需积分: 43 179 下载量 148 浏览量
2020-02-27
12:46:46
上传
评论 48
收藏 21.23MB RAR 举报
温馨提示
MNIST手写字 Matlab程序,包含BP和CNN程序。不依赖任何库,包含MNIST数据,BP网络可达到98.3%的识别率,CNN可达到99%的识别率。CNN比较耗时,关于CNN的程序介绍:https://blog.csdn.net/hoho1151191150/article/details/79714691
资源推荐
资源详情
资源评论
收起资源包目录
MNIST手写字体识别-Matlab程序(CNN+BP实现).rar (44个子文件)
MNIST手写字体识别-Matlab程序(CNN+BP实现)
cnn
run.m 1KB
cnn_backpropagation2.m 3KB
readme.m 75B
sigmoid_prime.m 95B
showdigit.m 400B
gzeros.m 165B
relu_prime.m 119B
cnn_evaluate.m 445B
cnn_backpropagation.m 3KB
cnn_kron.m 297B
sigmoid.m 72B
relu.m 81B
softmax.m 189B
copyToGPU.m 142B
grand.m 165B
cnn_initialize.m 4KB
gones.m 159B
loadMnistDataScript.m 252B
grandn.m 168B
cnn_feedforward.m 1KB
showWeights.m 1KB
fig
cnn
cnnresult.png 22KB
bp
relu-z2-m100-p5000-30-30.png 13KB
a100-100-m-100-me-50000-e-1-l-5.png 62KB
a80-80-m-100-me-50000-e-1-l-5.png 27KB
a120-120-m-100-me-50000-e-1-l-5.png 27KB
relu-z2-m100-p5000.png 13KB
bp
bp_feedforward.m 475B
readme.m 601B
networksmnist.m 1KB
networksmnist3.m 2KB
acti_relu_prime.m 124B
showdigit.m 400B
SGD.m 644B
evaluatemnist.m 425B
bp_backpropagation.m 812B
softmax.m 188B
networksmnist2.m 2KB
acti_sigmoid.m 77B
loadMnistDataScript.m 255B
acti_sigmoid_prime.m 105B
feedforward.m 476B
acti_relu.m 86B
data
mnist.mat 22.12MB
共 44 条
- 1
资源评论
- m0_482468662021-06-02能不能教一下具体怎么实现啊铁子,小白看不懂
- 普玻璃窗2020-10-16大佬,能不能说明一下具体怎么用吗?小白一枚真的很头大啊,QQ:1403950407
tiny__boy
- 粉丝: 121
- 资源: 221
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 形状分类31-YOLO(v5至v11)、COCO、CreateML、Darknet、Paligemma、VOC数据集合集.rar
- 常见排序算法概述及其性能比较
- 前端开发中的JS快速排序算法原理及实现方法
- 基于Java的环境保护与宣传网站论文.doc
- 基于8086的电子琴程序Proteus仿真
- 基于java的二手车交易网站的设计和实现论文.doc
- 纯真IP库,用于ip查询地址使用的数据库文件
- 基于javaweb的动漫网站管理系统毕业设计论文.doc
- 废物垃圾检测28-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- 探索CSDN博客数据:使用Python爬虫技术
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功