MATLAB 中的神经网络训练失败

neural network in MATLAB fails in training

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

我的训练集中有3个人,图像存储在'data'目录中。

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

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

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

谢谢

代码

 train(net1, trainSet', T);

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

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