Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

SVM weights parameter not set through Python

Hey,

I am using the SVM implementation in OpenCV (python) and I am running into some trouble setting the class weights parameter. The attribute is called class_weights inside the CVSvmParams class, so I'd expect this to remain the same in the Python interface. I try to assign the parameters as follows:

params = dict( kernel_type = cv2.SVM_LINEAR, 
               svm_type = cv2.SVM_C_SVC,
               C = 1,
               class_weights = [0.1, 0.9],)

However the class_weights variable does not seem to get set inside OpenCV. I added a line to log the value of the _params.class_weights pointer value in CvSVM::train and it prints 0x0.

If I try a similar thing in c++ it does get set. Any idea what is going wrong or what I can further investigate? The wrapper function for CvSvm::train() is the last step I could identify between Python and c++, is there a function before CvSvm::train() that I can check for faults?

Best regards, Hans