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个


温馨提示
MNIST手写字 Matlab程序,包含BP和CNN程序。不依赖任何库,包含MNIST数据,BP网络可达到98.3%的识别率,CNN可达到99%的识别率。CNN比较耗时,关于CNN的程序介绍:https://blog.csdn.net/hoho1151191150/article/details/79714691
资源推荐
资源详情
资源评论






















收起资源包目录




















































共 44 条
- 1
资源评论

- m0_482468662021-06-02能不能教一下具体怎么实现啊铁子,小白看不懂
- 普玻璃窗2020-10-16大佬,能不能说明一下具体怎么用吗?小白一枚真的很头大啊,QQ:1403950407

tiny__boy
- 粉丝: 121
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 单片机智能稳压电源的设计方案.doc
- 山西公务员热点大数据时代个人信息安全危机.doc
- 城乡规划中的测绘地理大数据应用探析.docx
- 中国-东盟网络安全合作与发展研究报告.pdf
- 软件开发模型.docx
- 大数据时代下-公共图书馆读者服务模式的发展研究.docx
- 华东交大软件学院6周软件工程实训总结报告-学号-姓名.doc
- 浅析计算机制图在工程测绘中的应用.docx
- 一.百万公众网络学习工程试题及标准答案(满分100分)docx.docx
- 河北大学MATLAB习题答案.doc
- 企业信息安全规划与技术实现-软件技术.doc
- 电气自动化李存义自动化应用方案设计书.doc
- 医院信息系统建设中虚拟化技术的运用.docx
- 物联网技术节水灌溉控制.doc
- 信息办公平台网络优化设计.docx
- 前端工程师项目实训金牌就业班版(Word).doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
