Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Issues with OpenCV train_HOG c++ sample code?

I am trying to train a HOG+SVM on the INRIA dataset using the OpenCV sample code train_HOG.cpp. Firstly, I am confused why Support Vector Regression (EPS_SVR) is used for what is clearly a classification problem. I've tried changing it to C_SVC but am getting the following runtime error with all kernels other than linear (this happens for the regression case as well) while testing on the training set itself:

OpenCV Error: Assertion failed (alpha.total() == 1 && svidx.total() == 1 && sv_total == 1) in get_svm_detector terminate called after throwing an instance of 'cv::Exception' what(): HOGsvm.cpp:41: error: (-215) alpha.total() == 1 && svidx.total() == 1 && sv_total == 1 in function get_svm_detector Aborted (core dumped)

Any idea on why it is happening and how to resolve it?

Issues with OpenCV train_HOG c++ sample code?

I am trying to train a HOG+SVM on the INRIA dataset using the OpenCV sample code train_HOG.cpp. Firstly, I am confused why Support Vector Regression (EPS_SVR) is used for what is clearly a classification problem. I've tried changing it to C_SVC but am getting the following runtime error with all kernels other than linear (this happens for the regression case as well) while testing on the training set itself:

OpenCV Error: Assertion failed (alpha.total() == 1 && svidx.total() == 1 && sv_total == 1) in get_svm_detector terminate called after throwing an instance of 'cv::Exception' what(): HOGsvm.cpp:41: error: (-215) alpha.total() == 1 && svidx.total() == 1 && sv_total == 1 in function get_svm_detector Aborted (core dumped)

Any idea on why it is happening and how to resolve it?

EDIT: Here's the code snippet that's raising the error

Ptr<svm> svm = SVM::create() ;

svm->setTermCriteria(TermCriteria( CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, 1e-3 ));

svm->setType(SVM::C_SVC);

svm->setKernel(SVM::RBF);

svm->setC(0.01);

svm->setGamma(0.1);

svm->train(train_data, ROW_SAMPLE, Mat(labels));

HOGDescriptor myHog ;

myHog.winSize = Size(64, 128) ;

vector<float> hogDetector ;

Mat sv = svm->getSupportVectors();

const int sv_total = sv.rows; Mat alpha, svidx; double rho = svm->getDecisionFunction(0, alpha, svidx);

CV_Assert( alpha.total() == 1 && svidx.total() == 1 && sv_total == 1 );

Issues with OpenCV train_HOG c++ sample code?

I am trying to train a HOG+SVM on the INRIA dataset using the OpenCV sample code train_HOG.cpp. Firstly, I am confused why Support Vector Regression (EPS_SVR) is used for what is clearly a classification problem. I've tried changing it to C_SVC but am getting the following runtime error with all kernels other than linear (this happens for the regression case as well) while testing on the training set itself:

OpenCV Error: Assertion failed (alpha.total() == 1 && svidx.total() == 1 && sv_total == 1) in get_svm_detector terminate called after throwing an instance of 'cv::Exception' what(): HOGsvm.cpp:41: error: (-215) alpha.total() == 1 && svidx.total() == 1 && sv_total == 1 in function get_svm_detector Aborted (core dumped)

Any idea on why it is happening and how to resolve it?

EDIT: Here's the code snippet that's raising the error

Ptr<svm> svm = SVM::create() ;

svm->setTermCriteria(TermCriteria( CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, 1e-3 ));

svm->setType(SVM::C_SVC);

svm->setKernel(SVM::RBF);

svm->setC(0.01);

svm->setGamma(0.1);

svm->train(train_data, ROW_SAMPLE, Mat(labels));

HOGDescriptor myHog ;

myHog.winSize = Size(64, 128) ;

vector<float> hogDetector ;

Mat sv = svm->getSupportVectors();

const int sv_total = sv.rows; Mat

Mat alpha, svidx;

double rho = = svm->getDecisionFunction(0, alpha, alpha, svidx);

CV_Assert( alpha.total() == 1 && svidx.total() == 1 && sv_total == 1 );