如何提高Matlab中神经网络的OCR准确率

时间:2016-06-02 18:46:40

标签: matlab neural-network ocr feature-extraction glcm

我正在研究OCR的阿拉伯字符。我想尝试glcm作为一种特征提取方法。我在这里得到了代码:http://www.mathworks.com/matlabcentral/fileexchange/22187-glcm-texture-features

输入图像(字符图像)的示例:

enter image description here enter image description here enter image description here

我已经制作了一个代码来根据所需的功能获取GLCM输出。这是:

function features = EkstraksiFitur_GLCM(x)
    glcm = graycomatrix(x,'offset',[0 1; -1 1; -1 0; -1 -1], 'NumLevels', 2); 

    stats = GLCM_Features1(glcm, 0);
    autocorrelation = double(mean (stats.autoc));
    if isnan(autocorrelation)
        autocorrelation=0;
    else
        autocorrelation=autocorrelation;
    end

    contrast = double(mean(stats.contr));
    if isnan(contrast)
        contrast=0;
    else
        contrast=contrast;
    end

    Correlation = double(mean (stats.corrm));
    if isnan(Correlation)
        Correlation=0;
    else
        Correlation=Correlation;
    end

    ClusterProminence = double(mean (stats.cprom));
    if isnan(ClusterProminence)
        ClusterProminence=0;
    else
        ClusterProminence=ClusterProminence;
    end

    ClusterShade = double(mean (stats.cshad));
    if isnan(ClusterShade)
        ClusterShade=0;
    else
        ClusterShade=ClusterShade;
    end

    Dissimilarity = double(mean (stats.dissi));
    if isnan(Dissimilarity)
        Dissimilarity=0;
    else
        Dissimilarity=Dissimilarity;
    end

    Energy = double(mean (stats.energ));
    if isnan(Energy)
        Energy=0;
    else
        Energy=Energy;
    end
    . 
    .
    .
    features=[autocorrelation, contrast, Correlation, Dissimilarity, Energy, Entropy, Homogeneity, MaximumProbability, SumAverage, SumVariance, SumEntropy, DifferenceVariance, DifferenceEntropy, InverseDifferenceMomentNormalized];

使用循环获取所有图像的特征(数据系列):

srcFile = dir('D:\1. Thesis FINISH!!!\Data set\0 Well Segmented Character\Advertising Bold 24\datatrain\*.png');
fetrain = [];
for a = 1:length(srcFile)
    file_name = strcat('D:\1. Thesis FINISH!!!\Data set\0 Well Segmented Character\Advertising Bold 24\datatrain\',srcFile(b).name);
    A = imread(file_name);
    [gl] = EkstraksiFitur_GLCM2 (A);
    [fiturtrain] = reshape (gl, [56,1]) ;
    fetrain = [fetrain fiturtrain];
%   vectorname = strcat(file_name,'_array.mat');

end
 save ('fetrain.mat','fetrain');

我有这些功能。

enter image description here

然后使用神经网络运行训练过程,但我的准确率非常低。这是代码:

% clc;clear;close all;
% function net1 = pelatihan (input, target)
net = newff(fetrain,target,[10 2],{'tansig','tansig'},'trainscg');
% net.trainParam.mem_reduc = 2;
net.performFcn = 'mse'; 
net.divideFcn = 'dividetrain';
% [trainInd,valInd,testInd] = dividetrain(601);
net.trainParam.show = 10; % Frequency of progress displays (in epochs).
net.trainParam.epochs = 1000; %default 1000
net.trainParam.goal = 1e-6;
net = train(net,fetrain,target);
output = round(sim(net,fetrain));
save net1.mat net
% net2 = output;
data = fetest;

[target; output];
prediksi = round(sim (net, data));
[targetx; prediksi];

%% Calculate the accuracy %
y = 1;
j = size (prediksi, 2); 
% x = size (targetx, 2);
for i = 1:j 
    if prediksi (i) == targetx (i)
       y =y+1;
    else
        y;
    end 
end 
% y all correct data
% j all data
s = 'The accuracy is %.2f%%';
acc = 100 *(y/j);
sprintf (s,acc)

我已经尝试了几次,但准确率(NN测试结果)没有改善。它可以提供1.96%的输出。流程流程或我编写的代码是否有问题?

任何帮助都会非常有帮助和赞赏

1 个答案:

答案 0 :(得分:1)

首先,我可以从您提取的特征中看到它们没有被标准化,并且它们的范围不同。这意味着一些胎儿会占据其余部分。尝试规范化或标准化功能。您仅在训练集上测量的准确度,或者您是一些测试集或交叉验证方法?我看到你使用601功能是真的吗?您是否尝试使用功能选择方法来确定哪些功能更适合数据和模型?

其次,我想知道你为结构实现了什么,而不是阅读完整的代码来理解你所做的。

第三个是查看输入图像以了解您正在处理的enviremoent。