Ask Your Question
1

Cascade Training: killed and bad_alloc

asked 2014-02-24 11:14:29 -0600

Rolo gravatar image

Hi everyone,

I have OpenCV 2.4.7 installed on Amazon Linux (similar to Centos 6 - 64-bit). I've been following several tutorials online to create haar cascade classifier files, but have run into issues with both commands: opencv_traincascade and opencv_haartraining

In my experiments I have 40 positive images and 664 negative images (all cropped to w=300 h=100).

The tutorial used for generating samples etc. was found here: http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html

1) Command: opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 40 -numNeg 664 -w 300 -h 100 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024

Result: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted

2) Command: opencv_haartraining -data classifier -vec samples.vec -bg negatives.txt -nstages 20 -minhitrate 0.995 -maxfalsealarmrate 0.5 -npos 40 -nneg 664 -w 300 -h 100 -mode ALL

Result: Stuck at stage 0 and the script simply returns the word "Killed"

Any help of experience anyone can share would be greatly appreciated. Please also respond if you believe I need to supply more information. New to cascade training.

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-02-24 13:02:00 -0600

Hi Mark,

The error std::bad_alloc occurs when you fail to allocate required storage space.

1)you need to reduce the size of positive and negative images.Max preferable dimension is width=100 and height=100.It would be really good if you could resize them to be around w=20 and h=20.

2)Try to set numPos = 0.9 * number_of_positive_samples and 0.99 as a minHitRate

3)vec-file has to contain >= (numPose + (numStages-1) * (1 - minHitRate) * numPose) + S, where S is a count of samples from vec-file.S is a count of samples from vec-file that can be recognized as background right away.

4)To just test lightly on a temporary basis keep number of stages less(around 5-10).

5)It usually takes a lot of time to train,so be patient.

6)try this:

add -nonsym -mem 512 to your opencv_haartraining command

Again if you want you could refer to my blog:click here

Hope this helps you:)

edit flag offensive delete link more

Comments

Thank you so much for your response :) I've passed the bad_alloc error and while I'm not 100% certain I believe the secret sauce may have been the -nonsysm -mem 512 addition to the opencv_traincascade call.

I will follow up again once the training has completed.

Rolo gravatar imageRolo ( 2014-02-24 13:47:10 -0600 )edit

I'm using some C++ code to generate opencv_train_cascade command

opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 400 -numNeg 961 -w 80 -h 80 -mode ALL -precalcValBufSize 2048 -precalcIdxBufSize 2048

I get the "Killed error" and I tried to add -nonsym -mem 512, but I got

'C++ basic_string::_M_construct null not valid

It seems that such option is not accepted in training command (I haven't found it on official page, indeed). Any suggestion? thanks

biagio montesano gravatar imagebiagio montesano ( 2016-11-29 11:17:12 -0600 )edit

Question Tools

Stats

Asked: 2014-02-24 11:14:29 -0600

Seen: 6,405 times

Last updated: Feb 24 '14