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;
    break;
}
if( tempLeafFARate <= requiredLeafFARate )
{
    cout << "Required leaf false alarm rate achieved. "
            "Branch training terminated." << endl;
    break;
}
if( (tempLeafFARate <= acceptanceRatioBreakValue) && (acceptanceRatioBreakValue >= 0) ){
    cout << "The required acceptanceRatio for the model has been reached to avoid overfitting of trainingdata. "
            "Branch training terminated." << endl;
    break;
}

...


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.

https://amin-ahmadi.com/2019/05/29/batch-convert-and-resize-images-using-picture-stamper/

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 *****************
**************************************************
Object : %%PATH_TO THE_OBJECT%%
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: 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:



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

  1. 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.

    Thanks.

    Regards,

    Jack

    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.

  2. 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.

  3. 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.

  4. 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?

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.