本文介绍了如何标记PCA获得的用于训练SVM的训练预测进行分类?的MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组图像训练集".我已经形成了本征空间".现在,我需要标记投影以训练SVM. 面1"到本征空间的投影必须标记为+1,所有其他面到本征空间的投影必须标记为-1.

I have a "training set" of images. I have formed the 'Eigenspace'. Now i need to label the projections to train the SVM. The projections of "face 1" to the Eigenspace has to be labelled +1 and the projections of all the other faces to the Eigenspace has to be labelled -1.

我不知道该怎么做.任何建议都会很有帮助!

I don't know how to do this.Any suggestions would be really helpful!

我使用以下方法形成了本征空间:

I formed the eigenspace using the following :

    function [signals,V] = pca2(data)
    [M,N] = size(data);
    data = reshape(data, M*N,1); % subtract off the mean for each dimension
    mn = mean(data,2);
    data = bsxfun(@minus, data, mean(data,1));
    % construct the matrix Y
    Y = data'*data / (M*N-1);
    [V D] = eigs(Y, 10); % reduce to 10 dimension
    % project the original data
    signals = data * V;

推荐答案

如果您试图识别一个以上的人,则必须为每个人创建一个单独的数据文件,并分别创建一个文件每个人的SVM.这是因为SVM专注于两类分离.

If you are trying to recognize more than one person, you have to create one separate data file for each person, and one sepparate SVM for each person. This is because SVM are focused on two-class separation.

这是将libsvm用于Matlab的示例(此处是完整的代码),假设您将数据保存在文件中:

This is an example using libsvm for Matlab (here is the full code), supposing you have the data in a file:

[person1_label, person1_inst] = libsvmread('../person1');
[person2_label, person2_inst] = libsvmread('../person2');
[person3_label, person3_inst] = libsvmread('../person3');

model1 = svmtrain(person1_label, person1_inst, '-c 1 -g 0.07 -b 1');
model2 = svmtrain(person2_label, person2_inst, '-c 1 -g 0.07 -b 1');
model3 = svmtrain(person3_label, person3_inst, '-c 1 -g 0.07 -b 1');

要测试一张脸,您需要应用所有模型并获得最大输出(使用svmpredict时,必须使用'-b 1'来获得概率估计.

To test one face, you need to apply all the models and get the max output (when using svmpredict you have to use '-b 1' to obtain the probability estimates.

此外,在Matlab中,您无需使用svmreadsvmwrite,您可以直接传递数据:

Additionally, in Matlab you don't need to use svmread or svmwrite, you can pass directly the data:

training_data = [];%Your matrix that contains 4 feature vectors
person1_label =[1,1,-1,-1];
person2_label = [-1,-1,1,-1];
person3_label = [-1,-1,-1,1];

model1 = svmtrain(person1_label, person_inst, '-c 1 -g 0.07 -b 1');
model2 = svmtrain(person2_label, person_inst, '-c 1 -g 0.07 -b 1');
model3 = svmtrain(person3_label, person_inst, '-c 1 -g 0.07 -b 1');

这篇关于如何标记PCA获得的用于训练SVM的训练预测进行分类?的MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 23:04