Ask Your Question

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

asked 2017-09-18 17:18:56 -0500

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:


And this:


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

bin\ 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\ -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:

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 =====
POS count : consumed   100 : 100
NEG count : acceptanceRatio    200 : 1
Precalculation time: 69.809
|  N |    HR   |    FA   |
|   1|        1|        1|
|   2|        1|    0.115|
Training until ...
edit retag flag offensive close merge delete



"I am mostly interested in frontal and back view of the car" -- uuhm, you probably cannot train it on BOTH front and back view at the same time

berak gravatar imageberak ( 2017-09-19 00:53:18 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2017-09-19 06:29:02 -0500

updated 2017-09-19 06:43:25 -0500

Let me get some hints up

  • As pointed out by @berak, two views in a single cascade --> forget it, simply does not work and not what cascade classifiers in OpenCV following the Viola and Jones paper is meant for. You will need at least 2 separate models.
  • Naotoshi Seo's createsamples script --> your second mistake. Its better to use your true data, without artificial data augmentation, but thats purely from experience.
  • -w and -h are the dimension of your window (for negative sample grabbing) and model size. These can be the training image dimensions but do not have to be. Everything is rescaled to these parameters before training starts.
  • Again don't use the script, then you do not need to merge vectors :D
  • -minHitRate 0.999 that is very strict for your weak classifiers, might wanna try putting that on 0.995. Its an immense difference!
  • Required leaf false alarm rate achieved. Branch training terminated. --> your data is optimally seperated given the set parameters. You need more data to obtain a better detector.

Oh and BTW, people should understand the difference between a notice/warning and an actual error. This does not mean your training breaks up, it just finished because you have what you asked for.

And finally, if you want a robust car detector --> with very little false positives, be prepared to collect multiple thousand positives and at least 200k-300k negative samples. Your set is just way to easy to solve mathematically spoken.

edit flag offensive delete link more


I am little confused... There is 5 stage LBP cars.xml publicly available that can detect car from every side. Thanks to all of you for your advice. I will think about all of the information given and let you know how did I solved my problem.

AlexVujic gravatar imageAlexVujic ( 2017-09-19 06:47:42 -0500 )edit

I do not know of such a cascade, and also, it does not make sense, since aspect ratio's are different. Are you sure we are talking about and OpenCV cascade?

StevenPuttemans gravatar imageStevenPuttemans ( 2017-09-19 06:49:33 -0500 )edit

cant remember now where I found it but here is repository containing haar cascade that can detect both front and back of the car.

Used both of the mentioned cascades myself, so I know they are working... Just not good enough.

AlexVujic gravatar imageAlexVujic ( 2017-09-19 06:56:05 -0500 )edit

answered 2017-09-18 19:17:10 -0500

daveg2 gravatar image

My understanding is that this means the classifier has reached the desired accuracy on the training dataset given the input parameters. Have you tried running your classifier on your test images to see if it works as-is?

With regards your point 2., I believe the number should be the number of negatives in the -bg training set.

" Be careful that only the first <num> negative images in the <collection_file_of_negatives> are used."

From point 3. here:

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-09-18 17:18:56 -0500

Seen: 543 times

Last updated: Sep 19 '17