Jeremy
opencv_traincascade.exe -data data -vec diode\pos.vec -bg nodiode\neg.dat -numPos 600 -numNeg 600 -numStages 15 -w 22 -h 52 -minHitRate 0.995 -maxFalseAlarmRate 0.5 pause
在应用opencv_traincascade.exe对图片进行训练的过程中碰到很多问题,现一一记录如下:
[bug1]: Train dataset for temp stage can not filled. Branch training terminated.
首先我们来看这个错误时从哪里出来的,从源代码[cascadeclassifier.cpp]中我们可以看到:
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; } CvCascadeBoost* tempStage = new CvCascadeBoost; bool isStageTrained = tempStage->train( (CvFeatureEvaluator*)featureEvaluator, curNumSamples, _precalcValBufSize, _precalcIdxBufSize, *((CvCascadeBoostParams*)stageParams) ); cout << "END>" << endl;
bool CvCascadeClassifier::updateTrainingSet( double minimumAcceptanceRatio, double& acceptanceRatio) { int64 posConsumed = 0, negConsumed = 0; imgReader.restart(); int posCount = fillPassedSamples( 0, numPos, true, 0, 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, minimumAcceptanceRatio, 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; }
我们的错误输出是在"POS count……"之后,“NEG count”之前,这样……问题就是negCount=false,也即fillPassedSamples()函数出错了
后来我把numPos变大为1500,numNeg变大为1200。因为每次stage的迭代过程中会只更换“1%”左右的样本。