integrated parallel SVM prediction; fixed warnings after meanshift integration
This commit is contained in:
@@ -543,7 +543,8 @@ public:
|
||||
bool balanced=false );
|
||||
|
||||
virtual float predict( const CvMat* sample, bool returnDFVal=false ) const;
|
||||
|
||||
virtual float predict( const CvMat* samples, CvMat* results ) const;
|
||||
|
||||
#ifndef SWIG
|
||||
CV_WRAP CvSVM( const cv::Mat& trainData, const cv::Mat& responses,
|
||||
const cv::Mat& varIdx=cv::Mat(), const cv::Mat& sampleIdx=cv::Mat(),
|
||||
@@ -563,7 +564,7 @@ public:
|
||||
CvParamGrid coeffGrid = CvSVM::get_default_grid(CvSVM::COEF),
|
||||
CvParamGrid degreeGrid = CvSVM::get_default_grid(CvSVM::DEGREE),
|
||||
bool balanced=false);
|
||||
CV_WRAP virtual float predict( const cv::Mat& sample, bool returnDFVal=false ) const;
|
||||
CV_WRAP virtual float predict( const cv::Mat& sample, bool returnDFVal=false ) const;
|
||||
#endif
|
||||
|
||||
CV_WRAP virtual int get_support_vector_count() const;
|
||||
|
@@ -2081,7 +2081,7 @@ float CvSVM::predict( const CvMat* sample, bool returnDFVal ) const
|
||||
CV_CALL( cvPreparePredictData( sample, var_all, var_idx,
|
||||
class_count, 0, &row_sample ));
|
||||
result = predict( row_sample, get_var_count(), returnDFVal );
|
||||
|
||||
|
||||
__END__;
|
||||
|
||||
if( sample && (!CV_IS_MAT(sample) || sample->data.fl != row_sample) )
|
||||
@@ -2090,6 +2090,44 @@ float CvSVM::predict( const CvMat* sample, bool returnDFVal ) const
|
||||
return result;
|
||||
}
|
||||
|
||||
struct predict_body {
|
||||
predict_body(const CvSVM* _pointer, float* _result, const CvMat* _samples, CvMat* _results)
|
||||
{
|
||||
pointer = _pointer;
|
||||
result = _result;
|
||||
samples = _samples;
|
||||
results = _results;
|
||||
}
|
||||
|
||||
const CvSVM* pointer;
|
||||
float* result;
|
||||
const CvMat* samples;
|
||||
CvMat* results;
|
||||
|
||||
void operator()( const cv::BlockedRange& range ) const
|
||||
{
|
||||
for(int i = range.begin(); i < range.end(); i++ )
|
||||
{
|
||||
CvMat sample;
|
||||
cvGetRow( samples, &sample, i );
|
||||
int r = (int)pointer->predict(&sample);
|
||||
if (results)
|
||||
results->data.fl[i] = r;
|
||||
if (i == 0)
|
||||
*result = r;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
float CvSVM::predict(const CvMat* samples, CV_OUT CvMat* results) const
|
||||
{
|
||||
float result = 0;
|
||||
cv::parallel_for(cv::BlockedRange(0, samples->rows),
|
||||
predict_body(this, &result, samples, results)
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
CvSVM::CvSVM( const Mat& _train_data, const Mat& _responses,
|
||||
const Mat& _var_idx, const Mat& _sample_idx, CvSVMParams _params )
|
||||
|
@@ -1396,7 +1396,7 @@ int createSchedule(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all
|
||||
const int threadsNum, int *kLevels, int **processingLevels)
|
||||
{
|
||||
int rootFilterDim, sumPartFiltersDim, i, numLevels, dbx, dby, numDotProducts;
|
||||
int averNumDotProd, j, minValue, argMin, tmp, lambda, maxValue, k;
|
||||
int averNumDotProd, j, minValue, argMin, lambda, maxValue, k;
|
||||
int *dotProd, *weights, *disp;
|
||||
if (H == NULL || all_F == NULL)
|
||||
{
|
||||
|
@@ -44,11 +44,17 @@
|
||||
using namespace cv;
|
||||
|
||||
MeanshiftGrouping::MeanshiftGrouping(const Point3d& densKer, const vector<Point3d>& posV,
|
||||
const vector<double>& wV, double modeEps, int maxIter):
|
||||
densityKernel(densKer), weightsV(wV), positionsV(posV), positionsCount(posV.size()),
|
||||
meanshiftV(positionsCount), distanceV(positionsCount), modeEps(modeEps),
|
||||
iterMax (maxIter)
|
||||
const vector<double>& wV, double modeEps, int maxIter)
|
||||
{
|
||||
densityKernel = densKer;
|
||||
weightsV = wV;
|
||||
positionsV = posV;
|
||||
positionsCount = posV.size();
|
||||
meanshiftV.resize(positionsCount);
|
||||
distanceV.resize(positionsCount);
|
||||
modeEps = modeEps;
|
||||
iterMax = maxIter;
|
||||
|
||||
for (unsigned i=0; i<positionsV.size(); i++)
|
||||
{
|
||||
meanshiftV[i] = getNewValue(positionsV[i]);
|
||||
|
Reference in New Issue
Block a user