简体   繁体   中英

Using LIBSVM in MatLab for Multi Class image classification

I'm using LIBSVM within MatLab to try and classify images.

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.

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. The output data would be a binary variable equal to 1 if is in that class and 0 otherwise. 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).

As a supplementary answer of @Dan's, below is the relevant code from my previous post :

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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