Commit de059567 authored by logic1988's avatar logic1988 Committed by Alexander Alekhin

Update inner_functions.cpp

Fix #4958 cv::ml::StatModel::calcError not working for responses of type CV_32S
parent 53f72f18
...@@ -74,6 +74,7 @@ float StatModel::calcError( const Ptr<TrainData>& data, bool testerr, OutputArra ...@@ -74,6 +74,7 @@ float StatModel::calcError( const Ptr<TrainData>& data, bool testerr, OutputArra
int i, n = (int)sidx.total(); int i, n = (int)sidx.total();
bool isclassifier = isClassifier(); bool isclassifier = isClassifier();
Mat responses = data->getResponses(); Mat responses = data->getResponses();
int responses_type = responses.type();
if( n == 0 ) if( n == 0 )
n = data->getNSamples(); n = data->getNSamples();
...@@ -91,7 +92,7 @@ float StatModel::calcError( const Ptr<TrainData>& data, bool testerr, OutputArra ...@@ -91,7 +92,7 @@ float StatModel::calcError( const Ptr<TrainData>& data, bool testerr, OutputArra
int si = sidx_ptr ? sidx_ptr[i] : i; int si = sidx_ptr ? sidx_ptr[i] : i;
Mat sample = layout == ROW_SAMPLE ? samples.row(si) : samples.col(si); Mat sample = layout == ROW_SAMPLE ? samples.row(si) : samples.col(si);
float val = predict(sample); float val = predict(sample);
float val0 = responses.at<float>(si); float val0 = (responses_type == CV_32S) ? (float)responses.at<int>(si) : responses.at<float>(si);
if( isclassifier ) if( isclassifier )
err += fabs(val - val0) > FLT_EPSILON; err += fabs(val - val0) > FLT_EPSILON;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment