【字母识别】基于matlab BP神经网络手写字母识别(单一)【源码9期】

一、简介

基于matlab BP神经网络手写字母识别(单一),BP神经网络Back Propagation Neural Network,简称BPNN)是一种广泛应用于模式识别和机器学习领域的重要工具。其基本原理是通过反向传播算法对神经网络中的权重进行调整,以达到最小化网络输出与实际目标之间的误差。在手写字母识别中,BP神经网络展现出了其强大的特征学习和分类能力。本文旨在探讨BP神经网络在手写字母识别中的应用,并通过实践来验证其效果。

二、部分源码

clc; clear all; close all;
warning off all;
% 获取字符集
fd = fullfile(pwd, 'images', 'dbx');
fds = dir(fd);
ts = [];
for i = 1 : length(fds)
    if isequal(fds(i).name, '.') || isequal(fds(i).name, '..')
        continue;
    end
    ts{end+1} = fds(i).name;
end
files = GetAllFiles(fd);
% 提取字符集合的特征向量
db_file = fullfile(pwd, 'VL.mat');
if exist(db_file, 'file')
    load(db_file);
else
    VT = [];
    LT = [];
    for i = 1 : length(files)
        im = imread(files{i});
        [~, v] = get_feature(im);
        % 特征
        VT = [VT v];
        [pn, ~, ~] = fileparts(files{i});
        [~, nm, ~] = fileparts(pn);
        for j = 1 : length(ts)
            if isequal(ts{j}, nm)
                % 标签
                LT = [LT j];
                break;
            end
        end
    end
    save(db_file, 'VT', 'LT');
end
% BP训练
net_file = fullfile(pwd, 'bp_net.mat');
if exist(net_file, 'file')
    load(net_file);
else
    p_train=VT;
    t_train=LT;
    [pn,minp,maxp,tn,mint,maxt] = premnmx(p_train, t_train);
    threshold=minmax(pn);
    net=newff(threshold,[30,20,10,1],{'tansig','tansig','tansig','purelin'},'trainlm');
    net.trainParam.epochs=10000;
    net.trainParam.goal=1e-5;
    net.trainParam.show=50;
    net.trainParam.lr=0.01;
    net=train(net,pn,tn);
    % 存储网络
    save(net_file, 'net', 'minp', 'maxp', 'mint', 'maxt');
end
%% 评测
p2n = tramnmx(VT,minp, maxp);
y2n = sim(net, p2n);
% 数据的反归一化,预测结果
y2n = postmnmx(y2n,mint,maxt);
% 比对
T = [LT; round(y2n)];
acc = (sum(T(1, :)-T(2, :) == 0)/numel(T(1, :)))*100;
fprintf('\n准确率为%.2f%%\n', acc);

三、运行结果

四、matlab版本

MATLAB R2019a

五、学习与交流

文中不足之处请大家多多指教,学习与交流可以联系企鹅:3752243968
文中部分源码仅供参考,若需要全部代码可以私信(有偿)

  • 21
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值