Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV exception after 1 day calculation

I am using opencv_traincascade for object detection. I try to find glasses on photo. For this, I've downloaded 830 pictures like this: http://pi1.lmcdn.ru/product/V/I/VI060DWIHZ27_1_v2.jpg

Then I've downloaded many pictures with model in dresses or just dresses photos, 1799 photos.

Then I've start opencv_traincascade with parameters: opencv_traincascade -data Feature/classifier -vec samples.vec -bg negatives.txt -numStages 10 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 830 -numNeg 1799 -w 60 -h 90 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024

But after step 4, I have a message: Train dataset for temp stage can not be filled. Branch training terminated.

The full stacktrace is:

➜  pictureFeature opencv_traincascade -data Feature/classifier -vec samples.vec -bg negatives.txt -numStages 10 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 830 -numNeg 1799 -w 60 -h 90 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024

PARAMETERS:
cascadeDirName: Feature/classifier
vecFileName: samples.vec
bgFileName: negatives.txt
numPos: 830
numNeg: 1799
numStages: 10
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 60
sampleHeight: 90
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: ALL



===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   830 : 830
NEG count : acceptanceRatio    1799 : 1
Precalculation time: 26

+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3|        1| 0.145636|
+----+---------+---------+

END>
Training until now has taken 0 days 5 hours 22 minutes 10 seconds.

===== TRAINING 1-stage =====
<BEGIN
POS count : consumed   830 : 830
NEG count : acceptanceRatio    1799 : 0.145715
Precalculation time: 24

+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3|        1|        1|
+----+---------+---------+
|   4|        1| 0.762646|
+----+---------+---------+
|   5|        1| 0.432462|
+----+---------+---------+

END>
Training until now has taken 0 days 14 hours 38 minutes 28 seconds.

===== TRAINING 2-stage =====
<BEGIN
POS count : consumed   830 : 830
NEG count : acceptanceRatio    1799 : 0.062696
Precalculation time: 28

+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3|        1|        1|
+----+---------+---------+
|   4|        1| 0.590328|
+----+---------+---------+
|   5|        1| 0.187326|
+----+---------+---------+

END>
Training until now has taken 0 days 23 hours 21 minutes 4 seconds.

===== TRAINING 3-stage =====
<BEGIN
POS count : consumed   830 : 830
NEG count : acceptanceRatio    1799 : 0.0117929
Precalculation time: 21

+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3|        1|0.0944969|
+----+---------+---------+

END>
Training until now has taken 1 days 3 hours 47 minutes 34 seconds.

===== TRAINING 4-stage =====
<BEGIN
POS count : consumed   830 : 830
NEG count : acceptanceRatio    1799 : 0.00112161
Precalculation time: 18

+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        0|
+----+---------+---------+

END>
Training until now has taken 1 days 5 hours 4 minutes 35 seconds.

===== TRAINING 5-stage =====
<BEGIN
POS count : consumed   830 : 830
Train dataset for temp stage can not be filled. Branch training terminated.

I tried to use cascade.xml for object searching, but the result was completely fail.

enter image description here

Could somebody help with my problem?

like image 666
Anton Erjomin Avatar asked Jul 28 '16 06:07

Anton Erjomin


2 Answers

If you look at the error you'll find that it stopped at 'NEG count' which means there was an issue with reading the negative training data set images at stage-5. So you need to fix the path to the negative training samples for it to work.

Here is a detailed discussion on this issue which might be helpful: Cascade Training Error OpenCV 2.4.4

It can also be an issue with the bg.txt file, here is another answer: error in train casacde.

Another post with similar error: Train dataset for temp stage can not be filled.

If nothing works try using a different version of open cv: http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/download

like image 149
Abhijay Ghildyal Avatar answered Nov 07 '22 16:11

Abhijay Ghildyal


That's a pretty common error. There is not much I know about this error and I can only guess a solution, since there are a lot of possible reasons for that error.

It could be relative to the directories structure (just notice that the path for negative examples should be relative to the current directory)

or because the line break in bg file (negatives.txt in your case) are bad encoded. Could you please double check that last character of each line in the 'negatives.txt' file are '\n' and not '\r' ?

Also keep trying to maintain positive to negative samples ratio around 25%-30%

And finaly be sure that all your positive and negative images contain the head face:

In the sample picture (one of the 830) there is only one sunglasses visible on it (no head , no hear, no hair) only white backgroud, so your classifier will finaly train to make recognition of sunglasses only on white backgroud, so there is no chance to recognize any sunglasses when face is visible;

Try to respect :

  • positive picture = headface with sunglasses

  • negative picture = headface only

Regards

like image 3
A STEFANI Avatar answered Nov 07 '22 17:11

A STEFANI