Training Classifier Cascades Using Multiple Processor Cores

10,392 views
Skip to first unread message

Aaron Brown

unread,
Aug 20, 2011, 5:00:18 PM8/20/11
to android-opencv
Hey folks,

I'm trying to train new classifier cascades and using one core is
taking forever. (20 stage classifier building at about 1 stage per
day.) So I've investigated building Haartraining with OpenMP enabled,
but I can't for the life of me get it to build. The Visual Studio
projects are all broken, and I get compile errors from make when I try
to enable it via the CMake files.

In my investigations, I've also found references to TrainCascades,
which I get the impression does the same thing as Haartraining. Is
that true? Does TrainCascades use multithreading to utilize multiple
cores? If not, how could I enable it?

Basically I need some utility that I can use to build classifiers
that won't take forever, hopefully by using all 8 cores in my machine,
rather than just one. Any advice, pointers?

Thanks,
AMB

Kirill Kornyakov

unread,
Aug 23, 2011, 4:11:30 AM8/23/11
to android...@googlegroups.com, Maria Dimashova
OpenCV team should create a guide describing training process, because nobody is able to work on it effectively... Unfortunately I don't have enough time to describe the whole process, but I'll try to give some advises.

BTW, better to discuss this topic in major OpenCV group: http://tech.groups.yahoo.com/group/OpenCV/

1. opencv_traincascade. opencv_haartraining is an obsolete utility and probably will be removed from trunk (actually better to do it ASAP, because it confuses people). opencv_traincascade is a newer version and it has 2 important features: it supports LBP features and it supports multi-threading. So, we should forget about opencv_haartraining and switch completely to opencv_traincascade.
2. LBP. In short words, LBP has one significant advantage over Haar - speed. Both training and detection are much faster, you will see the difference. At the same time LBP may have a bit lower quality of detection. But if you do training well (good training dataset first of all), you can get almost the same quality. In any case we recommend to work with LBP features during training. Later you can run training process on the final training set with Haar features and compare the results. But the most important step is to create a proper training dataset, and better to use LBP here.
3. Multi-threading. If you want to enable multi-threading in OpenCV, you should build it from sources with Intel TBB support. OpenMP is removed completely from OpenCV. To compile everything from sources, just look at http://opencv.willowgarage.com/wiki/TBB and then follow http://opencv.willowgarage.com/wiki/InstallGuide. After that you should see that opencv_traincascade uses several cores during training.

So, download the TBB, build OpenCV with it and try to run opencv_traincascade with LBP features. Training process takes ~2hours on 50K+ positives on my Intel Core i5 (4 cores).

Good luck :)
Kirill

Aaron Brown

unread,
Aug 24, 2011, 9:46:46 PM8/24/11
to android-opencv
Kirill,

This is AWESOME. Thank you so much! Grabbing TBB right now. :-)

-Aaron

On Aug 23, 1:11 am, Kirill Kornyakov <kirill.kornya...@itseez.com>
wrote:
> OpenCV team should create a guide describing training process, because *
> nobody* is able to work on it effectively... Unfortunately I don't have
> enough time to describe the whole process, but I'll try to give
> some advises.
>
> BTW, better to discuss this topic in major OpenCV group:http://tech.groups.yahoo.com/group/OpenCV/
>
> 1. opencv_traincascade. opencv_haartraining is an obsolete utility and
> probably will be removed from trunk (actually better to do it ASAP, because
> it confuses people). opencv_traincascade is a newer version and it has 2
> important features: it supports LBP features and it supports
> multi-threading. So, we should forget about opencv_haartraining and switch
> completely to opencv_traincascade.
> 2. LBP. In short words, LBP has one significant advantage over Haar - speed.
> Both training and detection are much faster, you will see the difference. At
> the same time LBP may have a bit lower quality of detection. But if you do
> training well (good training dataset first of all), you can get almost the
> same quality. In any case we recommend to work with LBP features during
> training. Later you can run training process on the final training set with
> Haar features and compare the results. But the most important step is to
> create a proper training dataset, and better to use LBP here.
> 3. Multi-threading. If you want to enable multi-threading in OpenCV, you
> should build it from sources with Intel TBB support. OpenMP is removed
> completely from OpenCV. To compile everything from sources, just look athttp://opencv.willowgarage.com/wiki/TBBand then followhttp://opencv.willowgarage.com/wiki/InstallGuide. After that you should see

Aaron Brown

unread,
Aug 27, 2011, 5:08:35 PM8/27/11
to android-opencv
I just wanted to say, thanks to your post I got traincascades working
with TBB.

haartraining + singlecore > 3 weeks for one classifier.
traincascades + multicore < 30 minutes for one classifier.

AWESOME! Thank you SO much. :-)

-Aaron
> > completely from OpenCV. To compile everything from sources, just look athttp://opencv.willowgarage.com/wiki/TBBandthen followhttp://opencv.willowgarage.com/wiki/InstallGuide. After that you should see

yngjng

unread,
Sep 22, 2011, 11:14:21 PM9/22/11
to android-opencv
Hi,

I'm new with opencv_traincascade.exe,
I just followed the mentioned step and unable to get the traincascades
work.
FYI, I'm using OpenCV 2.1 with TBB + IPP and run on WinXP SP3

command arguments:
opencv_traincascade.exe -data cascade001 -vec positives.vec -bg
negatives.txt -numPos 1400 -numNeg 2800 -numStages 20 -
precalcValBufSize 512 -precalcIdxBufSize 512 -featureType LBP -w 91 -h
21 > cascade001.log

Below is the output message.

PARAMETERS:
cascadeDirName: cascade001
vecFileName: positives.vec
bgFileName: negatives.txt
numPos: 1400
numNeg: 2800
numStages: 20
precalcValBufSize[Mb] : 512
precalcIdxBufSize[Mb] : 512
stageType: BOOST
featureType: LBP
sampleWidth: 91
sampleHeight: 21
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxTreeDepth: 1
maxWeakCount: 100

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 1400 : 1400
NEG count : acceptanceRatio 2800 : 1
Precalculation time: 38.375
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 0|
+----+---------+---------+
END>
Parameters can not be written, because file cascade001\params.xml can
not be opened.

Is it because of FA = 0?
If i train withHAAR feature, it will prompt an error message on out of
memory.
FYI, these training data can be train using opencv_haartraining.

Please advise. Thanks.
> > > completely from OpenCV. To compile everything from sources, just look athttp://opencv.willowgarage.com/wiki/TBBandthenfollowhttp://opencv.willowgarage.com/wiki/InstallGuide. After that you should see

Kirill Kornyakov

unread,
Sep 23, 2011, 4:18:11 AM9/23/11
to android-opencv
It looks like you don't have cascade001 folder. Please note that you
should create manually the directory which is given with -data command
line option.

Actually you should meet the same problem with HAAR. So, I think that
you give another directory with -data option, and probably this folder
contains cascade in OLD FORMAT. opencv_haartraining uses another
format, so you can't reuse the same cascade folder between
opencv_haartraining and opencv_traincascade applications.

So, please try to create new folder and run training from the
beginning. May be you should update to OpenCV 2.3.1. You can also send
us your vec-file (if it is not a top-secret) and we will try it with
OpenCV trunk.

Best regards,
Kirill
> > > > completely from OpenCV. To compile everything from sources, just look athttp://opencv.willowgarage.com/wiki/TBBandthenfollowhttp://opencv.wil.... After that you should see

yngjng

unread,
Oct 13, 2011, 9:14:53 PM10/13/11
to android-opencv
Kirill, thank you for your advice. It works!!!
I had updated to OpenCv 2.3.1 and using opencv_traincascade.
However, the application will prompt error message of memory
allocation if I set
precalcValBufSize[Mb] : 512
precalcIdxBufSize[Mb] : 512
Temporary solved the problem by changing these 2 variables to 256.
Any ideas on it?

Besides, it seem like the structure of the cascade.xml had changed.
Can i use opencv_performance.exe to test the cascade performance or
any compatible application is this new version of opencv that work
that way?
I found a application named "opencv_test_objdetect.exe", still unable
to find the documentation on it.
Please advise.

Thanks.

On Sep 23, 4:18 pm, Kirill Kornyakov <kirill.kornya...@itseez.com>
wrote:

Kirill Kornyakov

unread,
Oct 14, 2011, 4:38:49 AM10/14/11
to android...@googlegroups.com
There is a new user guide on training: http://opencv.itseez.com/trunk/doc/user_guide/ug_traincascade.html. Is is pre-alpha and contains spelling errors :)

opencv_test_objdetect is a set of unit-tests for opencv_objdetect module. It can't be used to analyse the quality of classifier.

You can see that opencv_performance can be used only for old-format cascade. If you want to test your LBP cascade, you should create QA scripts by yourself. Or you can update opencv_performance and submit your patch ;)

Good luck,
Kirill

Kirill Kornyakov

unread,
Jul 19, 2012, 4:27:57 AM7/19/12
to android...@googlegroups.com
Sorry, but I was mistaken about the threading in training. Here is the question with more details: http://answers.opencv.org/question/63/enable-multithreading-with-tbb-during-cascade/. So, you shouldn't expect significant speedup from TBB... :(

Serhiy Kolesnyk

unread,
Jul 19, 2012, 1:02:15 PM7/19/12
to android...@googlegroups.com
Thanks! That clears everything!

On 19 July 2012 11:27, Kirill Kornyakov <kirill.k...@itseez.com> wrote:
Sorry, but I was mistaken about the threading in training. Here is the question with more details: http://answers.opencv.org/question/63/enable-multithreading-with-tbb-during-cascade/. So, you shouldn't expect significant speedup from TBB... :(

--
 
 
 

Reply all
Reply to author
Forward
0 new messages