From: marina.kolpakova Date: Wed, 12 Dec 2012 11:35:30 +0000 (+0400) Subject: amplement weidhting according to L. Bourdev and J. Brandt paper "Robust Object Detect... X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~4025^2~65 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a8d0e04912104cd29633ad000db438cc5720b420;p=platform%2Fupstream%2Fopencv.git amplement weidhting according to L. Bourdev and J. Brandt paper "Robust Object Detection Via Soft Cascade" --- diff --git a/apps/sft/include/sft/octave.hpp b/apps/sft/include/sft/octave.hpp index f5fd788..81b73bb 100644 --- a/apps/sft/include/sft/octave.hpp +++ b/apps/sft/include/sft/octave.hpp @@ -158,7 +158,7 @@ protected: float predict( const Mat& _sample, const cv::Range range) const; private: void traverse(const CvBoostTree* tree, cv::FileStorage& fs, const float* th = 0) const; - + virtual void initial_weights(double (&p)[2]); cv::Rect boundingBox; int npositives; diff --git a/apps/sft/octave.cpp b/apps/sft/octave.cpp index 6b601ab..e886fbd 100644 --- a/apps/sft/octave.cpp +++ b/apps/sft/octave.cpp @@ -295,6 +295,7 @@ void sft::Octave::generateNegatives(const Dataset& dataset) dprintf("Processing negatives finished:\n\trequested %d negatives, viewed %d samples.\n", nnegatives, total); } + template int sgn(T val) { return (T(0) < val) - (val < T(0)); } @@ -378,6 +379,13 @@ void sft::Octave::write( cv::FileStorage &fso, const Mat& thresholds) const << "}"; } +void sft::Octave::initial_weights(double (&p)[2]) +{ + double n = data->sample_count; + p[0] = n / (double)(nnegatives) ; + p[1] = n / (double)(npositives); +} + bool sft::Octave::train(const Dataset& dataset, const FeaturePool& pool, int weaks, int treeDepth) { CV_Assert(treeDepth == 2); diff --git a/modules/ml/include/opencv2/ml/ml.hpp b/modules/ml/include/opencv2/ml/ml.hpp index 7ba97c8..e8e069b 100644 --- a/modules/ml/include/opencv2/ml/ml.hpp +++ b/modules/ml/include/opencv2/ml/ml.hpp @@ -1251,6 +1251,8 @@ protected: virtual void write_params( CvFileStorage* fs ) const; virtual void read_params( CvFileStorage* fs, CvFileNode* node ); + virtual void initial_weights(double (&p)[2]); + CvDTreeTrainData* data; CvBoostParams params; CvSeq* weak; diff --git a/modules/ml/src/boost.cpp b/modules/ml/src/boost.cpp index 3525a11..b644733 100644 --- a/modules/ml/src/boost.cpp +++ b/modules/ml/src/boost.cpp @@ -1116,6 +1116,12 @@ bool CvBoost::train( CvMLData* _data, return result; } +void CvBoost::initial_weights(double (&p)[2]) +{ + p[0] = 1.; + p[1] = 1.; +} + void CvBoost::update_weights( CvBoostTree* tree ) { @@ -1159,8 +1165,9 @@ CvBoost::update_weights( CvBoostTree* tree ) // in case of logitboost and gentle adaboost each weak tree is a regression tree, // so we need to convert class labels to floating-point values - double w0 = 1./n; - double p[2] = { 1, 1 }; + double w0 = 1./ n; + double p[2] = { 1., 1. }; + initial_weights(p); cvReleaseMat( &orig_response ); cvReleaseMat( &sum_response );