Ask Your Question
1

Haartraining and Traincascade crashes creating XML.

asked 2013-12-11 04:51:38 -0500

Ralcaidev89 gravatar image

updated 2013-12-11 05:25:07 -0500

Hi everyone, I'm trying to generate XML with haartraining or taincascade based on generated .vec file, which is created by following command:

bin\opencv_createsamples.exe -info positive\info.txt -vec positive\muestra.vec -num 10 -w 90 -h 140

I think it's well generated: no errors, and file weight is about 30mb (when specify -num 900, -num 10 weights about 250kb).

I've tried to train using:

bin\opencv_haartraining.exe -data cascada -vec positive\muestra.vec -bg negative\infofile.txt -npos 10 -nneg 10 -w 90 -h 140 -mem 1024 -nonsym

and

bin\opencv_traincascade.exe -data cascada -vec positive\muestra.vec -bg negative\infofile.txt -numPos 10 -numNeg 10 -w 90 -h 140 -mem 1024

In both cases, the app crashes, telling me it can't allocate memory. Using Haartaining it get stuck here:

image description

Watching at the system monitor, we can see it consumes about 5Gb of 6 available on system (4.7 on this particular screenshot), even with only 10 positive and 10 negative images. (This low number of images is an attempt to resolve the memory problem, the original files are about 900 positives and 1000 negatives, 92x144 sized with BMP extesion).

image description

Using Traincascade, simply don't show anything until it crashes. Only popup new Windows message "traincascade stop working, searching for solution..." after one minute.

I've tried with multiple -mem values in both haar and traincascade (between 512 and 5000), and three different OS in different PCs: Windows 8, Windows 7 and Debian, all x64. Also tried with three different versions of OpenCV.

Example of Positive list. Paths are OK.

rawdata/image105.bmp 1 22 26 40 68

rawdata/image106.bmp 1 21 27 42 72

rawdata/image107.bmp 2 19 26 43 69 20 29 42 67

Also tried adding and removing lots of parameters, image sizes, paths... nothing works. Every attempt finish with "unable to allocate memory", "insufficient memory" or simply crash. image description image description

The fact that it happens in three different PCs, OSs and OpenCV versions makes me think there's a problem with .vec, createsamples or some step before training.

Tree directory is: image description

.bat or .sh files to run previous commands are placed in the root of that tree.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
5

answered 2013-12-11 06:17:02 -0500

Ok the crutial mistake that you are making is trying to train a model of 90x140 pixels with that size of training data. Assuming that you can calculate +- 150.000 unique haar features of a 24x24 image, and the amount rises exponentially, the number at your range is huge. The algorithm has to store all of these features inside your working memory, which causes it to crash.

Suggestions I make to students are, keep your ratio's correct but use the createsamples utility to resize the images to a smaller size, which still contains more than enough features.

For example in your case, give parameters -w 9 -h 14 or double that to even -w 18 -h 28. The model will do exactly what it is supposed to do and the training will go fine. Also, the model size defines the smallest object you can detect in the image. So training it at a smaller size, enables you to actualle correctly detect smaller instances.

Once you perform detection, you can limit the scale space pyramid by specifying minSize and maxSize parameter of the detection algorithm.

edit flag offensive delete link more

Comments

Thanks! Now it don't crash, but freezes after one second at "Stage 7":

===== TRAINING 5-stage ===== <BEGIN POS count : consumed 10 : 10 NEG count : acceptanceRatio 10 : 0.000450511 Precalculation time: 0 +----+---------+---------+ | N | HR | FA | +----+---------+---------+ | 1| 1| 0| +----+---------+---------+ END>

===== TRAINING 6-stage ===== <BEGIN POS count : consumed 10 : 10 NEG count : acceptanceRatio 10 : 6.15665e-006 Precalculation time: 0 +----+---------+---------+ | N | HR | FA | +----+---------+---------+ | 1| 1| 0| +----+---------+---------+ END>

===== TRAINING 7-stage ===== <BEGIN POS count : consumed 10 : 10

Thanks one more time!

Ralcaidev89 gravatar imageRalcaidev89 ( 2013-12-11 10:20:36 -0500 )edit
1

Actually that is because you have not enough negative samples to pick from. At each stage it looks for unique negative samples that haven't been classified before. Either lower the stages or add more training data.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-12-12 06:05:42 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-12-11 04:51:38 -0500

Seen: 2,116 times

Last updated: Dec 11 '13