• 大小: 11.36MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-02
  • 语言: Matlab
  • 标签: CNN  matlab  

资源简介

CNN卷积神经网络实现,Matlab仿真,识别手写数字集。

资源截图

代码片段和文件信息

%%%  matlab实现LeNet-5
%%%  作者:xd.wp
%%%  时间:2016.10.14  20:29
%% 程序说明
%          1、池化(pooling)采用平均2*2
%          2、网络结点数说明:
%                           输入层:28*28
%                           第一层:24*24(卷积)*6
%                           第二层:12*12(pooling)*6
%                           第三层:8*8(卷积)*16
%                           第四层:4*4(pooling)*16
%                           第五层:全连接40
%                           第六层:全连接10
%          3、网络训练部分采用800个样本,检验部分采用100个样本
clear all;clc;
%% 网络初始化
layer_c1_num=6;
layer_c2_num=16;
%权值调整步进
yita=0.05;
bias=1;
%卷积核初始化
[kernel_c1kernel_c2]=init_kernel(layer_c1_numlayer_c2_num);
%pooling核初始化
pooling_a=ones(22)/4;
%全连接层的权值
weight_full_1=rand(1640)/sqrt(40);
weight_full_2=rand(4010)/sqrt(10);
weight_c2=rand(616)/10;
weight_arr2num=rand(44layer_c2_num)/sqrt(16);
disp(‘网络初始化完成......‘);
%% 开始网络训练
disp(‘开始网络训练......‘);
for n=10:20
    for m=0:9
        %读取样本
        train_data=imread(strcat(num2str(m)‘_‘num2str(n)‘.bmp‘));
        train_data=double(train_data);
        %         % 归一化
        %         train_data=train_data/sqrt(sum(sum(train_data.^2)));
        %标签label设置
        label_temp=-ones(110);
        label_temp(1m+1)=1;
        label=label_temp;
        for iter=1:10
            %前向传递进入卷积层1
            for k=1:layer_c1_num
                state_c1(::k)=convolution(train_datakernel_c1(::k));
                %进入pooling1
                state_s1(::k)=pooling(state_c1(::k)pooling_a);
            end
            %进入卷积层2
            [state_c2state_c2_temp]=convolution_c2(state_s1kernel_c2weight_c2);
            %进入pooling层2
            for k=1:layer_c2_num
                state_s2_temp1(::k)=pooling(state_c2(::k)pooling_a);
            end
            %将矩阵变成数
            for k=1:layer_c2_num
                state_s2_temp2(1k)=sum(sum(state_s2_temp1(::k).*weight_arr2num(::k)))+bias;
                state_s2(1k)=1/(1+exp(-state_s2_temp2(1k)));
%             state_s2(1k)=sum(sum(state_s2_temp1(::k).*weight_arr2num(::k)));
            end
            %16个特征数,进入全连接层1
            state_f1=state_s2*weight_full_1;
            %进入全连接层2
            state_f2=state_f1*weight_full_2;
            %% 误差计算部分
            Error=state_f2-label;
            Error_Cost=sum(Error.^2);
            if(Error_Cost<1e-4)
                break;
            end
            %% 参数调整部分
            [kernel_c1kernel_c2weight_c2weight_full_1weight_full_2weight_arr2num]=CNN_upweight1(Errortrain_data...
                state_c1state_s1...
                state_c2state_s2_temp1...
                state_s2state_s2_temp2...
                state_f1state_f2...
                kernel_c1kernel_c2...
                weight_c2weight_full_1...
                weight_full_2weight_arr2numyitastate_c2_temp);
            
        end
    end
end
disp(‘网络训练完成,开始检验......‘);
%% 检验部分
count_num=0;
for n=10:15
    for m=0

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-11-30 16:47  CNN_LeNet_test\
     文件        4655  2016-10-21 21:25  CNN_LeNet_test\CNN_LeNet_main.m
     文件        5179  2016-10-17 16:20  CNN_LeNet_test\CNN_upweight.m
     文件        4729  2016-10-18 19:44  CNN_LeNet_test\CNN_upweight1.m
     文件        4478  2016-10-18 12:08  CNN_LeNet_test\CNN_upweight2.m
     文件         298  2016-10-15 16:48  CNN_LeNet_test\convolution.m
     文件         430  2016-10-15 19:49  CNN_LeNet_test\convolution_c2.m
     文件         232  2016-10-21 21:23  CNN_LeNet_test\init_kernel.m
     文件         292  2016-10-15 16:51  CNN_LeNet_test\pooling.m
     目录           0  2018-11-30 16:47  CNN_LeNet_test\test_image\
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_0.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_1.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_10.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_100.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_101.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_102.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_103.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_104.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_105.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_106.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_107.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_108.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_109.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_11.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_110.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_111.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_112.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_113.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_114.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_115.bmp
     文件        1862  2010-05-28 18:22  CNN_LeNet_test\test_image\0_116.bmp
............此处省略9900个文件信息

评论

共有 条评论