0

I have been working on training pedestrian detection classifier based on HOG features. Presently I have done the followings:

a) Extracted HOG features of all files i.e. Positive and Negative and saved those features with label i.e. +1 for positive and -1 for negative in file.

b)downloaded svmlight, extracted binaries i.e. svm_learn, svm_classify.

c) passed the "training file" (features file) to svm_learn binary which produced a model file for me.

d) passed "test file" to svm_classify binary and got result in predictions file.

Now my question is that "What to do next and how?". i think i know that now i need to use that "model file" and not "predictions file" in openCV for detection of pedestrian in video but somewhere i read that openCV uses only 1 support vector but i got 295 SV, so how do i convert it into one proper format and use it and any further compulsory steps if any.

I do appreciate your kindness!

Lahori
  • 1,071
  • 11
  • 20

1 Answers1

2

It is not true that OpenCV (presumably you are talking about CvSVM) uses only one support vector. As pointed out by QED, what OpenCV does do is to optimize a linear SVM down to one support vector. I think the idea here is that the support vectors define the classification margin, but to do the actual classification only the separating hyperplane is needed and that can be defined with one vector.

Since you have a svmlight model file, and CvSVM can't read that, you have the following options:

  1. train a CvSVM and save the mode as a CvStatsModel file, that you can load tha tlater to get the support vecotrs.
  2. write some code to convert an svmlight model file into a CvStatsModel file (but for this you have to understand both formats).
  3. get source for svmlight, the bit that reaads the modelfile, and integrate it into your OpenCV application
  4. You may use LIBSVM instead, but really you are then faced with the same problems as svmlight.

For ideas on how to convert the support vectors so you can use them with the HOG detector see Training custom SVM to use with HOGDescriptor in OpenCV

Community
  • 1
  • 1
Bull
  • 11,771
  • 9
  • 42
  • 53
  • I have been trying to opt the 3rd suggestion of yours but was un-scuccessful that's why i asked of any simpler, out of the opencv but within C++ related procedure but thanks for your suggestion. At the moment i am compelled to shift to libsvm software. What is your suggestion: would it be nice, too? – Lahori Aug 02 '14 at 04:27
  • I have used LIBSVM a lot, it is good. And svm_predict is fairly easy to wrap for OpenCV. – Bull Aug 02 '14 at 05:45
  • Ok! I am reading this post (http://stackoverflow.com/questions/19089256/convert-libsvm-output-to-vector-of-floats) and what i understand till now is to upload my model file (this model is from libsvm). what should be the next step after it. i mean "Should i directly use this file in DetectMultiScale?" – Lahori Aug 02 '14 at 06:50
  • be very careful that you set all the exact same perameters that you used to create the features, and also that svmlight has put the bias into the last slot of the model vector of weights. Now if you can get a vector from that file that has all the learned weights + the bias, then you can call the hogdesc. setSVMDetector(const vector& detector) function with the vector as arg. If you get assert errors, then most prob. the bias is not at the end, or you have set different hog params. – QED Aug 02 '14 at 19:48
  • @B... if you use the linear kernel in opencv it has some special magic function that converts all the support vectors to just one support vector. It caught me out before as i thought it was a bug to have one support vector. https://github.com/Itseez/opencv/blob/master/modules/ml/src/svm.cpp line 1579 : void CvSVM::optimize_linear_svm() // we optimize only linear SVM: compress all the support vectors into one. – QED Aug 02 '14 at 20:01
  • @B... The Hog detector never calls the CSvm predict function, it performs dot product directly (or with ipp) as it was coded prior to the CSvm. So if orig. poster took option 1. they would then have to extract the weight vector from the CSvm, which is not implemented. http://stackoverflow.com/questions/15033363/obtaining-weights-in-cvsvm-the-svm-implementation-of-opencv – QED Aug 02 '14 at 20:05