Problems with Traincascade: A Practical Problem

asked 2013-10-15 08:45:40 -0500

updated 2013-10-15 10:23:40 -0500

In the past few days I've been investigating the createsamples and traincascade methods in order to generate a car cascaded classifier. Such as myself, many people find themselves not having a clue about how to get past all the errors and problems, so in this post I'll explain my procedure and reasoning as well as I can, as well as my problem.

To give a little more context, in the past I implemented myself a boosted classifier with Haar features but since the method was not cascaded it was very slow. I am, however, very well acquainted with the method behind the cascaded classification.

Problem: Car classification on images

I downloaded a dataset (set of images) that provides 550 positive windows (100w x 40h images with cars) and 500 negative windows (100w x 40h images without cars), and I intend to use this data to train the cascaded classifier.

STEP 1 - Generate the .dat files for creating samples

The createsamples application needs a .dat file with the information about the positive and negative samples. I generated two .dat files, one with positive windows and other with negative windows:

positive.dat example structure:

CarData\TrainImages\POS\pos-0.pgm 1 0 0 100 40

CarData\TrainImages\POS\pos-1.pgm 1 0 0 100 40 (and more 548 lines of this)

The number 1 indicates that there is one object in the entire image, and the next 4 integers represent the bounding box that has the object (the entire image in this example)

negative.dat example structure:


CarData\TrainImages\NEG\neg-1.pgm(and more 498 lines of this)

STEP 2 - Generate .vec files

To do this I use the createsamples.exe application with the following command line:

: createsamples.exe -info path/positive.dat -vec samples.vec -bg negative.dat -w 100 -h 40 -num 550

So far so good, the samples.vec file is generated with no issue.

STEP 3 - Train the cascaded classifier

To do this I use the traincascade application with the following command line:

: traincascade.exe -data CarDetector -vec path/samples.vec -bg path/negative.dat -numStages 15 -stageType BOOST -featureType HAAR -w 100 -h 40 -bt DAB -maxDepth 2 -mode ALL


numStages(15): means that I want my classifier will have 15 decision stages.

stageType(BOOST): each stage is a boosted classifier

featureType(HAAR): use haar features for classification. HOG and LBP also available.

w(100): detection window width

h(40): detection window height

bt(DAB): means I want to use Discrete Adaboost (rather than logitboost and others)

maxDepth(2): means each weak classifier will use 3 features for classification

-mode(ALL): I think it means it will use all variety of haar features.


When I run the command, the program crashes immediately with no error message, so I am completely clueless as to what I am doing wrong. I'm hoping that someone experienced in this matter will identify the problem with my procedure, as this is an ... (more)

edit retag flag offensive close merge delete


hey, you would have been the first person not having problems here. it is a difficult topic.

now, since it seems, you're using vs; you could try to remote debug it.

  • start your program, let it crash like in the pic above. don't press any button.
  • in vs, go to debug -> attach to process and select your prog from the list.
  • now press the 'retry' button in the errorbox. with a bit of luck, the debugger should jump to the offending code.

btw, very nice writeup. hopefully your effort pays out ( and not only for you )

berak gravatar imageberak ( 2013-10-15 09:02:48 -0500 )edit

Yes, I am on Visual Studio 2012 with Windows 8.

Already tried that, unfortunately with no luck

Pedro Batista gravatar imagePedro Batista ( 2013-10-15 09:24:01 -0500 )edit

@Median did you manage to solve the problem or get a meaningful error message via VisualStudio?

samkhan13 gravatar imagesamkhan13 ( 2013-10-23 05:00:32 -0500 )edit

I didn't completely solve this problem, since it didn't do what I wanted, but I did manage to train a classifier. First of all, I could not use the traincascade method, but I ended up getting the older haartraining.exe method to work. To make it work I had to call the haartraining.exe method with slightly less positive samples than the ones I used to generate the .vec file. I used 550 positive samples, and if I tried to generate a classifier using those 550 samples it would crash right at start. The trick was to use the -nPos input argument in the haartraining.exe call with slightly less positive samples than I actually had (500 did the trick). Another problem was the size of the positive samples. 100x40 wouldn't work, I think the method really wants positive samples to be a square.

Pedro Batista gravatar imagePedro Batista ( 2013-10-23 06:21:11 -0500 )edit

Hi Median, did you get training done with traincascade?? if yes , can you guide how?? thanks

ART gravatar imageART ( 2014-02-19 05:51:17 -0500 )edit