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: 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:



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

  1. Running : opencv_traincascade
    OpenCV Error: Parsing error (wrong file format for C:\Users\beek6\OneDrive\Masa�st�\objectsnota\pos_samples.vec
    ) in CvCascadeImageReader::PosReader::create, file D:\cv\opencv_3.2.0\sources_withTextModule\apps\traincascade\imagestorage.cpp, line 141

  2. I have a question regarding the Cascade Trainer GUI Version 3.3.1. I’ve been trying to create a new haarcascade xml utilizing the GUI software but each time, it only creates the following files: neg.lst, pos.lst, and pos_samples.vec. None of the other program files are generated inside the classifier folder except the standard log.txt file. So I am at a loss as to the specific issue here. I have been utilizing the standard settings on the Boost tab. Any help with this would greatly appreciated.

  3. Hi. I made a cascade, but when i try to test it it is saying that the test is complete, but result images is just the same as the ones i put in the program. No markups or detected objects in it. Is it a problem with cascade which i made or is it a problem with photos that im using(jpeg type, no non latinian symbols in file name, all photos are in main program folder)?

    1. Unfortunately the question is too general, just follow the instructions carefully.
      Sorry I can’t help you out with this.

  4. im getting an eror, cant rename file and make sure its not being used, even though i close everything

      1. Dear Amin,
        thank you for your job !

        How we can help you ?

        There is a issue with non latin character, exactly, that should be easy to fix it.

  5. Hi Amin thanks for your amazing work,

    is there a Ubuntu or MacOs version of your Cascade Trainer app?

    Thanks.

  6. Is there a way to create a cascade from a partial training using the stage files. I know it is possible but I can’t find a way to do it with the gui.

  7. OpenCV Error: Bad argument (Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.
    ) in CvCascadeImageReader::PosReader::get, file D:\cv\opencv_3.2.0\sources_withTextModule\apps\traincascade\imagestorage.cpp, line 158

    I am having this error. Please help me out!!!!!!!!!!!!!!!!!!!!!

  8. I have encountered this error pls help
    Train dataset for temp stage can not be filled. Branch training terminated.
    Cascade classifier can’t be trained. Check the used training parameters.
    my parameters are
    Running : opencv_traincascade
    PARAMETERS:
    cascadeDirName: E:\project\classifier
    vecFileName: E:\project\pos_samples.vec
    bgFileName: E:\project\neg.lst

    numPos: 88
    numNeg: 92
    numStages: 20
    precalcValBufSize[Mb] : 1024
    precalcIdxBufSize[Mb] : 1024
    acceptanceRatioBreakValue : -1
    stageType: BOOST
    featureType: HAAR
    sampleWidth: 24
    sampleHeight: 24
    boostType: GAB
    minHitRate: 0.995
    maxFalseAlarmRate: 0.5
    weightTrimRate: 0.95
    maxDepth: 1
    maxWeakCount: 100
    mode: BASIC
    Number of unique features given windowSize [24,24] : 162336

    1. That sounds odd for sure, but in general everything depends on your parameters.
      Have you changed any parameters instead of using default values? Can you share the params you used?

  9. Hi,

    First off I would like to say thank you for this, a lot of the specifics of this currently goes over my head. I just finished going through everything and it creates the pos.lst, neg.lst, and pos_samples.vec fine, but when it gets to the spot where it begins training the classifier I run into this issue:

    Running : opencv_traincascade
    OpenCV Error: One of arguments’ values is out of range (The total matrix size does not fit to “size_t” type) in cv::setSize, file D:\cv\opencv_3.2.0\sources_withTextModule\modules\core\src\matrix.cpp, line 324

    Do you have any insight into what this may be?

    Thanks for the help,
    Will

    1. Two questions,
      1. what parameters did you change or is everything default?
      2. Do you have any extremely big or very small images?

      Try with a very small dataset of images that you have gone through and you are sure have no issues and then move on from there.
      You can come back and answer to this comment when you’re done.
      Good luck.

  10. Hi, when I start program and start training, I’m browsing the pictures path and click Start, however this message appears at my screen;
    n folders not found at C:/Users/pc/Desktop/…
    what should I do? Thanks.

  11. i get that memory error (How to fix this error? “Insufficient memory (Failed to allocate X bytes) in cv::OutOfMemoryError”)
    i have 24GB of ram installed with my 1660TI GPU, i don’t know why (Failed to allocate 2147492516 bytes) when i only use 1024 MB.
    my p folder have <20MB
    my n folder have <20MB
    all consist of images

  12. Can you stop and continue Cascade training? it is possible to stop the training and start from where we stopped. For an example, I put the training on and it works, and turn it off at night so I can shutdown the PC, then turn it on again it in the morning and it continues the training from where it stopped. Is this is possible?

      1. Mr.Amin can you please make a tutorial explaining how to exactly use this Cascade trainer to make custom cascade files, it will be very useful to various hobbyists like me 🙂

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

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

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

  16. 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,
        Hasan

  17. i am getting an error saying unable to rename the images although everthing else is closed

  18. 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.
    Hasan

  19. 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. So can I input labeling information in your program or additional files which is created by program?

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

  20. 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. Yes, as you figured it out yourself, the number of images in “p” folder will be the final number of positive samples.

      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.

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

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