MNIST手写数字识别【Matlab神经网络工具箱】

30 篇文章 3 订阅
29 篇文章 31 订阅

MNIST手写数字识别

Matlab代码:

%Neural Networks Codes will be run on this part
tic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
pic1=imread('8.png');
pic1=rgb2gray(pic1);
% pic=255-pic;
[a,b]=size(pic1);
for i=1:1:a
    for j=1:1:b   
        if  pic1(i,j)==0    
            up=i;           
            break       
        end
    end
end
for i=a:-1:1
    for j=1:1:b       
        if  pic1(i,j)==0            
            down=i;
            break
        end        
    end
end
for j=1:1:b
    for i=1:1:a       
        if  pic1(i,j)==0            
            left=j;
            break
        end        
    end
end
for j=b:-1:1
    for i=1:1:a       
        if  pic1(i,j)==0            
            right=j;
            break
        end        
    end
end
pic=pic1(down:up,right:left);
imshow(pic)
pic=imresize(pic,[28 28]);
% size(pic);
pic1=1-double(reshape(pic,784,1))/255;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%加载待识别图像
image = loadMNISTImages('train-images'); % 加载样本图像共60000,size(image)=784*60000
label = loadMNISTLabels('train-labels');%加载样本图像对应标签
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label1=zeros(60000,10);
j=0;
for i=1:1:60000  
    j=label(i)+1;
    label1(i,j)=1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%=训练样本
PR=minmax(image);
bpnet=newff(PR,[30 10],{'tansig', 'tansig'}, 'traingd', 'learngdm');
net.epoch=100;
net.trainParam.epochs=10;%允许最大训练步数
net.trainParam.goal=0.001; %训练目标最小误差0.001
net.trainParam.show=1; %每间隔100步显示一次训练结果
net.trainParam.lr=0.01; %学习速率
bpnet=train(bpnet,image,label1');
bpnet=sim(bpnet,pic1);
shuzi=find(bpnet==max(bpnet))-1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
toc

利用自己在写字板上写的字测试:

如果不会下载MNIST 数据,可以访问:我的GitHub:

https://github.com/WeisongZhao/MNIST_Recognization

里面有不使用MATLAB工具箱的源代码

评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值