Using opencv_traincascade and speed up the processing
hello there,
I'm using OpenCV to create a "training" file for dog head recognition. I collected positive images (more than 250) and stored them in a directory. The file pointing to the images (positives.dat) looks like follows:
positive_images/314x382xfrench-bulldog.jpg.pagespeed.ic.9df2ynqdWL.jpg 1 0 0 243 243
positive_images/275x480xbeauceron.jpg.pagespeed.ic.VaRD4-_XQX.jpg 1 0 0 200 200
positive_images/shetland-sheepdog12.jpg 1 0 0 185 185
positive_images/7014-doberman-pinscher7.jpg 1 0 0 286 286
...
Every positive image has a good quality and white background (I thought this is better for OpenCV because the image contains the positive content exclusively).
Afterwards I collected negative images too. The file poiting to them looks like this (negatives.dat):
negative_images/neg-4179.jpg
negative_images/neg-0811.jpg
negative_images/neg-3761.jpg
negative_images/neg-4281.jpg
In the next step the vector file has been created by executing this command:
opencv_createsamples -vec samples.vec -bg negatives.dat -info positives.dat -w 80 -h 80 -show
That means that samples.vec contains all the images from positives.dat. Each and every image is scaled to 80x80 pixel.
Finally, I started the training by issuing this command:
opencv_traincascade -data training -vec samples.vec -bg negatives.dat \
-numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 200 \
-numNeg 600 -w 80 -h 80 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024
By now, opencv_traincascade has been running for approx. 52 hours!! Currently, the stage 19. is processed.
The console output looks like this:
~/OpenCVProjects/DogFaceRecognition$ ./_training.sh
PARAMETERS:
cascadeDirName: training
vecFileName: samples.vec
bgFileName: negatives.dat
numPos: 200
numNeg: 600
numStages: 20
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
stageType: BOOST
featureType: HAAR
sampleWidth: 80
sampleHeight: 80
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: ALL
===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 200 : 200
NEG count : acceptanceRatio 600 : 1
Precalculation time: 23
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 1| 0.298333|
+----+---------+---------+
END>
===== TRAINING 1-stage =====
<BEGIN
POS count : consumed 200 : 200
NEG count : acceptanceRatio 600 : 0.226757
Precalculation time: 23
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 1| 0.7|
+----+---------+---------+
| 4| 1| 0.328333|
+----+---------+---------+
END>
===== TRAINING 2-stage =====
<BEGIN
POS count : consumed 200 : 200
NEG count : acceptanceRatio 600 : 0.0837638
Precalculation time: 23
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 0.67|
+----+---------+---------+
| 3| 1| 0.308333|
+----+---------+---------+
END>
===== TRAINING 3-stage =====
<BEGIN
POS count : consumed 200 : 200
NEG count : acceptanceRatio 600 : 0.0256663
Precalculation time: 23
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 0.556667|
+----+---------+---------+
| 3| 1| 0.311667|
+----+---------+---------+
END>
===== TRAINING 4-stage =====
<BEGIN
POS count : consumed 200 : 200
NEG count : acceptanceRatio 600 : 0.00866226
Precalculation time: 22
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 1| 0.535|
+----+---------+---------+
| 4| 1| 0.276667|
+----+---------+---------+
END>
===== TRAINING 5-stage =====
<BEGIN
POS count : consumed 200 : 200
NEG count : acceptanceRatio 600 : 0.00343436
Precalculation time: 23
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 0.685|
+----+---------+---------+
| 3| 1| 0.438333|
+----+---------+---------+
END>
===== TRAINING 6-stage =====
<BEGIN
POS count : consumed 200 : 200
NEG count ...