how to get higher quality or accuracy of own made Haar cascade - opencv

Could anyone please just roughly tell me what is minimal hit rate, false alarm rate and how do I set width and height for the training purpose. I have already read through documentation on cv2 and also google some of it but in fact it didnt help me much. I have already done my first cascade but it didnt work well and quite horrible. Please just roughly tell me what happen if i change the value of these rate. Im using GUI haar cascade trainer on window. Thanks in advance.

not an answer, but a hint:
e.g. if you have, after stage 0, this result:
NEG count : acceptanceRatio 40000 : 1
Precalculation time: 24.031
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 0.995179| 0.0838|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 1 minutes 57 seconds.
and for stage 1 you get:
NEG count : acceptanceRatio 40000 : 0.124695
Precalculation time: 19.241
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 0.999077| 0.142975|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 4 minutes 9 seconds.
this means the classifier is quite simple in the beginning. FA of 0.0838 vs. acceptanceRatio 40000 : 0.124695 means, that generalization is ok, so far (0.0838 is close to 0.124695) but there is some gap, so negative samples might be diverse enough. In stage 2, NEG count : acceptanceRatio 40000 : 0.034703 shows, that generalization is still on a good way. 0.124695 * 0.142975 = 0.01782826762 though .
From my experience, the acceptance ratio is one of the most important things to observe during training, to show you the quality of your training data.

Related

HAAR training hangs in 7th stage

My Haar training gets hung in the 7th stage. Could someone please help to understand why and how I can get rid of such hung?
I use only 10 stages and have around 500 images.This is my training command:
opencv_traincascade -data data_50x50 -vec samples_50x50.vec -bg neg_70x70.dat -numPos 495 -numNeg 570 -numStages 10 -w 20 -h 20 -featureType HAAR -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024 -minHitRate 0.999 -maxFalseAlarmRate 0.1 -maxWeakCount 1000
Till 6th stage it runs fast (<5 hours), then in 7th stage, I am waiting days:
I can see that FA is decreasing till 6th stage.
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 27 minutes 11 seconds.
===== TRAINING 6-stage =====
<BEGIN
POS count : consumed 495 : 495
NEG count : acceptanceRatio 570 : 1.59311e-06
Precalculation time: 4
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 1| 0.166667|
+----+---------+---------+
| 4| 1| 0|
+----+---------+---------+
END>
Training until now has taken 0 days 4 hours 2 minutes 32 seconds.
===== TRAINING 7-stage =====
<BEGIN
POS count : consumed 495 : 495
Remains in such stage for ages (>2 days)
Thanks

OpenCV error "Train dataset for temp stage can not be filled. Branch training terminated." after starting training stage-3

While searching for this error I only found cases where it happened right at the beginning. In my case, it occurred at the beginning of the 3-stage training.
I'm using OpenCV 2.4.10, with OpenMP enabled. Bellow is the command line I used and the output. Does anyone knows how to solve this problem?
root#6b0f88eaadb9:/opt/ocr-samples3/train-detector# opencv_traincascade -data ./out// -vec ./positive/vecfile.vec -bg ./negative/negative.txt -w 247 -h 80 -numPos 78 -numNeg 1325 -featureType LBP -numStages 8
libdc1394 error: Failed to initialize libdc1394
Training parameters are loaded from the parameter file in data folder!
Please empty the data folder if you want to use your own set of parameters.
PARAMETERS:
cascadeDirName: ./out//
vecFileName: ./positive/vecfile.vec
bgFileName: ./negative/negative.txt
numPos: 78
numNeg: 1325
numStages: 8
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: LBP
sampleWidth: 247
sampleHeight: 80
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 78 : 78
NEG count : acceptanceRatio 1325 : 1
Precalculation time: 6
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1|0.0211321|
+----+---------+---------+
END>
Training until now has taken 0 days 1 hours 22 minutes 40 seconds.
===== TRAINING 1-stage =====
<BEGIN
POS count : consumed 78 : 78
NEG count : acceptanceRatio 1325 : 0.0928456
Precalculation time: 10
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 1|0.0324528|
+----+---------+---------+
END>
Training until now has taken 0 days 3 hours 19 minutes 57 seconds.
===== TRAINING 2-stage =====
<BEGIN
POS count : consumed 78 : 78
NEG count : acceptanceRatio 1325 : 0.00679104
Precalculation time: 7
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 0.08|
+----+---------+---------+
END>
Training until now has taken 0 days 4 hours 38 minutes 25 seconds.
===== TRAINING 3-stage =====
<BEGIN
POS count : consumed 78 : 78
Train dataset for temp stage can not be filled. Branch training terminated.
How big are you negative images. I had the same problem. The error say that he hasn't enough negative images. Your negative images doe not have to be the same size as your positive. So what I did take the original negative images but a black rectangle on the object. And started again.
The function negative search in the image for new negative images, when he used one negative image he will not use it again. It randomly chosen and has the same size as your positive image.

Bad trained cascade in OpenCV

I can't train the classifier properly.. When I use the generated cascade.xml the object is not recognized. Instead some parts of the object are.
The command line for training is this:
opencv_traincascade -data data -vec samples.vec -bg negatives.txt -numPos 200 -numNeg 100 -numStages 13 -w 80 -h 80 -featureType LBP -minHitRate 0.999 -maxFalseAlarmRate 0.5
While training the output looks like this:
===== TRAINING 10-stage =====
<BEGIN
POS count : consumed 200 : 200
NEG count : acceptanceRatio 100 : 0.00586029
Precalculation time: 2
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 0.09|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 6 minutes 9 seconds.
===== TRAINING 11-stage =====
<BEGIN
POS count : consumed 200 : 200
NEG count : acceptanceRatio 100 : 0.00724585
Precalculation time: 3
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 0.09|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 6 minutes 49 seconds.
===== TRAINING 12-stage =====
<BEGIN
And when I use it to detect my object (in my case the object is a steering wheel) the result is:
You are using too few images as a samples for the image which has a 80x80 dimension.
I'd minimize the dimension of the images, meanwhile adding some more samples.
Another thing is the set of the negative images. What are you using as a negative samples? Try to enlarge your negative image set by adding this false detected chunks.

Detecting Artificial Patterns

I trained a classifier to detect a MacBeth colorchart which is an artificial pattern and should be easy to detect. Training was done detecting haarfeatures from 1500 negatives and 4000 positives using bg photos from google (http://tutorial-haartraining.googlecode.com/svn/trunk/data/negatives/) that were similar to the environment where the pattern is most probably to be found.
The statistics of the training seemed to be very reasonable:
===== TRAINING 9-stage =====
POS count : consumed 4000 : 4170
NEG count : acceptanceRatio 1500 : 0.00365317
Precalculation time: 3
| N | HR | FA |
| 1| 1| 1|
| 2| 1| 1|
| 3| 1| 1|
| 4| 0.996| 0.865333|
| 5| 0.996| 0.865333|
| 6| 0.99625| 0.688|
| 7| 0.99525| 0.633333|
| 8| 0.99575| 0.517333|
| 9| 0.99525| 0.489333|
It went through all 10-stages and produced a 33kb XML cascade description file.
However when I try to find the pattern, it detects all sorts of things as the pattern.
Does anyone have an idea how to improve the settings or properly find that pattern?
Here are my training parameters:
PARAMETERS:
cascadeDirName: /training3
vecFileName: pos_samples_vec_004.vec
bgFileName: bg5.txt
numPos: 4000
numNeg: 1500
numStages: 10
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: HAAR
sampleWidth: 32
sampleHeight: 32
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: ALL
Increase the number of stages, a minimum of 20 stages are usually needed in order to achieve any amount of specificity in detection. Also keep track of the acceptance ratio in the negatives, the lower it is the better.

opencv_traincascade always gets stuck

I am trying to use OpenCV's opencv_traincascade to generate a Haar Cascade. So far I have 87 distinctive positive samples and 39 negative samples for testing purposes. I generated the .vec file with opencv_createsamples, which worked fine. When I'm running opencv_traincascade it always gets stuck after a few stages, no matter how I change the parameters. My call looks like this:
opencv_traincascade -data /opencvimgs/haarcascades/data/ -vec /opencvimgs/haarcascades/out.vec -bg /opencvimgs/haarcascades/neg.txt -numPos 87 -numNeg 39
I tried increasing and decreasing minHitRate and maxFalseAlarmRate as well as numPos and numNeg without any success. It might run for a few more stages but then it seems to hang in an infine loop again. How can I resolve this?
The output below is what the programm writes to the console:
opencv_traincascade -data /opencvimgs/haarcascades/data/ -vec
/opencvimgs/haarcascades/out.vec -bg /opencvimgs/haarcascades/neg.txt -numPos 87 -numNeg 39
PARAMETERS:
cascadeDirName: /opencvimgs/haarcascades/data/
vecFileName: /opencvimgs/haarcascades/out.vec
bgFileName: /opencvimgs/haarcascades/neg.txt
numPos: 87
numNeg: 39
numStages: 20
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: HAAR
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC
===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 87 : 87
NEG count : acceptanceRatio 39 : 1
Precalculation time: 1
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 0|
+----+---------+---------+
END>
===== TRAINING 1-stage =====
<BEGIN
POS count : consumed 87 : 87
NEG count : acceptanceRatio 39 : 0.0697674
Precalculation time: 1
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 0|
+----+---------+---------+
END>
===== TRAINING 2-stage =====
<BEGIN
POS count : consumed 87 : 87
NEG count : acceptanceRatio 39 : 0.00945455
Precalculation time: 1
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 0|
+----+---------+---------+
END>
===== TRAINING 3-stage =====
<BEGIN
POS count : consumed 87 : 87
NEG count : acceptanceRatio 39 : 0.000326907
Precalculation time: 1
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 0|
+----+---------+---------+
END>
===== TRAINING 4-stage =====
<BEGIN
POS count : consumed 87 : 87
A possible answer is that you're using too few negative samples.
Read the instruction from OpenCV documents and reference paper from Viola and Jones.
They are using cascaded classifier to achieve high accuracy and low false alarms by eliminate part of the negative samples each time. If you are using too few negative samples, it defeat the purpose of the cascaded classifier in the first place.
Notice that, for practical use, the system have much much more images without faces than with faces.

Resources