TrainHOG.exe svm trainAuto error
I'm using OpenCV 3.4.3 with C++ and i try to train my svm using TrainHOG.exe(you can find it on opencv docs). I've prepared dataset(combination of INRIA person dataset and a few more my own cropped images) but results of svm i get using params(like below) gives me too many false positives:
Ptr< SVM > svm = SVM::create();
/* Default values to train SVM */
svm->setCoef0(0.0);
svm->setDegree(3);
svm->setTermCriteria(TermCriteria(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 1000, 1e-3));
svm->setGamma(0);
svm->setKernel(SVM::LINEAR);
svm->setNu(0.5);
svm->setP(0.1); // for EPSILON_SVR, epsilon in loss function?
svm->setC(0.01); // From paper, soft classifier
svm->setType(SVM::EPS_SVR); // C_SVC; // EPSILON_SVR; // may be also NU_SVR; // do regression task
svm->train(train_data, ROW_SAMPLE, labels);
So i've changed train to trainAuto and it gives me this error multiple times:
OpenCV(3.4.3) Error: Assertion failed (sv_count != 0) in cv::ml::SVMImpl::do_train, file C:\build\3_4_winpack-build-win64-vc14\opencv\modules\ml\src\svm.cpp, line 1404
and then crashes with this error:
OpenCV(3.4.3) Error: Assertion failed (0 <= i && i < (int)decision_func.size()) in cv::ml::SVMImpl::getDecisionFunction, file C:\build\3_4_winpack-build-win64-vc14\opencv\modules\ml\src\svm.cpp, line 2033
I've checked that lines in svm.cpp (https://github.com/opencv/opencv/blob...) and the last assert giving me error is here:
double getDecisionFunction(int i, OutputArray _alpha, OutputArray _svidx ) const CV_OVERRIDE
{
CV_Assert( 0 <= i && i < (int)decision_func.size());
const DecisionFunc& df = decision_func[i];
int count = getSVCount(i);
Mat(1, count, CV_64F, (double*)&df_alpha[df.ofs]).copyTo(_alpha);
Mat(1, count, CV_32S, (int*)&df_index[df.ofs]).copyTo(_svidx);
return df.rho;
}
Since i = 0 (in TrainHog.exe):
vector< float > get_svm_detector(const Ptr< SVM >& svm){
// get the support vectors
Mat sv = svm->getSupportVectors();
const int sv_total = sv.rows;
// get the decision function
Mat alpha, svidx;
double rho = svm->getDecisionFunction(0, alpha, svidx);
CV_Assert(alpha.total() == 1 && svidx.total() == 1 && sv_total == 1);
CV_Assert((alpha.type() == CV_64F && alpha.at<double>(0) == 1.) ||
(alpha.type() == CV_32F && alpha.at<float>(0) == 1.f));
CV_Assert(sv.type() == CV_32F);
vector< float > hog_detector(sv.cols + 1);
memcpy(&hog_detector[0], sv.ptr(), sv.cols * sizeof(hog_detector[0]));
hog_detector[sv.cols] = (float)-rho;
return hog_detector;
}
assertion fails due to second condition (i < (int)decision_func.size()), but i don't know what it means and still don't know what am i doing wrong.
Sorry for my bad eng and thanks in advance.
please, no screeenshots of code or errors here. pleae give us a text version instead,which can be properly quoted, indexed,etc.
now fixed, sorry for that
you need a LINEAR svm for this (default is RBF), else you cannot export a single (1d) support vector for the HOGDetector
but here:
svm->setKernel(SVM::LINEAR);
i've set a linear kernel and didn't change itor i need set that property in somewhere else?
hmm, it's unclear, wh at you're doing exactly, there. can yoou try to clean upp your question, and focus on the "trainAuto" part ?
also note, that a linear svm only uses C and coef0 params (all others are bogus)