What mean is SVM predict method return value ?

asked 2013-10-28 11:02:48 -0500

shige gravatar image

I use predict method for 2-class classification with SVM labeled +1 or -1. And returnDFVal is false, then I get +1 or -1 accurate. but, returnDFVal is true, then return value is opposite to the label, i.e.

returnDFVal = false -> return = -1

returnDFVal = true  -> return = 1.07756

code is below, best regard.

float svmPredict(const char* classifier, const char* image, const char* method)
    // load query image
    cv::Mat img = cv::imread(image, CV_LOAD_IMAGE_GRAYSCALE);

    // compute descriptor for each keypoint
    cv::Mat desc;
    desc = getDescriptors(img, method);

    // load svm classifier
    cv::SVM svm;

    // convert descriptor -> vector
    cv::Mat centroids(1, 64, CV_32F);
    cv::Mat label(1, 1, CV_32F, cv::Scalar(-1));
    cv::kmeans(desc, 1, label, cv::TermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0), 1, 2, centroids);

    // predict
    //float predict = svm.predict(centroids, false);
    float predict = svm.predict(centroids, true);

    return predict;
edit retag flag offensive close merge delete


I am wondering how you got the cv::SVM to work. Even the master documentation states that it is still in the old C api using CvSVM? Did you wrap it yourself? Also just checked master branch at github. Latest release still doesn't have C++ wrappers ... I am confused here ...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-04-25 06:44:44 -0500 )edit