mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
* 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:
committed by
Vadim Pisarevsky
parent
1857aa22b3
commit
f70cc29edb
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user