1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

export SVM::trainAuto to python #7224 (#8373)

* export SVM::trainAuto to python #7224

* workaround for ABI compatibility of SVM::trainAuto

* add parameter comments to new SVM::trainAuto function

* Export ParamGrid member variables
This commit is contained in:
Julian Tanke
2017-03-23 14:00:19 +01:00
committed by Vadim Pisarevsky
parent 1857aa22b3
commit f70cc29edb
3 changed files with 103 additions and 4 deletions
+4
View File
@@ -50,6 +50,10 @@ ParamGrid::ParamGrid(double _minVal, double _maxVal, double _logStep)
logStep = std::max(_logStep, 1.);
}
Ptr<ParamGrid> ParamGrid::create(double minval, double maxval, double logstep) {
return makePtr<ParamGrid>(minval, maxval, logstep);
}
bool StatModel::empty() const { return !isTrained(); }
int StatModel::getVarCount() const { return 0; }
+37
View File
@@ -362,6 +362,12 @@ static void sortSamplesByClasses( const Mat& _samples, const Mat& _responses,
//////////////////////// SVM implementation //////////////////////////////
Ptr<ParamGrid> SVM::getDefaultGridPtr( int param_id)
{
ParamGrid grid = getDefaultGrid(param_id); // this is not a nice solution..
return makePtr<ParamGrid>(grid.minVal, grid.maxVal, grid.logStep);
}
ParamGrid SVM::getDefaultGrid( int param_id )
{
ParamGrid grid;
@@ -1920,6 +1926,24 @@ public:
bool returnDFVal;
};
bool trainAuto_(InputArray samples, int layout,
InputArray responses, int kfold, Ptr<ParamGrid> Cgrid,
Ptr<ParamGrid> gammaGrid, Ptr<ParamGrid> pGrid, Ptr<ParamGrid> nuGrid,
Ptr<ParamGrid> coeffGrid, Ptr<ParamGrid> degreeGrid, bool balanced)
{
Ptr<TrainData> data = TrainData::create(samples, layout, responses);
return this->trainAuto(
data, kfold,
*Cgrid.get(),
*gammaGrid.get(),
*pGrid.get(),
*nuGrid.get(),
*coeffGrid.get(),
*degreeGrid.get(),
balanced);
}
float predict( InputArray _samples, OutputArray _results, int flags ) const
{
float result = 0;
@@ -2281,6 +2305,19 @@ Mat SVM::getUncompressedSupportVectors() const
return this_->getUncompressedSupportVectors_();
}
bool SVM::trainAuto(InputArray samples, int layout,
InputArray responses, int kfold, Ptr<ParamGrid> Cgrid,
Ptr<ParamGrid> gammaGrid, Ptr<ParamGrid> pGrid, Ptr<ParamGrid> nuGrid,
Ptr<ParamGrid> coeffGrid, Ptr<ParamGrid> degreeGrid, bool balanced)
{
SVMImpl* this_ = dynamic_cast<SVMImpl*>(this);
if (!this_) {
CV_Error(Error::StsNotImplemented, "the class is not SVMImpl");
}
return this_->trainAuto_(samples, layout, responses,
kfold, Cgrid, gammaGrid, pGrid, nuGrid, coeffGrid, degreeGrid, balanced);
}
}
}