【问题标题】:neural network in MATLAB fails in trainingMATLAB中的神经网络训练失败
【发布时间】:2017-08-18 12:58:39
【问题描述】:

我正在使用 MATLAB 学习神经网络,我正在尝试实现一个使用 PCA 进行特征提取的人脸识别程序,以及一个用于分类的前馈神经网络。

我的训练集中有 3 个人,图像存储在“数据”目录中。

我为每个人使用一个网络,我用我的训练集的所有图像训练每个网络,我的项目的代码如下所示:

dirs = dir('data');
size = numel(dirs);
eigenVecs = [];
% a neural network for each individual
net1 = feedforwardnet(10);
net2 = feedforwardnet(10);
net3 = feedforwardnet(10);

% extract eigen vectors and prepare the input of the NN
for i= 3:size
    eigenVecs{i-2} =  eigenFaces(dirs(i).name);
end
trainSet= cell2mat(eigenVecs'); % 27X1024 double

% set the target for each NN, and then train it.
T = [1 1 1 1 1 1 1 1 1 ...
     0 0 0 0 0 0 0 0 0 ...
     0 0 0 0 0 0 0 0 0];
train(net1, trainSet', T);
T = [0 0 0 0 0 0 0 0 0 ...
     1 1 1 1 1 1 1 1 1 ...
     0 0 0 0 0 0 0 0 0];
train(net2, trainSet', T);
T = [0 0 0 0 0 0 0 0 0 ...
     0 0 0 0 0 0 0 0 0 ...
     1 1 1 1 1 1 1 1 1];
train(net3, trainSet', T);

在完成网络训练后,我得到了这个面板:

nntraintool panel

** 如果有人可以向我解释面板的进度部分,因为我无法理解这些数字的含义。 **

训练网络后,我尝试使用以下方法测试网络:

sim(net1, L)

其中 L 是我的集合中的一个样本,它是一个 1X1024 向量,我得到的结果是这样的:

Empty matrix: 0-by-1024

我训练神经网络的方法错了吗?我该怎么做才能修复这个程序?

谢谢

【问题讨论】:

    标签: matlab neural-network pca face-recognition


    【解决方案1】:

    代码

     train(net1, trainSet', T);
    

    不会将经过训练的网络保存到net1 变量中(它会将其保存到ans 变量中)。这就是sim 的结果为空的原因:net1 中没有经过训练的网络。你必须自己保存训练好的网络:

     net1= train(net1, trainSet', T);
    

    【讨论】:

    猜你喜欢
    • 2010-11-20
    • 1970-01-01
    • 2015-08-13
    • 2012-12-04
    • 2015-10-28
    • 2011-04-07
    • 1970-01-01
    • 2017-08-14
    • 2014-02-24
    相关资源
    最近更新 更多