SVM::isTrained returns false after SVM::load

I successfully trained and predicted with SVM. The results are great with Windows OpenCV C++ versions 4.1 and 4.8.


Type: C_SVC
Kernel: RBF
C: 1.0
Gamma: 0.5
TermCriteria: EPS, 1000, 1e-6

I save the model (SVM::save). I then quite my application and restart. I use SVM::load to reload the model. The function returns true. But SVM::isTrained returns false, and SVM::predict has an error.

From what I understand SVM::load recreates the loaded model and is ready for prediction. I predict with the same trained data.

I read somewhere OPENCV 3.x had an error with reloading SVM models with non-linear kernels. But couldn’t find anything else on the issue.

Please offer potential problems and solutions.

show code, please (it’s a static function, creating a new model !)

most likely, you’re trying this:

oldsvm->load("my.xml"); // new svm gets discarded !!)

when you need this:

Ptr<SVM> newsvm = SVM::load("my.xml");