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 178 下载量 134 浏览量
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
- 粉丝: 120
- 资源: 221
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 前端常用布局模板39套,纯CSS实现布局
- 课程资源整理,黑马程序员JavaWeb开发教程,实现javaweb企业开发全流程
- 数据集-目标检测系列- 笔 钢笔 检测数据集 pen >> DataBall
- ANSYS命令流(APDL)源代码:简支梁桥梁的建立(beam4、beam188的形变及自振频率)(耦合&弹簧连接梁墩)
- 学习threejs,使用第一视角控制器FirstPersonControls控制相机,city模型
- 2022-2023全国分省GDP数据.zip
- 数据集-目标检测系列- 圣诞帽 冬天帽子 检测数据集 hat >> DataBall
- 数据集-目标检测系列- 短裤 检测数据集 shorts >> DataBall
- 基于原子STM32F407板编写程序
- Spring Boot MySQL 分库分表
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功