简体   繁体   English

在MatLab中使用LIBSVM进行多类图像分类

[英]Using LIBSVM in MatLab for Multi Class image classification

I'm using LIBSVM within MatLab to try and classify images. 我在MatLab中使用LIBSVM来尝试对图像进行分类。

I understand that SVM is a binary Classification Model, however I'm wondering how I would go about using it as multi-class Classification Model. 我知道SVM是一个二进制分类模型,但是我想知道如何将它用作多类分类模型。

Is it possible to train pairs of data (ie car and non car, horse and non horse, person and non person) and then predict which class an image belongs to by comparing the image to all three models? 是否可以训练成对的数据(即汽车和非汽车,马和非马,人和非人),然后通过将图像与所有三个模型进行比较来预测图像所属的类别? If so, how could I achieve this? 如果是这样,我怎么能实现这个目标? What would my test label vector be? 我的测试标签矢量是什么?

Yes your suggestion is a good approach. 是的,你的建议是一个很好的方法。 It's called the one-vs-all strategy . 它被称为一对一战略

You need to train separate SVMs for each class. 您需要为每个班级训练单独的SVM。 The output data would be a binary variable equal to 1 if is in that class and 0 otherwise. 如果在该类中,则输出数据将是等于1的二进制变量,否则为0。 Then in order to classify a new item, run it through each of your SVMs and choose the one with the highest output (output closest to 1). 然后,为了对新项目进行分类,请在每个SVM中运行它,并选择输出最高的项目(输出最接近1)。

As a supplementary answer of @Dan's, below is the relevant code from my previous post : 作为@ Dan的补充答案,以下是我之前帖子中的相关代码:

model = cell(NumofClass,1);  % NumofClass = 3 in your case
for k = 1:NumofClass
    model{k} = svmtrain(double(trainingLabel==k), trainingData, '-c 1 -g 0.2 -b 1');
end

%% calculate the probability of different labels

pr = zeros(1,NumofClass);
for k = 1:NumofClass
    [~,~,p] = svmpredict(double(testLabel==k), testData, model{k}, '-b 1');
    pr(:,k) = p(:,model{k}.Label==1);    %# probability of class==k
end

%% your label prediction will be the one with highest probability:

[~,predctedLabel] = max(pr,[],2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM