Ask Your Question

Revision history [back]

Traincascade - Required leaf false alarm rate achieved. Branch training terminated.

Hi all,

First of all, I know this kind of question was asked thousand times, and believe me I've read them all. Problem is that answers in most cases are very different and/or contradict. I would like to show you what have I done and what result I got and hope for you to show me what is this I do wrong.

NOTE: Example shown below is my latest failure with 100 positive and 200 negative pictures. I also tried 700 pos and 300 neg, 2000 pos and 5000 neg, 8000 pos and 9000 neg. I also tried changing several other options but I will answer your questions as they come.

1) I am trying to make my own car cascade. I am mostly interested in frontal and back view of the car, so I have several thousand positive pictures showing exactly that and negative pictures showing common background, street signs, etc. Both positive and negative pictures are sized 64x64. First, I put all of my positive pictures in my positive folder and all of my negative pictures in my negative folder. Then I run the command to create my positive.txt and my negative.txt file.

Result looks like this:

.\negative_images\image352.png
.\negative_images\image353.png
.\negative_images\image354.png
.\negative_images\image355.png
.\negative_images\image356.png
.\negative_images\image357.png
.\negative_images\image358.png
...

And this:

.\positive_images\image0005.png
.\positive_images\image0006.png
.\positive_images\image0007.png
.\positive_images\image0008.png
.\positive_images\image0009.png
.\positive_images\image0032.png
.\positive_images\image0033.png
.\positive_images\image0034.png
...

2) After that i run Naotoshi Seo's createsamples script to create vec file

bin\createsamples.pl positives.txt negatives.txt samples 300 "F:\opencv3.2.0\build\x64\vc14\bin\opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 64 -h 64"

Number 300 (4th parameter) should be total number of pictures: all positives + all negatives. Is this correct? Does -w and -h parameter values should match pictures width and height?

3) All vec files are now in samples folder. Now i run script to merge all vec files in to one.

python tools\mergevec.py -v .\samples -o samples.vec

4) Now I run traincascade to create xml

F:\opencv3.2.0\build\x64\vc14\bin\opencv_traincascade.exe -data classifier -vec samples.vec -bg negatives.txt -numStages 10 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 100 -numNeg 200 -w 64 -h 64 -mode ALL -precalcValBufSize 6096 -precalcIdxBufSize 6096

And this is the result:

PARAMETERS:
cascadeDirName: classifier
vecFileName: samples.vec
bgFileName: negatives.txt
numPos: 100
numNeg: 200
numStages: 10
precalcValBufSize[Mb] : 6096
precalcIdxBufSize[Mb] : 6096
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 64
sampleHeight: 64
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: ALL
Number of unique features given windowSize [64,64] : 13481422

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   100 : 100
NEG count : acceptanceRatio    200 : 1
Precalculation time: 69.809
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|    0.115|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 6 minutes 21 seconds.

===== TRAINING 1-stage =====
<BEGIN
POS count : consumed   100 : 100
NEG count : acceptanceRatio    200 : 0.113895
Precalculation time: 61.826
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|     0.26|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 11 minutes 45 seconds.

===== TRAINING 2-stage =====
<BEGIN
POS count : consumed   100 : 100
NEG count : acceptanceRatio    200 : 0.0301432
Precalculation time: 52.79
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        0|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 16 minutes 25 seconds.

===== TRAINING 3-stage =====
<BEGIN
POS count : consumed   100 : 100
NEG count : acceptanceRatio    0 : 0
Required leaf false alarm rate achieved. Branch training terminated.

In this example it could be seen that stages are very short and it seems that more samples should be added. But, as I said earlier, I tried with more positive and negative examples and calculation always ends up the same. With 8000 positive and 9000 negative samples, calculation lasted for several days before braking on stage 9/20.