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:



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

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