Ask Your Question
1

Cascade training failed OpenCV 2.4.9.1

asked 2016-05-30 23:48:29 -0600

bluezap gravatar image

updated 2016-06-01 12:44:41 -0600

I'm trying to train a cascade database with 41 positive images and 500 negative images (as a trail) Here are my steps

pos.info -

pos/pos-001.pgm 1 0 0 100 40
pos/pos-002.pgm 1 0 0 100 40
pos/pos-003.pgm 1 0 0 100 40

so on till 41

**neg.txt -**

neg/neg-001.pgm
neg/neg-002.pgm

so on till 500

All images are 100x40

all files are on my ubuntu Desktop (even the data folder with no data inside)

To create the vector file

opencv_createsamples -info pos.info -num 40 -w 48 -h 24 -vec pos.vec

To train the database -

opencv_traincascade -data data -vec pos.vec -bg bg.txt -numPos 30 -numNeg 500 -numStages 10 -w 48 -h 24 -featureType LBP

Version OpenCV - 2.4.9.1

Here is the copy from my terminal -

--Error--

example@example:~/Desktop$ opencv_createsamples -info pos.info -num 41 -w 48 -h 24 -vec pos.vec

Info file name: pos.info
Img file name: (NULL)
Vec file name: pos.vec
BG  file name: (NULL)
Num: 41
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 48
Height: 24
Create training samples from images collection...
Done. Created 41 samples


example@example:~/Desktop$ opencv_traincascade -data data -vec pos.vec -bg bg.txt -numPos 30 -numNeg 500 -numStages 10 -w 48 -h 24 -featureType LBP

PARAMETERS:
cascadeDirName: data
vecFileName: pos.vec
bgFileName: bg.txt
numPos: 30
numNeg: 500
numStages: 10
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: LBP
sampleWidth: 48
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100

===== TRAINING 0-stage =====

BEGIN
POS count : consumed   30 : 30
Train dataset for temp stage can not be filled. Branch training terminated.
Cascade classifier can't be trained. Check the used training parameters.

NEW ERROR AFTER NEG PATH CORRECTION

example@Example:~/Desktop$ opencv_createsamples -info balls.info -num 41 -w 48 -h 28 -vec balls.vec

Info file name: balls.info
Img file name: (NULL)
Vec file name: balls.vec
BG  file name: (NULL)
Num: 41
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 48
Height: 28
Create training samples from images collection...
Done. Created 41 samples

example@Example:~/Desktop$ opencv_traincascade -data data -vec balls.vec -bg bg.txt -numPos 35 -numNeg 500 -numStages 2 -w 48 -h 28 -featureType LBP

PARAMETERS:
cascadeDirName: data
vecFileName: balls.vec
bgFileName: bg.txt
numPos: 35
numNeg: 500
numStages: 2
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: LBP
sampleWidth: 48
sampleHeight: 28
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   35 : 35
NEG count : acceptanceRatio    500 : 1
Precalculation time: 0
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        0|
+----+---------+---------+
END>
Training until now ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-06-01 07:34:33 -0600

updated 2016-06-01 07:35:06 -0600

It is not able to find the negative files, because there is no rule stating NEG count:consumed. That being said, change all the relative paths in your text files from neg/neg-001.pgm to like /home/yourUserName/Desktop/neg/neg-001.pgm and your problems will go away :) The tool is not working decently with relative paths.

edit flag offensive delete link more

Comments

Thank you! this got me quite far. but I ran into another error. I have updated the question above.

bluezap gravatar imagebluezap ( 2016-06-01 12:40:34 -0600 )edit
2

This is not an error, rather your training that satisfies your needs/demands. The required leaf false alarm rate is calculated by reqLeafFA = maxFalseAlarmRate^number_stages. This means that by defining the parameter -numStages 2 that this value is very sloppy and thus your cascade is good enough. Change that value to -numStages 20 and training will simply continue.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-06-02 02:31:55 -0600 )edit

Got it! What should I do to train the cascade with a lower number of stages? I don't want to go for 20 because it will take weeks. Should I reduce the number of samples I have? Thanks

bluezap gravatar imagebluezap ( 2016-06-04 14:22:23 -0600 )edit

Well it is not because you have multiple stages that it will train for weeks. Start of with LBP features and 20 stages and with some luck, getting those will only take an hour or two.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-06-19 15:24:04 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-05-30 23:47:17 -0600

Seen: 497 times

Last updated: Jun 01 '16