Cascade Classifier Training – FAQ, Known Issues and Workarounds

After receiving almost the same questions about Cascade Trainer GUI application all over again from many different users, I realized that it will be much more useful for anyone with a similar question, and much more efficient for me to actually compile a list of frequently asked questions, all the known issues and error and warning messages and try to answer them all in one place. Here is the result.

Question: What is the price of Cascade Trainer GUI and what are its possible limitations?

Answer: Cascade Trainer GUI is provided free of charge and without warranties of any kind. Just mention it as the application used for training your classifiers and you should be fine.

Question: What does this error mean and how to get around it? “Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.”

Answer: This is probably the one that is asked the most and I have written a whole post about it. Click here for more.

Question: How to fix this error? “Insufficient memory (Failed to allocate X bytes) in cv::OutOfMemoryError”

Answer: First of all, make sure you have enough memory on your computer. Second, make sure you set buffer sizes according to your available memory. In the example picture below, I assume we have at least 2 GBs available and I assign 1 GB of RAM to each one of the buffer types. Note that available memory is not the total memory. In this example I should have 4 GBs of RAM or something similar to that to be able to safely assign this much memory to the buffers.

Question: I received this message and the training stopped, what should I do? “Required leaf false alarm rate achieved. Branch training terminated.”

Answer: You can play around with the following parameters, but essentially what this error means is that there’s no point in further training since the required accuracy and performance and related settings are already reached, so the training stopped.

To further explain for people interested in more details I’ll be sharing the piece of code from OpenCV which is responsible for this error message and I think it pretty much speaks for itself:

for( int i = startNumStages; i < numStages; i++ )
cout << endl << "===== TRAINING " << i << "-stage =====" << endl;
cout << "<BEGIN" << endl;

if ( !updateTrainingSet( requiredLeafFARate, tempLeafFARate ) )
    cout << "Train dataset for temp stage can not be filled. "
            "Branch training terminated." << endl;
if( tempLeafFARate <= requiredLeafFARate )
    cout << "Required leaf false alarm rate achieved. "
            "Branch training terminated." << endl;
if( (tempLeafFARate <= acceptanceRatioBreakValue) && (acceptanceRatioBreakValue >= 0) ){
    cout << "The required acceptanceRatio for the model has been reached to avoid overfitting of trainingdata. "
            "Branch training terminated." << endl;


Question: I am facing issues with my images and their formats. What do I need to do?

Answer: You can try converting all your images to JPG to be on the safe side. Use the following article to see how you can batch convert your images and prepare them for training.

Question: What operating systems are supported by Cascade Trainer GUI?

Answer: At the moment, only Windows operating systems are supported.

Question: I’m getting errors similar to the following and the training doesn’t even star. What is the reason and what is the workaround?

*************** CREATING SAMPLES *****************
Fixing file names in negative images folder.
Fixing file names in positive images folder.
Creating negative list %%PATH_TO THE_OBJECT%%/neg.lst
Creating positive list %%PATH_TO THE_OBJECT%%/pos.lst
Running : opencv_createsamples
OpenCV Error: Assertion failed (ssize.width > 0 && ssize.height > 0) in cv:
:resize, file opencv\modules\imgproc\src\imgwarp.cpp, line 3492

************* TRAINING CLASSIFIER ****************
Running : opencv_traincascade
OpenCV Error: Parsing error (wrong file format for %%PATH_TO THE_OBJECT%%\pos_samples.vec
) in CvCascadeImageReader::PosReader::create, file opencv\apps\traincascade\imagestorage.cpp, line 141

Answer: Check if the path to the object (%%PATH_TO THE_OBJECT%% in the preceding log output) contains any Non Standard Latin characters. If so, rename the path, or move the object to a folder without any non Latin characters.

Question: When I try to run Cascade Trainer GUI, I’m receiving errors related to missing MSVCP140.dll, such as the one below:

The program can't start because MSVCP140.dll is missing from your computer.

Answer: Try Installing Microsoft Visual C++ 2015 Redistributable packages. You can download them from this link. Use vc_redist.x64.exe with 64 bit version and vc_redist.x86.exe with 32 bit version.

Question: I’m seeing this error when I try to train a classifier:

Can't create list file (Some Path)

Answer: Either use a folder for training that doesn’t require elevated (administrator) privileges, or run Cascade Trainer GUI as Administrator. (The second method is not recommended)

Question: Tips on Positive and Negative samples?

Answer: Use as many samples as you can but focus on the quality of data. The quantity is important but if you have too many too similar samples you’ve end up with an inaccurate classifier. Positive samples must ONLY contain the object that needs to be detected, with a little bit of background visible in them, and make sure the aspect ratio of all positive samples are identical (they can have different sizes). This means even if the object is rotated, include more background and keep the aspect ratio the same for all samples. Here are some examples that show positive samples of a traffic sign:

On the other hand, negative samples can have any size or shape or aspect ratio, just make sure they don’t contain the object in the positive samples at all. Here are a couple of examples:

34 Replies to “Cascade Classifier Training – FAQ, Known Issues and Workarounds”

  1. Hello Sir I have been watching your videos for the past one month and I have learned a lot. But for creating my custom Haar cascade I have been facing a problem. When I press start training a error shows that says can’t rename img. And every time I click on it it show a different image and says can’t rename it.
    How can I solve this problem, please let me know as soon as possible.|
    You are doing a great job.

    1. Make sure your files are in a folder without any access issues and that they don’t have non-Latin characters in file names.

  2. Using a lot of similar images with a small diferences make the detecction most impresise?
    (Google translator).

    Usar várias imagens similares mas com pequenas diferenças torna a detecção imprecisa?

    1. Try to use real or synthesized samples from the actual environment you want to do the detection in.
      On a separate note, it depends on how “small” the differences are.

  3. Hello,

    What should be the ratio of positive images to negative images, means, whether the no. of negative image should be equal as positive image?

    1. There’s no empirical ratio. Just get as much as you can for both positive and negative images.
      Theoretically, having more negative images will help decrease false negative results, meaning your classifier will perform better with negatives, and vice versa.
      Also, the ratios of training, validation or test datasets should match.

    1. Make sure your images are not in a folder that might require Admin permissions. This is simply related to access issues with the image.

  4. Hi Dr. Amin,
    I used low buffer bcs the error of number 52 that I mentioned to at first comment, and the memory size is around 7GB.
    For note, I am using videos with 1280*920 with ROI sizes around 200*150!
    Should I need to reduce it to 720*600 for example , then the ROIs will be small to make the process success??

    Best regards,

    1. If by ROI you mean sample width/height parameters of the cascade classifier, then you should know that’s an insanely huge size. Go for 20×15 instead. Or if you must, 40×30, but not 200×150. It will be painfully slow.
      Cascade classifiers are scale invariant so you shouldn’t care about the ROI size really.
      And resizing your source video frames to a smaller size will definitely improve detection speed of the classifier, but has nothing to do with the training process.

      1. Hi Dr. Amin,
        Thanks for your notes and communication. Now its work and got a good results but need some modifications to the data-set.
        Best regards,

  5. Yes, I Checked and I applied all things mentioned, and I got some problems such as:
    1- when I change memories size to be very low as 512, the process finished correctly but without any results, I mean there is no clasifer.xml

    2- when I change the method to HOG or LP, the process finished with 3 or 5 stage only with the msg: “Required leaf false alarm rate achieved. Branch training terminated.”

    3- when I apply the classifer.xml from 2 above on the video for testing, it failed.

    So, plz , I u have any updating way or new method to be tried.??
    also, I have no information about the parameters and how can the changed to get a better results.

    with my thanks and best regards.

  6. Thanks for your nice program.

    I found something is not going well. It draws many additional boxes what I don’t expect. For example, it draws boxes at numbers. So I’d like to use labeling information like x,y,w,h for training p and n images well. It’s going to draw boxes at right location.

    Please keep me posted.




    1. It’s not clear what you mean, but simply put: You need to put positive samples in p folder and negative ones in n folder and train. Cascade Trainer GUI includes a cropper to help you with creating samples, NOT labeling if you mean something like annotation.

  7. Hi, what decides the number of positive training samples that are created by opencv_createsamples? I’m familiar with how generating positive samples using opencv_createsamples on the command line allows us to pass the number of samples to be created from our original set of positive images (which may only be a few) but I don’t find any such option on the GUI tool. Is it just 1:1 (the number of positive samples = number of positive images in “p” directory)?

      1. Can this be changed to get more test samples than the number of “p” images? As the main purpose of using opencv_createsamples is to automatically generate lots of samples from a few positives. If there is anything I can change in how the GUI is run, to achieve the above, please let me know.

        1. Of course it can be changed, it’s just a matter of priorities at the moment.
          For the time being as a workaround though, you can create a tool that generates samples from a single image and saves it into “p” folder. Then you can use Cascade Trainer GUI to train using graphical tools if you need.

  8. I have a question about using cascade trainer GUI – How can I properly stop (pause) and resume the training later? Despite loading the same .ini setting file, it just started from scratch.
    The resuming function is crucial for me when I have to deal with 2700 pos and 6900 neg, which means taking a good amount of time, and I don’t always have time to leave program running for 6 hours or more.

    1. That’s a fair point, but unfortunately Cascade Trainer GUI currently does not support resume when training is stopped manually. You’ll have to leave it running.

  9. Despite the 16GB of free RAM and default training, I get the following error:

    OpenCV Error: Insufficient memory (Failed to allocate 1242859764 bytes) in cv::OutOfMemoryError, file D:\cv\opencv_3.2.0\sources_withTextModule\modules\core\src\alloc.cpp, line 52

    What can I do?

          1. OpenCV Error: Insufficient memory (Failed to allocate 661040372 bytes) in cv::OutOfMemoryError, file D:\cv\opencv_3.2.0\sources_withTextModule\modules\core\src\alloc.cpp, line 52

            I am using HD video, ROI size around 200*200
            Plz, If u have some solutions????
            best regards

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.