JS技术

正式使用opencv里的训练和检测 - opencv_createsamples、opencv_traincascade(7)

字号+ 作者:H5之家 来源:H5之家 2015-12-15 08:44 我要评论( )

To reduce computation time for boosted models without substantially losing accuracy, the influence trimming technique can be employed. As the training algorithm proceeds and the number of trees in th

To reduce computation time for boosted models without substantially losing accuracy, the influence trimming technique can be employed. As the training algorithm proceeds and the number of trees in the ensemble is increased, a larger number of the training samples are classified correctly and with increasing confidence, thereby those samples receive smaller weights on the subsequent iterations. Examples with a very low relative weight have a small impact on the weak classifier training. Thus, such examples may be excluded during the weak classifier training without having much effect on the induced classifier. This process is controlled with the weight_trim_rate parameter. Only examples with the summary fraction weight_trim_rate of the total weight mass are used in the weak classifier training. Note that the weights for all training examples are recomputed at each training iteration. Examples deleted at a particular iteration may be used again for learning some of the weak classifiers further 

See alsocv::ml::Boost Prediction with Boost

StatModel::predict(samples, results, flags) should be used. Pass flags=StatModel::RAW_OUTPUT to get the raw sum from Boost classifier.

8、关于训练过程打印信息的解释

1)POS count : consumed   n1 : n2

每次都调用updateTrainingSet( requiredLeafFARate, tempLeafFARate );函数

bool CvCascadeClassifier::updateTrainingSet( double minimumAcceptanceRatio, double& acceptanceRatio) { int64 posConsumed = 0, negConsumed = 0; imgReader.restart(); int posCount = fillPassedSamples( 0, numPos, true, 0, posConsumed );//Consumed消耗 if( !posCount ) return false; cout << "POS count : consumed " << posCount << " : " << (int)posConsumed << endl;//这就是打印信息,我的理解是这个stage判成正样本数和正样本数 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; }int CvCascadeClassifier::fillPassedSamples( int first, int count, bool isPositive, double minimumAcceptanceRatio, int64& consumed ) { int getcount = 0; Mat img(cascadeParams.winSize, CV_8UC1); for( int i = first; i < first + count; i++ ) { for( ; ; ) { if( consumed != 0 && ((double)getcount+1)/(double)(int64)consumed <= minimumAcceptanceRatio ) return getcount; bool isGetImg = isPositive ? imgReader.getPos( img ) : imgReader.getNeg( img ); if( !isGetImg ) return getcount; consumed++; featureEvaluator->setImage( img, isPositive ? 1 : 0, i ); if( predict( i ) == 1.0F ) { getcount++; printf("%s current samples: %d\r", isPositive ? "POS":"NEG", getcount); break; } } } return getcount; }int CvCascadeClassifier::predict( int sampleIdx ) { CV_DbgAssert( sampleIdx < numPos + numNeg ); for (vector< Ptr<CvCascadeBoost> >::iterator it = stageClassifiers.begin(); it != stageClassifiers.end(); it++ ) { if ( (*it)->predict( sampleIdx ) == 0.f ) return 0; } return 1; }float CvCascadeBoost::predict( int sampleIdx, bool returnSum ) const { CV_Assert( weak ); double sum = 0; CvSeqReader reader; cvStartReadSeq( weak, &reader ); cvSetSeqReaderPos( &reader, 0 ); for( int i = 0; i < weak->total; i++ ) { CvBoostTree* wtree; CV_READ_SEQ_ELEM( wtree, reader ); sum += ((CvCascadeBoostTree*)wtree)->predict(sampleIdx)->value; } if( !returnSum ) sum = sum < threshold - CV_THRESHOLD_EPS ? 0.0 : 1.0; return (float)sum; }





  • 上一篇创建空白图像
  • 下一篇系统时间
  • 顶 7 踩 0

    我的同类文章

    猜你在找

    查看评论

    * 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

     

    1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

    相关文章
    • AngularJS使用HTML5摄像头拍照

      AngularJS使用HTML5摄像头拍照

      2016-02-23 09:42

    • 从Container内存监控限制到CPU使用率限制方案 - 走在前往架构师的路上 - 博客频道 - CSDN.NET 走

      从Container内存监控限制到CPU使用率限制方案 - 走在前往架构师的路

      2015-12-15 09:09

    • 数据抽取工具Kettle使用 - 唐僧打怪兽 - 博客频道 - CSDN.NET 唐僧打怪兽 热爱互联网,编程,比如:J

      数据抽取工具Kettle使用 - 唐僧打怪兽 - 博客频道 - CSDN.NET 唐僧打

      2015-12-14 15:37

    • Oracle数据库Decode()函数的使用方法 - 周泽辉的CSDN博客... - 博客频道 - CSDN.NET 周

      Oracle数据库Decode()函数的使用方法 - 周泽辉的CSDN博客... - 博客

      2015-12-14 15:05

    网友点评
    s