Skip to content

Commit 519fbdb

Browse files
committed
Wrappers for load methods of EM, LR, SVMSGD and Normal Bayes Classifier
1 parent aa5caf8 commit 519fbdb

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

modules/ml/include/opencv2/ml.hpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,17 @@ class CV_EXPORTS_W NormalBayesClassifier : public StatModel
393393
/** Creates empty model
394394
Use StatModel::train to train the model after creation. */
395395
CV_WRAP static Ptr<NormalBayesClassifier> create();
396+
397+
/** @brief Loads and creates a serialized NormalBayesClassifier from a file
398+
*
399+
* Use NormalBayesClassifier::save to serialize and store an NormalBayesClassifier to disk.
400+
* Load the NormalBayesClassifier from this file again, by calling this function with the path to the file.
401+
* Optionally specify the node for the file containing the classifier
402+
*
403+
* @param filepath path to serialized NormalBayesClassifier
404+
* @param nodeName name of node containing the classifier
405+
*/
406+
CV_WRAP static Ptr<NormalBayesClassifier> load(const String& filepath , const String& nodeName = String());
396407
};
397408

398409
/****************************************************************************************\
@@ -927,6 +938,17 @@ class CV_EXPORTS_W EM : public StatModel
927938
can use one of the EM::train\* methods or load it from file using Algorithm::load\<EM\>(filename).
928939
*/
929940
CV_WRAP static Ptr<EM> create();
941+
942+
/** @brief Loads and creates a serialized EM from a file
943+
*
944+
* Use EM::save to serialize and store an EM to disk.
945+
* Load the EM from this file again, by calling this function with the path to the file.
946+
* Optionally specify the node for the file containing the classifier
947+
*
948+
* @param filepath path to serialized EM
949+
* @param nodeName name of node containing the classifier
950+
*/
951+
CV_WRAP static Ptr<EM> load(const String& filepath , const String& nodeName = String());
930952
};
931953

932954
/****************************************************************************************\
@@ -1512,6 +1534,17 @@ class CV_EXPORTS_W LogisticRegression : public StatModel
15121534
Creates Logistic Regression model with parameters given.
15131535
*/
15141536
CV_WRAP static Ptr<LogisticRegression> create();
1537+
1538+
/** @brief Loads and creates a serialized LogisticRegression from a file
1539+
*
1540+
* Use LogisticRegression::save to serialize and store an LogisticRegression to disk.
1541+
* Load the LogisticRegression from this file again, by calling this function with the path to the file.
1542+
* Optionally specify the node for the file containing the classifier
1543+
*
1544+
* @param filepath path to serialized LogisticRegression
1545+
* @param nodeName name of node containing the classifier
1546+
*/
1547+
CV_WRAP static Ptr<LogisticRegression> load(const String& filepath , const String& nodeName = String());
15151548
};
15161549

15171550

@@ -1627,6 +1660,17 @@ class CV_EXPORTS_W SVMSGD : public cv::ml::StatModel
16271660
*/
16281661
CV_WRAP static Ptr<SVMSGD> create();
16291662

1663+
/** @brief Loads and creates a serialized SVMSGD from a file
1664+
*
1665+
* Use SVMSGD::save to serialize and store an SVMSGD to disk.
1666+
* Load the SVMSGD from this file again, by calling this function with the path to the file.
1667+
* Optionally specify the node for the file containing the classifier
1668+
*
1669+
* @param filepath path to serialized SVMSGD
1670+
* @param nodeName name of node containing the classifier
1671+
*/
1672+
CV_WRAP static Ptr<SVMSGD> load(const String& filepath , const String& nodeName = String());
1673+
16301674
/** @brief Function sets optimal parameters values for chosen SVM SGD model.
16311675
* @param svmsgdType is the type of SVMSGD classifier.
16321676
* @param marginType is the type of margin constraint.

modules/ml/src/em.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,11 @@ Ptr<EM> EM::create()
845845
return makePtr<EMImpl>();
846846
}
847847

848+
Ptr<EM> EM::load(const String& filepath, const String& nodeName)
849+
{
850+
return Algorithm::load<EM>(filepath, nodeName);
851+
}
852+
848853
}
849854
} // namespace cv
850855

modules/ml/src/lr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ Ptr<LogisticRegression> LogisticRegression::create()
127127
return makePtr<LogisticRegressionImpl>();
128128
}
129129

130+
Ptr<LogisticRegression> LogisticRegression::load(const String& filepath, const String& nodeName)
131+
{
132+
return Algorithm::load<LogisticRegression>(filepath, nodeName);
133+
}
134+
135+
130136
bool LogisticRegressionImpl::train(const Ptr<TrainData>& trainData, int)
131137
{
132138
// return value

modules/ml/src/nbayes.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ Ptr<NormalBayesClassifier> NormalBayesClassifier::create()
458458
return p;
459459
}
460460

461+
Ptr<NormalBayesClassifier> NormalBayesClassifier::load(const String& filepath, const String& nodeName)
462+
{
463+
return Algorithm::load<NormalBayesClassifier>(filepath, nodeName);
464+
}
465+
461466
}
462467
}
463468

modules/ml/src/svmsgd.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ Ptr<SVMSGD> SVMSGD::create()
134134
return makePtr<SVMSGDImpl>();
135135
}
136136

137+
Ptr<SVMSGD> SVMSGD::load(const String& filepath, const String& nodeName)
138+
{
139+
return Algorithm::load<SVMSGD>(filepath, nodeName);
140+
}
141+
142+
137143
void SVMSGDImpl::normalizeSamples(Mat &samples, Mat &average, float &multiplier)
138144
{
139145
int featuresCount = samples.cols;

0 commit comments

Comments
 (0)