GilLevi
GilLevi

Reputation: 2137

Training a Haar cascade took very little time

I trained a new haar cascade using 2000 cropped face images (that contains just the face) and 3321 negative random images.

I used the command:

opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.999  maxFalseAlarmRate 0.5 -numPos 2000 -numNeg 3321 -w 80 -h 40 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024

I'm worried as training elapsed only 34 minutes. The results are also not very good.

Should I use more samples? Is it normal to take only 30 minutes to train a classifier using the above parameters? Should I change them to get better results?

I'm working on windows8 with OpenCV 2.4.7. I working on a relatively strong machine with 8GN of RAM.

Thanks in advance,

Gil.

Upvotes: 3

Views: 5496

Answers (2)

Sole Zender
Sole Zender

Reputation: 56

I'm probably late with my answer. But for the sake of others I'll post it anyway;

First, I'm astonished that the training took so little time. Especially since your samples are very large. 80x40 is really HUGE! Myself I usually train with samples around 20 pixels for the largest dimension. In your case 22x11 would be fine. With increasing sample size the training time increases almost square-wise.

Next, 2000 positives should work quite well. That is, if they are not too much alike. It's better to have samples with as big a difference as you would want to detect in action. Remove samples that are very much alike. They have a negative impact on the quality of the detector.

Then, 3000 negatives is a bit on the low side. Around 6000 negatives gives me good results. But there again, it's better to have negatives that are very different. It's also better to have negatives with a lot of detail. Pictures of a bright blue sky won't work very well. If you can't get that many negatives easily, you can also present rotated versions of the ones you have.

Finally, the more I think of it, the more I'm convinced that you did something wrong. 20 stages for 2000 samples of 80x40 in just 34 minutes?? No way! Do you really have all 2000 positives in that vector file?

Regards and good luck!

Upvotes: 4

Dima
Dima

Reputation: 39389

Check if you actually got a 20-stage cascade. If you got fewer stages than expected, check if that is because you ran out of positive samples. Generally, you should not use all of your positive samples for each stage. Depending on what your hit rate is, you may reject some of the positive samples at each stage, which need to be replenished for training the next stage. So you want your numPos be less than the total number of positive samples you have.

First of all, you need to analyze your detection results. Are you suffering from too many false positives, too many false negatives, or both?

Generally, if your results are not good, you can do several things.

First, make sure that your negative images are reasonably large, and that they contain backgrounds that are typically associated with your objects of interest (faces, in your case). The trainer generates negative samples automatically for each stage. It uses the stages it already has to run detection on the negative images. Whatever it detects is by definition a false positive, and those are used as negatives for the next stage.

More data is generally a good idea. So if you have 15K positives, try adding more. This can be very helpful if your detector misses a lot of faces.

If you are seeing too many false alarms, then you should try to reduce the overall false alarm rate of your classifier. Since you have so much data you can try doing that by increasing the number of stages. Alternatively, you can decrease the max false alarm rate for each stage. That means each stage will have to be more complex, and will take longer to train.

You can also try different features. You now have a choice of Haar, LBP, and HOG. LBP and HOG take much less time and memory to train than Haar. However, HOG may not be very suitable for faces.

Upvotes: 3

Related Questions