Ask Your Question
1

error in train casacde

asked 2013-07-16 21:20:02 -0500

Pinky gravatar image

updated 2013-07-22 00:20:02 -0500

Hi I am having an error saying "Train dataset for temp stage can not filled. Branch training terminated. Cascade Classifier can't be trained. check the used training parameters" when I am trying to do training. I used 50 positive and 100 negative images. I saw a similar question here . My bg.txt file is already in the form mentioned in that solution but still having the error.

my console output was as follows-

C:\Users\Administrator\Documents\Visual Studio 2010\Projects\cv_traincascade\Debug>cv_traincascade.exe 
-data test -vec positives.vec -bg infofile.txt -numPos 50 -numNeg 100 -numStages 20 -precalcValBufSize 1024 
-precalcIdxBufSize 1024 -w 24 -h 24


PARAMETERS:
cascadeDirName: test
vecFileName: positives.vec
bgFileName: infofile.txt
numPos: 50
numNeg: 100
numStages: 20
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
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
===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   50 : 50
Train dataset for temp stage can not be filled. Branch training terminated.
Cascade classifier can't be trained. Check the used training parameters.

strong text Can you please say what is wrong in my command? any help will be appreciated. thank you.

my directory info- C:\Users\Administrator\Documents\Visual Studio 2010\Projects\cv_traincascade\Debug

cv_traincascade.exe

positives.vec

negative

infofile.txt

context of infofile is al follows-

negative/UMD_001.jpg
negative/UMD_002.jpg
negative/UMD_003.jpg
negative/UMD_004.jpg
negative/UMD_005.jpg
negative/UMD_006.jpg
negative/UMD_007.jpg
negative/UMD_008.jpg
negative/UMD_009.jpg
negative/UMD_010.jpg

...

Here is the zip file of the directory https://docs.google.com/file/d/0B90iLkzk5IUrbXI3dkRsZFdEVGc/edit?usp=sharing

edit retag flag offensive close merge delete

Comments

Parameter which you passed is "preCalcValBufSize" while it should have been precalcValBufSize. Similarly in the case of "precalcIdxBufSize". Its a sad thing that the parameters are not checked by the program. Double check your bg file too.

Prasanna gravatar imagePrasanna ( 2013-07-17 01:43:49 -0500 )edit

Hi Prasanna, Thanks for your reply I changed this 2 parameters but still getting the error.

Pinky gravatar imagePinky ( 2013-07-17 02:14:05 -0500 )edit

Wrong parameters are no problem, they are just skipped, leaving you with the initial values, which should give no problem. So what @Prasanna pointed out can't be your problem. Can you publish a part of your infofile.txt file. I have the impression that he doesn't succeed in getting negative images. Also how did you create your positives vec file, single image with rotation stuff? Or based on original images only?

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-17 02:57:22 -0500 )edit
1

Also if you have exactly 50 positive images, try changing it to 40, because you always use the 0.9*effective_number rule, just to make sure that he can still get new positives if needed.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-17 03:00:17 -0500 )edit

Also did you check if you are using front slashes or double backslashes? On some systems, backslash is an escape character, which will lead to the impossibility to read the bg.txt file and recover images.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-17 03:03:21 -0500 )edit

I have tried using front slahes, back shales, doubles slashes.. but for every cases it gives same error.

Pinky gravatar imagePinky ( 2013-07-17 03:25:51 -0500 )edit

Ok can you create a zip file containing the folder structure and data? Let me see what goes wrong by testing it out. Place the link to your downloads here.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-17 03:36:23 -0500 )edit

Also, it could be your system filename becomes to long or can't contain slashes. Create a folder test on your root drive, then copy all the data and see if error still occurs.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-17 03:38:39 -0500 )edit
1

Wait a sec. I didn't point that out as a solution to the actual problem. My guess is to try passing paths with a " ./ " preceding it. So it should look like ./negative/UMD_001.jpg . Tell me if it works.

Prasanna gravatar imagePrasanna ( 2013-07-17 04:07:37 -0500 )edit

@Prasanna thanks for your reply I tried using "./" but it does not work.

Pinky gravatar imagePinky ( 2013-07-17 20:42:34 -0500 )edit

5 answers

Sort by ยป oldest newest most voted
1

answered 2013-07-17 03:08:17 -0500

I did some background checking of the current OpenCV2.4.6.1 source code. Your problem is exactly that he cannot read the negative files, so there is actually something wrong with your bg.txt file.

Looking at cascadeclassifier.cpp we see this code:

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

        if ( !updateTrainingSet( tempLeafFARate ) )
        {
        cout << "Train dataset for temp stage can not be filled. "
            "Branch training terminated." << endl;
        break;
    } 
    ...

This says clearly that the problem must be at the updateTrainingSet function for the first iteration. If we dig deeper, we can see this code:

bool CvCascadeClassifier::updateTrainingSet( double& acceptanceRatio)
{
    int64 posConsumed = 0, negConsumed = 0;
    imgReader.restart();
    int posCount = fillPassedSamples( 0, numPos, true, posConsumed );
    if( !posCount )
        return false;
    cout << "POS count : consumed   " << posCount << " : " << (int)posConsumed << endl;

    int proNumNeg = cvRound( ( ((double)numNeg) * ((double)posCount) ) / numPos ); // apply only a fraction of negative samples. double is required since overflow is possible
    int negCount = fillPassedSamples( posCount, proNumNeg, false, negConsumed );
    if ( !negCount )
        return false;

    curNumSamples = posCount + negCount;
    acceptanceRatio = negConsumed == 0 ? 0 : ( (double)negCount/(double)(int64)negConsumed );
    cout << "NEG count : acceptanceRatio    " << negCount << " : " << acceptanceRatio << endl;
    return true;
}

If you look at that code and your output, you clearly see that the positive samples are fetched and this works. The only other way of returning a false in this function, is if negCount has no value, meaning that the fillPassedSamples function doesn't work on your data :)

So please put your bg.txt file and all your path related info inside your question.

edit flag offensive delete link more

Comments

1

I have updated the question with bg.txt file info and the related path

Pinky gravatar imagePinky ( 2013-07-17 03:24:48 -0500 )edit
1

answered 2013-07-18 02:47:43 -0500

Ok so new answer. First of all, you are still using OpenCV2.4.3 since that is the dll type the exe requires when I am starting up your training system. I have switched to OpenCV2.4.6 (do this also) and compiled against the newest libraries, used the training algorithm on your data and it works perfect.

Be sure that your result folder is manually created before running the algorithm, else it cannot write data to it.

Here you can find the command I used to start the training, and the actual result of the first 2 and a half stages.

image description

image description

Don't mind the fact that you will not get the calculation time for the previous stage, it is something that I adapted in the source code, in order to see how my progress was going.

edit flag offensive delete link more

Comments

hi Steven !! thank you for your time.. I tested it with opencv2.4.6 also still having same error. here is the new .exe file and all data. can you please check with my .exe file. https://docs.google.com/file/d/0B90iLkzk5IUrbXI3dkRsZFdEVGc/edit?usp=sharing

Pinky gravatar imagePinky ( 2013-07-18 21:00:21 -0500 )edit

:'( :'( :(

Pinky gravatar imagePinky ( 2013-07-18 21:15:12 -0500 )edit

Can you tell me what system you are using, because I am using windows 7 x64 bit and your application just crashes on launch, so I guess you have used 32 bit dlls?

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-19 02:57:15 -0500 )edit

HI steven !! yes my system is windos 7, 32 bit .

Pinky gravatar imagePinky ( 2013-07-21 20:19:14 -0500 )edit

Do you have any suggestion what should I do ?

Pinky gravatar imagePinky ( 2013-07-21 22:59:38 -0500 )edit

Hmm that will be difficult. I can't seem to run your executable. Guess there is still something wrong with your traincascade file. Did you build that latest version of it? 2.4.6?

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-22 00:55:12 -0500 )edit

Yes I build it with the 2.4.6 version.

Pinky gravatar imagePinky ( 2013-07-22 01:50:12 -0500 )edit

Let me try to rebuilt the training tool myself here on x64 bit and see if something changed in between versions ...

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-22 01:54:16 -0500 )edit

Hmmm after trying the latest version, it seems training starts with me, but ends with a crash instead of an error like you. Lemme check what could go wrong :) I guess you might just help me discover a bug :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-22 02:20:00 -0500 )edit
1

Ok do me a pleasure. For one reason or the other, building a new traincascade on your data fails on me too. I have made some adaptations to my traincascade, because of infinite loops, and that ones still works perfectly, based on openCV 2.4.5. I will give you a link with the code I used for compiling, please check if it works... Ill go processing the errors later then. Just a sec!

StevenPuttemans gravatar imageStevenPuttemans ( 2013-07-22 02:41:46 -0500 )edit
1

answered 2015-09-17 22:34:07 -0500

Frank_Tan gravatar image

I found it has some empty lines in the end of your infofile.txt. It maybe the answer.

edit flag offensive delete link more
0

answered 2015-01-16 08:23:20 -0500

Nann Nguyen gravatar image

Hi, I had this similar problem which gives error:

POS count : consumed   50 : 50
Train dataset for temp stage can not be filled. Branch training terminated.

The problem was that, my bg.txt was generated in a Windows system using \r for next line. When I tried to use opencv_traincascade in Ubuntu, it read '\r' into the string for filelist, thus in CvCascadeImageReader::NegReader::nextImg() , the line src = imread(imgFilenames[last++], 0); did not work.

My fix was to add str.erase(std::remove(str.begin(), str.end(), '\r'), str.end()); before imgFilenames.push_back(dirname + str); in imagestorage.cpp

I hope this helps.

edit flag offensive delete link more
0

answered 2016-03-05 01:51:16 -0500

Hi Pinky, I met the same problem with you, how would you solve the problem? If the solution of it, can you tell me the solution, thank you!

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-07-16 21:20:02 -0500

Seen: 10,945 times

Last updated: Jul 22 '13