Ask Your Question

Revision history [back]

Load an SVM from a string in Python?

Is there a way to load a pre-trained SVM model from an XML string in Python? I am looking to use it on a platform that does not support an external file system, so the model must be saved as a string in the .py file itself.

These examples (1, 2) seem possible in C++; however, it doesn't appear that svm->read is exposed in Python.

Is there a workaround that would accomplish something similar in Python?

//1
string yml; // the whole schlepp in a string
FileStorage fs;
fs.open(yml,FileStorage::READ|FileStorage::MEMORY);
facereco->load(fs);
fs.release();

//2
string data_string; //containing xml/yml data
FileStorage fs( data_string, FileStorage::READ | FileStorage::MEMORY);
svm.read(fs.getFirstTopLevelNode()); // or the node with your trainset