2

I am trying to train a cascade classifier using OpenCV, a tutorial & UIUC Image Database for Car Detection. However, the training 'hangs' at stage 0 and never generates any files; in the tutorial, results are seen in a matter of minutes.

I am running OpenCV 2.4.8, which I have installed using conda, on a 2015 MBP running Yosemite (10.10.5)

Steps:

  1. Downloaded the dataset & saved the positive images in a pos folder and the negative images in a neg folder
  2. generated a txt file for the positive images

    find pos -iname "*.pgm" > cars.txt 
    sed -i '' 's/.pgm/.pgm 1 0 0 100 40/g' cars.txt 
    
  3. generated a txt file for the negative images

    find neg -iname "*.pgm" > bg.txt
    
  4. generated a vec file from cars.txt

    opencv_createsamples -info cars.txt -num 550 -w 48 -h 24 -vec cars.vec
    
  5. create a data dir

    mkdir data
    
  6. train cascade

    opencv_traincascade -data data -vec cars.vec -bg bg.txt -numPos 500 -numNeg 500 -numStages 2 -w 48 -h 24 -featureType LBP
    

Output:

PARAMETERS:
cascadeDirName: data
vecFileName: cars.vec
bgFileName: bg.txt
numPos: 500
numNeg: 500
numStages: 2
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   500 : 500
NEG count : acceptanceRatio    500 : 1

I have waited for several hours but the training never progresses nor does it generate any files in my data directory. What is causing the 'hanging'?

j-i-l
  • 10,281
  • 3
  • 53
  • 70
jkarimi
  • 1,247
  • 2
  • 15
  • 27

4 Answers4

1

For what it's worth, I ran into the same symptom and it was driving me crazy. Uninstalling and reinstalling opencv fixed it. The exact command that was hanging suddenly worked fine. It could be you have an old version of opencv lingering somewhere like I had:

$ brew uninstall opencv
Uninstalling /usr/local/Cellar/opencv/2.4.12... (225 files, 36M)
opencv 2.4.11_1 is still installed.
Remove them all with `brew uninstall --force opencv`.

$ brew uninstall --force opencv
Uninstalling opencv... (222 files, 35M)

$ brew install opencv --with-tbb

At any rate, something to consider.

Arel
  • 1,339
  • 17
  • 22
0

I run into the same problem. It turns out using haar cascade training works just fine. You could specific more stages for it to improve accuracy.

  • 1
    This is not an answer... if you have something to add or with to discuss the question, please post as a comment on the question. – dub stylee Sep 25 '15 at 23:14
0

I just don't see how you expect to get anything good out of two training stages. You should train until your -acceptanceRatioBreakValue reaches 10e-5. You've ordered 10 burgers from OpenCV but left after only getting 2.

See here: http://docs.opencv.org/3.1.0/dc/d88/tutorial_traincascade.html#gsc.tab=0

JohnAllen
  • 7,317
  • 9
  • 41
  • 65
0

Compiling OpenCV with --use-tbb (from homebrew) solved this for me, I believe it is a bug with GCD implementation on OS X as mentioned here: https://github.com/opencv/opencv/issues/4765

davedavedave
  • 487
  • 6
  • 11