Okay, I have some training data with 35 variables, I trained an SVM classifier and saved it using:
svm->save("trained-svm.xml")
In another application, I was trying to load the classifier using the XML file saved previously, and I encountered an Assertion Failure when I tried to call predict() on a piece of new input data:
OpenCV Error: Assertion failed (samples.cols == var_count && samples.type() == CV_32F) in cv::ml::SVMImpl::predict, file E:\Downloads\opencv\sources\modules\ml\src\svm.cpp, line 1930
I double checked that I have loaded my data as CV_32F type, which means that the assertion failed at samples.cols == var_count. And I double checked that I did have the right number of columns (35) in my test data.
So I tried to print out the var_count as follows:
svm->load("trained-svm.xml");
cout << svm->getVarCount() << endl;
The result is that getVarCount() reports value of -842150451, which is clearly wrong. Since my XML does mention var_count as 35. Apparently load() doesn't update this value, causing the assertion.
3 C_SVC LINEAR 1. 1.1920928955078125e-07 1000
**35 **6 6 1 i
1 2 3 4 5 615
(snipped away rest of XML)
Any solutions to this?
↧