AdaBoost训练出现问题:Train dataset for temp stage can not be filled

时间:2024-04-10 20:20:14
AdaBoost训练出现问题
F:\boost5>cd bin


F:\boost5\bin>opencv_traincascade.exe -data ../cascade -vec ../pos/sample_pos.ve
c -bg sample_negative.dat -numPos 3950 -numNeg 4479 -featureType LBP -w 24 -h 24
 -numStages 15 -mem 1024
PARAMETERS:
cascadeDirName: ../cascade
vecFileName: ../pos/sample_pos.vec
bgFileName: sample_negative.dat
numPos: 3950
numNeg: 4479
numStages: 15
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: LBP
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
Number of unique features given windowSize [24,24] : 8464


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


F:\boost5\bin>pause

请按任意键继续. . .

AdaBoost训练出现问题:Train dataset for temp stage can not be filled


解决:路径问题


AdaBoost训练出现问题:Train dataset for temp stage can not be filled




F:\boost5>cd bin

F:\boost5\bin>opencv_traincascade.exe -data ../cascade -vec ../pos/sample_pos.ve
c -bg sample_negative.dat -numPos 3950 -numNeg 4479 -featureType LBP -w 24 -h 24
 -numStages 15 -mem 1024
PARAMETERS:
cascadeDirName: ../cascade
vecFileName: ../pos/sample_pos.vec
bgFileName: sample_negative.dat
numPos: 3950
numNeg: 4479
numStages: 15
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: LBP
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
Number of unique features given windowSize [24,24] : 8464


===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   3950 : 3950
NEG count : acceptanceRatio    4479 : 1
Precalculation time: 2.641
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2| 0.997215|0.0618442|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 4 seconds.


===== TRAINING 1-stage =====
<BEGIN
POS count : consumed   3950 : 3961
NEG count : acceptanceRatio    4479 : 0.072789
Precalculation time: 2.729
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2| 0.998987|0.0707747|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 8 seconds.


===== TRAINING 2-stage =====
<BEGIN
POS count : consumed   3950 : 3965
NEG count : acceptanceRatio    4479 : 0.00551266
Precalculation time: 2.679
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2| 0.999241|0.0645233|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 16 seconds.


===== TRAINING 3-stage =====
<BEGIN
POS count : consumed   3950 : 3968
NEG current samples: 1173


问题:

AdaBoost训练出现问题:Train dataset for temp stage can not be filled

http://villager5.blog.163.com/blog/static/8273636201462452037527/

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


I took me the whole afternoon to find the solution by google, some other guys have the same problem like me as discussed in this topic: http://answers.opencv.org/question/16868/error-in-train-casacde/

Why?
The reason is very simple, in your opencv folder, find "opencv-2.4.6.1 -> apps -> traincascade ", open "imagestorage.cpp", in function "bool CvCascadeImageReader::NegReader::create( const String _filename, Size _winSize )", we can see that all the image file names in negInfo.txt are read into imgFilenames by std:getline. It seems right! But only if you have used ubuntu to generate the negInfo.txt. If you have used windows (what I did) to generate this text file, there would be two chars at the end of each line \r\n; on linux there is just one, \n.  So, with the original code in opencv, the \r is kept at the end of each file name. Then, in Line 60, "src = imread( imgFilenames[last++], 0 )", the image file can't be loaded. 

So, there are two solutions:
1) generate your bt.txt (negative sample file) on Ubuntu, make sure that there is a newline for each image file no empty line in the whole file;
2) or generate your bt.txt (negative sample file) on Windows, but add one line in the original opencv code "imagestorage.cpp":
before line 45, add "
if (str[str.size() - 1] == '\r')
       str.resize(str.size() - 1); // to erase \r if the file is generated by windows
"; then, recompile (cmake .. -> make -> make install) your opencv for a new opencv_traincascade application.

解决方法:http://blog.csdn.net/forest_world/article/details/71082036

转载请注明:http://blog.csdn.net/forest_world