Ask Your Question
3

Cascade Training Error OpenCV 2.4.4 - Train dataset for temp stage can not filled. Branch training terminated. Cascade Classifier can't be trained. check the used training parameters

asked 2013-04-06 02:41:49 -0600

Constantin gravatar image

Hi there! I used createsamples.exe to create my .vec file then I tried to use cascade training according to the OpenCV doc. But I came to this error:

PARAMETERS:

cascadeDirName: CassCade
vecFileName: Positive\ResistorP1.vec
bgFileName: Negative\NegSamples.txt
numPos: 150
numNeg: 150
numStages: 20
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
stageType: BOOST
featureType: LBP
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   150 : 150
Train dataset for temp stage can not be filled. Branch training terminated.
Cascade classifier can't be trained. Check the used training parameters.

I use this command for cascade training:

opencv_traincascaded.exe -data CassCade -vec Positive\ResistorP1.vec -bg N
egative\NegSamples.txt -numPos 150 -numNeg 150 -numStage 30 -featureType LBP -pr
ecalcValBufSize 1024 -precalcIdxBufSize 1024

my .vec size 2.25MB and number of positive samples created by opencv_createsamples.exe is 2000 and number of negative samples is mor than 600 .jpg files.I don't know what's wrong with it ! Thanks in advance! :)

edit retag flag offensive close merge delete

Comments

Hi, Constantin I am having same error. I changed my bg.txt as you told in the solution but still having the error. can you please help me with it?

Pinky gravatar imagePinky ( 2013-07-16 00:03:43 -0600 )edit

Hi Constantin, Did you get out of the problem .If yes ,can you please tell the solution to resolve the issue. Even i am facing the same Thanks

ART gravatar imageART ( 2014-02-03 22:14:11 -0600 )edit

Hi, I added an answer. my mistake was the one I mentioned. It worked for me!

Constantin gravatar imageConstantin ( 2014-02-05 05:39:40 -0600 )edit

I was also struggle with this problem a lot. I test run opencv_traincascade for linux on a raspberry pi 3 and thanks for the tip that the problem seem's to be in the bg.txt file I test lot of things in the bg.txt file and suddenly it start to work when I was add ./ before each file name so my bg.txt file look like this (when the background files are in same directory as opencv_tranicascade file is)

./0.JPG

./1.JPG

./2.JPG

./3.JPG

./4.JPG

./5.JPG

./6.JPG

and so on.... I also notice that there was important to have Not have any "invisible" obscure ASCII character in the bg.txt (when I export a colum from Excel it was add some invisible obscure ASCII ho mess up, then I generate a bg.txt from a C code ten it work fine)

Olle Welin gravatar imageOlle Welin ( 2016-04-08 14:59:14 -0600 )edit

//bg.txt generator

//Olle Welin [email protected]

include <stdio.h>

main() {

FILE *fp;

    printf("Generate a bg.txt file how work with raspberry pi for opencv_traincascade \n");

fp = fopen("bg.txt", "w+");

for(int i=0;i < 1000; i++) { fprintf(fp, "./%d",i);

   fprintf(fp, ".JPG\n");

} fclose(fp);

}

Olle Welin gravatar imageOlle Welin ( 2016-04-08 15:00:08 -0600 )edit

Thanks. I also got similar problem and solved. It was path problem with negative samples. Easiest way to solve path problem was to give full path in info file for negative images.

ghimire gravatar imageghimire ( 2017-03-08 19:35:11 -0600 )edit

5 answers

Sort by ยป oldest newest most voted
2

answered 2013-04-10 08:47:47 -0600

Constantin gravatar image

Finally done! Just notice that the path for negative examples should be relative to the current directory! I mean if my cascade_trainer.exe is in the G:\ML directory and my negative examples description file is in G:\ML\Negative\NegSamples.txt your entries should be in the this form:
my G: directory is:

G:
Positives dir
Negative dir
opencv_traincascaded exe

then my description file should be in this format:

\\computer 001.jpg

my command for the cascade is:

opencv_traincascaded.exe -data CassCade -vec Positive\ResistorP1.vec -bg Negative\NegSamples.txt -numPos 150 -numNeg 150 -numStage 30 -featureType LBP -precalcValBufSize 1024 -precalcIdxBufSize 1024

edit flag offensive delete link more

Comments

1

thanks @steven for his comments :)

Constantin gravatar imageConstantin ( 2013-04-10 08:48:43 -0600 )edit
1

Ok good for you. Indeed something I did not think of, but which is a critical point. This should also be added to the guide. BTW, please accept a solution, so that this topic appears as solved.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-10 09:06:15 -0600 )edit

Hi, you have build traincascade.exe using opencv2.4.5 or 2.4.6.? i'm using 2.4.5 and after displaying this below content

===== TRAINING 0-stage ===== <BEGIN POS count : consumed 100 : 100 NEG count : acceptanceRatio 300 : 1 Precalculation time: 5.915 +----+---------+---------+ | N | HR | FA | +----+---------+---------+ | 1| 1| 1| +----+---------+---------+ | 2| 1| 1| +----+---------+---------+ | 3| 1| 1| +----+---------+---------+ | 4| 1| 0.77| +----+---------+---------+ | 5| 1| 0.3| +----+---------+---------+ END> OpenCV Error: Unspecified error (Invalid fs.state) in unknown function, file .....\src\opencv\modules\core\src\persistence.cpp, line 5271 It is getting stoppped.

ART gravatar imageART ( 2014-02-03 23:46:23 -0600 )edit

@ART, pleace create a new question... this one has already been solved.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-04 01:56:09 -0600 )edit

Hi Steven, Here is my question pls look into it . http://answers.opencv.org/question/27653/unspecified-error-in-persistencecpp-during/ and can you tell me where i am doing wrong Thanks

ART gravatar imageART ( 2014-02-04 03:02:22 -0600 )edit
2

answered 2013-04-06 05:51:17 -0600

First guess, something is wrong with your bg.txt file. Can you check if the path matches the absolute path to your images?

edit flag offensive delete link more

Comments

I use this command on my windows: dir \b \s > NegSamples.txt does it matter the size of the images in the negative samples or their foramts? Do i need to install IPP or TBB ?

Constantin gravatar imageConstantin ( 2013-04-06 07:44:06 -0600 )edit

Most common formats I know of are all supported (ppm, tif, png, jpeg, bmp) and about size, they should be at least the size of the window, not smaller.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-06 08:56:26 -0600 )edit

they are bigger than size of the windows!

Constantin gravatar imageConstantin ( 2013-04-06 09:04:58 -0600 )edit

I found a first error in your command, it states -numStage without the S, since you specify it as 30 and the output states there only 20 selected. It can be that the wrong parameter is read and the algorithm states that it cannot be. Change it to -numStages 30 please and see if it works now?

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-06 09:09:52 -0600 )edit

Thanks! But it didn't work? Is it possible that the problem raise from the .vec file? my bg images is really large about 1900*1900?

Constantin gravatar imageConstantin ( 2013-04-06 09:18:47 -0600 )edit

I checked the code for the cascadeclassifier.cpp, where the error thrown is here: if ( !updateTrainingSet( tempLeafFARate ) ) { cout << "Train dataset for temp stage can not be filled. " "Branch training terminated." << endl; break; }

Constantin gravatar imageConstantin ( 2013-04-06 09:36:45 -0600 )edit

I checked the code for negReader, It can not open my NegSamples.txt file that is description text file? some lines of my file is as follows : .... G:\ML\Negative\animals_friends_9.jpg G:\ML\Negative\aUP28275.jpg G:\ML\Negative\bb.jpg G:\ML\Negative\computer 001.jpg G:\ML\Negative\computer 002.jpg G:\ML\Negative\computer 003.jpg ....

what is wrong with my decription file? :!

Constantin gravatar imageConstantin ( 2013-04-09 12:55:42 -0600 )edit
1

Basically a negative descriptor file should like like this G:\ML\Negative\animals_friends_9.jpg G:\ML\Negative\aUP28275.jpg G:\ML\Negative\bb.jpg

With new line for each entry

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-09 13:12:48 -0600 )edit

Yes it is! new line for every entry, but got the same error!

Constantin gravatar imageConstantin ( 2013-04-09 13:30:59 -0600 )edit
2

Try using front slashes. Some compilers look at backslashes as escape character. It sometimes ruins your execution.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-09 13:37:08 -0600 )edit
1

answered 2015-01-16 08:25:23 -0600

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. I also posted the similar answer here : http://answers.opencv.org/question/16... .

edit flag offensive delete link more

Comments

You could switch EOL conversion with Notepad++ (Edit and Save).

mrfromage gravatar imagemrfromage ( 2016-07-15 03:31:11 -0600 )edit
1

answered 2016-01-10 23:07:25 -0600

LuciferSam gravatar image

I had the exact same problem. The issue for me was that I created my negatives.txt file using PowerShell which writes a BOM to the file. The BOM trips up the opencv_traincascade program when it tries to read the file and causes it to not find any of the images. I converted the file to UTF-8 using Notepad++ and that fixed the issue.

edit flag offensive delete link more
0

answered 2014-06-30 07:54:17 -0600

keyvan gravatar image

I this get this error , too. I try with older version of haartraning.exe and worked but with traincascade.exe in opencv 2.4.6 dont work . plz help i want lbp classifiction. any body know what this problem occured ???

haartraining.exe -data data -vec pos.vec -bg bg.txt -npos 500 -nneg 500 -w 48 -h 24 older traincascade.exe -data data -vec pos.vec -bg bg.txt -numPos 500 -numNeg 500 -w 48 -h 24 newer

edit flag offensive delete link more

Comments

1

Please, move to your own topic, reviving old ones won't help anyone here. Supply full information and wait for people to help you there. Do know that haartraining and traincascade DO NOT have the same setup, they are different tools so please look closely at their documentation.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-06-30 07:57:35 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-04-06 02:41:49 -0600

Seen: 29,133 times

Last updated: Jun 30 '14