Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV - LBP Traincascade can’t pass Precalculation in Stage 0, but HAAR works fine?

Tags:

opencv

I run opencv_traincascade, and I never reach the precalculation time for stage 0.

Edit: My problem seems to be specific to LBP training. I changed featureType to HAAR and the classifier below finished training in a matter of minutes

Edit: Precalculation time is in seconds, so at stage 0 you should see it reach precalculation within 10 seconds, but I've seen it as high as 40 seconds. Precalculation time may increase steadily from stage to stage, and then suddenly increase dramatically to half an hour in the later stages (and perhaps even longer than that if you are working with thousands of samples, but I haven't got that far yet)

(I will continue to update this post filling in things I've come to understand that prevented me from understanding precalculation, and perhaps find out why HAAR training would work while LBP doesn't. It would probably just require looking at the source code for initiating the stage cycle)

Problem

I run opencv_traincascade, and I never reach the precalculation time for stage 0.

I’m using an MacBook Air purchased in 2014.

Processor 1.3 GHz Intel Core i5
Memory 4 GB 1600 MHz DDR3
Graphics Intel HD Graphics 5000
Software OS X 10.9.4 (13E28)

My terminal looks something like this, and runs some 390% (really?) of my CPU and 4 threads in my Activity Monitor.

===== TRAINING 0-stage ===== <BEGIN POS count : consumed x : x NEG count : acceptanceRatio y : 1

Although I’ve tried creating many classifiers, for the sake of sharing something we can all relate to, I’m going to reference a tutorial for car detection since I get the same result not matter if it’s a training of my own or not. This trainer has been published, and I’ve seen other people reference it, so I assume it works.

https://www.youtube.com/watch?v=WEzm7L5zoZE

On my desktop I have:

A pos folder with the relative file paths and information (1 0 0 100 40) in a cars.info folder;
A bg.txt file with relative paths to a neg folder containing the negative samples;
An empty data folder named “data”;
A cars.vec file of positive samples. I can view the vector file and the images are there.

There are 550 positive samples at 100x40 originally, and 48x24 after using createsamples to create the vec file

There are 500 negative samples at 100x40

Here was the createsamples command, for reference:

opencv_createsamples -info cars.info -num 550 -w 48 -h 24 -vec cars.vec

Then I run the following command:

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

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

This is my output that I’ve never seen reach precalculation for LBP, no matter what I’m trying to train; how I’ve tried to change the sample size, resolution of images, minHitRate, or lowering numPos.

===== TRAINING 0-stage ===== <BEGIN POS count : consumed 500 : 500 NEG count : acceptanceRatio 500 : 1

Please ask for any information I failed to supply. I apologize.

I’ve read about trainers being stuck in infinite loops, and modification of the source code needed. However, I hope that can be avoided since this appears to work for others (at least the author).

Thank you all for all the past questions and answers that have helped me with various coding projects.

like image 846
Troup Avatar asked Aug 25 '14 01:08

Troup


1 Answers

I have met such problem before. The way I solve it is to set the values of precalcValBufSize and precalcIdxBufSize to 0 and 0. It seems that precalculation can not work for LBP. However, it works well after they were set to 0. The training process for LBP is much faster than Haar.

like image 84
user2914509 Avatar answered Nov 22 '22 08:11

user2914509