Commit 62cb7109 authored by Maria Dimashova's avatar Maria Dimashova

fixed traincascade (#554)

parent 07e68eb0
...@@ -139,7 +139,7 @@ bool CvCascadeBoostParams::scanAttr( const String prmName, const String val) ...@@ -139,7 +139,7 @@ bool CvCascadeBoostParams::scanAttr( const String prmName, const String val)
{ {
weight_trim_rate = (float) atof( val.c_str() ); weight_trim_rate = (float) atof( val.c_str() );
} }
else if( !prmName.compare( "-maxDepth" ) ) else if( !prmName.compare( "-maxTreeDepth" ) )
{ {
max_depth = atoi( val.c_str() ); max_depth = atoi( val.c_str() );
} }
...@@ -240,9 +240,11 @@ void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluat ...@@ -240,9 +240,11 @@ void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluat
if (sample_count < 65536) if (sample_count < 65536)
is_buf_16u = true; is_buf_16u = true;
numPrecalcVal = min( (_precalcValBufSize*1048576) / int(sizeof(float)*sample_count), var_count ); numPrecalcVal = min( cvRound((double)_precalcValBufSize*1048576. / (sizeof(float)*sample_count)), var_count );
numPrecalcIdx = min( (_precalcIdxBufSize*1048576) / numPrecalcIdx = min( cvRound((double)_precalcIdxBufSize*1048576. /
int((is_buf_16u ? sizeof(unsigned short) : sizeof (int))*sample_count), var_count ); ((is_buf_16u ? sizeof(unsigned short) : sizeof (int))*sample_count)), var_count );
assert( numPrecalcIdx >= 0 && numPrecalcVal >= 0 );
valCache.create( numPrecalcVal, sample_count, CV_32FC1 ); valCache.create( numPrecalcVal, sample_count, CV_32FC1 );
var_type = cvCreateMat( 1, var_count + 2, CV_32SC1 ); var_type = cvCreateMat( 1, var_count + 2, CV_32SC1 );
...@@ -394,7 +396,7 @@ void CvCascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* o ...@@ -394,7 +396,7 @@ void CvCascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* o
} }
else else
{ {
for( int i = 0; i < nodeSampleCount; i++ ) for( int i = 0; i < nodeSampleCount; i++ )
{ {
int idx = (*sortedIndices)[i]; int idx = (*sortedIndices)[i];
idx = sampleIndices[idx]; idx = sampleIndices[idx];
...@@ -404,13 +406,26 @@ void CvCascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* o ...@@ -404,13 +406,26 @@ void CvCascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* o
} }
else // vi >= numPrecalcIdx else // vi >= numPrecalcIdx
{ {
// use sample_indices as temporary buffer for values vector<float> sampleValuesBuf;
float* sampleValues = 0;
if( sizeof(float) == sizeof(int) )
{
// use sampleIndices as temporary buffer for values
sampleValues = (float*)sampleIndices;
}
else
{
sampleValuesBuf.resize(nodeSampleCount);
sampleValues = &sampleValuesBuf[0];
}
if ( vi < numPrecalcVal ) if ( vi < numPrecalcVal )
{ {
for( int i = 0; i < nodeSampleCount; i++ ) for( int i = 0; i < nodeSampleCount; i++ )
{ {
sortedIndicesBuf[i] = i; sortedIndicesBuf[i] = i;
((float*)sampleIndices)[i] = valCache.at<float>( vi, sampleIndices[i] ); sampleValues[i] = valCache.at<float>( vi, sampleIndices[i] );
} }
} }
else else
...@@ -418,12 +433,12 @@ void CvCascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* o ...@@ -418,12 +433,12 @@ void CvCascadeBoostTrainData::get_ord_var_data( CvDTreeNode* n, int vi, float* o
for( int i = 0; i < nodeSampleCount; i++ ) for( int i = 0; i < nodeSampleCount; i++ )
{ {
sortedIndicesBuf[i] = i; sortedIndicesBuf[i] = i;
((float*)sampleIndices)[i] = (*featureEvaluator)( vi, sampleIndices[i]); sampleValues[i] = (*featureEvaluator)( vi, sampleIndices[i]);
} }
} }
icvSortIntAux( sortedIndicesBuf, sample_count, (float *)sampleIndices ); icvSortIntAux( sortedIndicesBuf, nodeSampleCount, &sampleValues[0] );
for( int i = 0; i < nodeSampleCount; i++ ) for( int i = 0; i < nodeSampleCount; i++ )
ordValuesBuf[i] = ((float*)sampleIndices)[sortedIndicesBuf[i]]; ordValuesBuf[i] = (&sampleValues[0])[sortedIndicesBuf[i]];
*sortedIndices = sortedIndicesBuf; *sortedIndices = sortedIndicesBuf;
} }
...@@ -553,7 +568,6 @@ struct FeatureValOnlyPrecalc ...@@ -553,7 +568,6 @@ struct FeatureValOnlyPrecalc
void CvCascadeBoostTrainData::precalculate() void CvCascadeBoostTrainData::precalculate()
{ {
int minNum = MIN( numPrecalcVal, numPrecalcIdx); int minNum = MIN( numPrecalcVal, numPrecalcIdx);
CV_DbgAssert( !valCache.empty() );
double proctime = -TIME( 0 ); double proctime = -TIME( 0 );
parallel_for( BlockedRange(numPrecalcVal, numPrecalcIdx), parallel_for( BlockedRange(numPrecalcVal, numPrecalcIdx),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment