Checking the Sample Size Input for `cv::ml::StatModel::predict()` Loaded from File?
I'm loading an ML trained model from a file.
I noticed that when calling predict()
with an input sample of the wrong size, the function does not (necessarily) fail! Apparently there is no internal checking that the input is of the right size!
I want to verify that when I'm calling predict()
, my input sample is of the correct size. How can I do that?
I cannot seem to find such a method to provide this info.
OpenCV 3.4. Some "sample" code:
cv::Ptr<cv::ml::StatModel> classifier = cv::Algorithm::load(...);
// ...
cv::Mat sample32f; // fill sample32f
//...
classifier->predict(sample32f.reshape(1,1)); // How to verify the correct expected size???
some code to reproduce it would be nice here ..
(StatModel is an abstract interface, we'd have to look at the actual implementation, like SVM, DTree, or such)
also: opencv version ?
See above tho this is a question about API, so the code is rather simple/obvious...
Yes,
StatModel
is an abstract interface, but all derived classes expect a model of some known size.but which class has the missing size check ? (it probably needs to be reported)
I misunderstood the meaning of
getVarCount()
. I thought it was related to the number of examples in the training phase: "Returns the number of variables in training samples." That is apparently the right answer. Thanks!