Ask Your Question

Revision history [back]

Stage threshold in cascade training

Hi,

I've been through the code of the cascade training framework and something remains unclear to me. In many papers the overall threshold of each stage (certain amount of weak classifier) is set by decreasing the threshold until reaching a pre-defined detection rate. In opencv implementation it seems different, some values are first sorted and the threshold is one of these values. Can anyone give me a light on this portion of code (a paper/source would be nice to understand !) ?

bool CvCascadeBoost::isErrDesired() { int sCount = data->sample_count, numPos = 0, numNeg = 0, numFalse = 0, numPosTrue = 0; vector eval(sCount);

for( int i = 0; i < sCount; i++ ) if( ((CvCascadeBoostTrainData*)data)->featureEvaluator->getCls( i ) == 1.0F ) eval[numPos++] = predict( i, true );

std::sort(&eval[0], &eval[0] + numPos);

int thresholdIdx = (int)((1.0F - minHitRate) * numPos);

threshold = eval[ thresholdIdx ]; numPosTrue = numPos - thresholdIdx; for( int i = thresholdIdx - 1; i >= 0; i--) if ( abs( eval[i] - threshold) < FLT_EPSILON ) numPosTrue++; float hitRate = ((float) numPosTrue) / ((float) numPos);

for( int i = 0; i < sCount; i++ ) { if( ((CvCascadeBoostTrainData*)data)->featureEvaluator->getCls( i ) == 0.0F ) { numNeg++; if( predict( i ) ) numFalse++; } } float falseAlarm = ((float) numFalse) / ((float) numNeg);

cout << "|"; cout.width(4); cout << right << weak->total; cout << "|"; cout.width(9); cout << right << hitRate; cout << "|"; cout.width(9); cout << right << falseAlarm; cout << "|" << endl; cout << "+----+---------+---------+" << endl;

return falseAlarm <= maxFalseAlarm;

}

Thanks