nadjet
nadjet

Reputation: 31

confidence of prediction in SVM in OpenCv3.0.0

i'm using aprogram to classify road singns, and i want get confidence of prediction between 0-1. Well, I tried to calculate the confidence and compare it with probabilities, but it was not work, because there's images representing (for exp 60 Km / h), and have a rates below than 0.9, and another (also representing 60 Km / h) have a higher rate to 0.9.

but the same thing is repeated with unrecognized traffic sing : there's images that does not represent a traffic sing, and which have a rate less than 0.9, and others which have a rate higher than 0 9. i tried this

decision = svmob.predict(testData, true);
confidence = 1.0 / (1.0 + exp(-decision));

that i found here but it does'n work in OpenCv3.0. can you help me please.

than I tried this:

 int classObject = decision.at<float>(currentFile) < 0.0 ? 1 : -1;
    float confidence = classObject == -1 ? (1.0 / (1.0 + exp(-decision.at<float>(currentFile)))) : (1.0 - (1.0 / (1.0 + exp(-decision.at<float>(currentFile)))));
    if(confidence<0.9)
        printf("le panneau n'est pas reconnu");
    else
        printf("decision = %f, response = %f\n",
        decision.at<float>(0), response);

I want to know ho to do it, please?

Upvotes: 3

Views: 1329

Answers (1)

张嘿嘿
张嘿嘿

Reputation: 21

in opencv3.0 we should use the interface predict(p, noArray(), cv::ml::StatModel::RAW_OUTPUT). Its' effect is equal to predict(p, true) in opencv2.4

Opencv documention explain the interface:C++: float StatModel::predict(InputArray samples, OutputArray results=noArray(), int flags=0 ) const Parameters: samples – The input samples, floating-point matrix results – The optional output matrix of results.

flags – The optional flags, model-dependent. Some models, such as Boost, SVM recognize StatModel::RAW_OUTPUT flag, which makes the method return the raw results (the sum), not the class label.

Upvotes: 2

Related Questions