วันพุธที่ 8 ธันวาคม พ.ศ. 2553

First Success in HOG descriptor training

My own trained detector using Dalal HOG method.

detection time = 873.865ms

Opencv2.1 has peopledetect.cpp that come with Dalal default detector. It does not provide the details how the detector can be trained.

In this blog, I present the training method I have done so far. The result is shown in the left.

My request toward reader: I still do not know how the Det graph and performance measurement can be implemented. Any help will be appreciated.

Theory: Dalal and Trig HOG must be computed first. After that, we use the SVM to classify the people/no people. With the fault positive,  retrain the system once again.

Result: SVM
Accuracy on test set: 98.90% (14447 correct, 161 incorrect, 14608 total)

Precision/recall on test set: 99.04%/94.25%

Implement: Opencv with the HOGDescriptor::compute, one can compute the HOG of the given image. Requirement is to train the SVM with Train/negative, Train/Positive image set. After that,  test the SVM model with the Test/negative. Any detection is therefore, fault positive. Retrain the fault positive with the training set again.

The trained SVM model is a file containing support vectors. With the support vectors, one can use them to predict people/non-people classification. Opencv, However, use only one vector to detect people.
This vector is the weight vector as shown in picture above as w.

Start implement:
1. Using the INRIA person dataset ,
- INRIAPerson/96X160H96/Train/pos
- INRIAPerson/Train/neg
- INRIAPerson/Test/neg
for positive train test set.
2. Prepare the 64x128 images for those picture. For negative image, it is required that the 64x128 randomly cropped from the original image.

3. HogCompute parameter. We will compute the HOG using Opencv HOGDescriptor::compute with the following default parameters.
blockSize =(16,16) blockStride =(8,8) CellSize =(8,8) derivAperture bool =0 gammaCorrection bool=0 histogramNormType =0if = 0 means L2Hys L2HysTheshold =0.2 nbins =9
winSigma =-1 winSize =(64,128)

4. SVM learn, and classifier. SVMLight is used. Using libsvm/tools/checkdata.py to make sure that the input file to SVM is correctly formated.

5. Compute HOG, train the SVM, test the negative test set with the trained model, put the fault positive to retrain again. (its called hard train)

6. Compute the weight vector of the hard train and use it as  vector<float> getDefaultPeopleDetector()  the trig is we need to put the theshold value from the model added into the last vector position.

7. At detectMultiScale function, change the threshold values,group threshold and hit threshold until u get good result.  

Discussion: Manually change the threshold value does not seems to be "computer vision" it is human vision. How can I auto change the threshold value and get good result?

Download: Here I created a project to host all above training. License: Its for free to everything.

5 ความคิดเห็น:

  1. Hello,
    I'm trying to train CvHOGDetector and have found your post. Thank you very much for your work.

    I download "hogtrainingtuto" archive. It looks like in that archive there are many different hog-training tutorials and project. Could you please tell me, what does each folder mean ? (cvCropSrc, cvModifiedPeopleDetect, cvSamplePeopleDetect, libsvm-3.0, svm_light). What files should I compile and link to get executable for hog-training ?

    Am I rigth, that I should do this way:
    1. Compile svm_light folder to get svm_learn.exe file (I work on Windows)
    2. Compile cvModifiedPeopleDetect\peopledetect.cpp to get peopledetect.exe
    3. Run peopledetect.exe to get HOG Features set for my Training pos\neg sets
    4. Feed these sets to svm_learn.exe and compute weight vector by using weightVector.pl file ?

    Thank you

    ตอบลบ
  2. Hi, I have used SVM in opencv. And also able to compute HOG descriptor. Can you please tell me the part in which we have to give this HOG descriptors to svm. And also there is setSVMDetector method in HOG class. Can you tell me how to use it. Thanks,

    ตอบลบ
  3. Hi, can you please tell me how to train your SVM for License Plate recognition ?

    ตอบลบ