HOG setSVMDetector slow [closed]
I'm using HOG with custom svm. I've used https://github.com/opencv/opencv/blob... but my feature vector has 2268 features and get_svm_detector() give me 2269 support vectors, this don't give me error but hog.detectMultiScale is very slow ( ~ 6 s), why?
With svmLight I get 2268 support vectors and hog.detectMultiScale takes about ~64 ms.
I Add the code:
Ptr<SVM> svm;
Ptr<TrainData> trainData = TrainData::loadFromCSV("./trainData.csv");
svm = SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::LINEAR);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, (int)1000, 1e-3));
svm->trainAuto(trainData,10,SVM::getDefaultGrid(SVM::C),SVM::getDefaultGrid(SVM::GAMMA),SVM::getDefaultGrid(SVM::P),SVM::getDefaultGrid(SVM::NU),SVM::getDefaultGrid(SVM::COEF),SVM::getDefaultGrid(SVM::DEGREE),true );
svm->save("model.yml");
In other class:
HOGDescriptor hog;
Ptr<SVM> svm = StatModel::load<SVM>( "model.yml" );
Ptr<SVM> svm = StatModel::load<SVM>( "clasificador.yml" );
vector< float > hog_detector;
// 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 );
hog_detector.clear();
hog_detector.resize(sv.cols + 1);
memcpy(&hog_detector[0], sv.ptr(), sv.cols*sizeof(hog_detector[0]));
hog_detector[sv.cols] = (float)-rho;
hog.setSVMDetector( hog_detector );
// Then, it take me about 6 s!!
hog.detectMultiScale(img, detections, thresholdDetection, winStride, padding);
rho
value, so yes, it will have one more element that the feature vectorOk. Done !
It seems ok. Once again, please post the multiscale params and input image size. That is likely the problem (if you're sure to be in release mode)
Hi LorenaGdL I have seen http://stackoverflow.com/questions/21... If I put rho as an argument in HOGDescriptor::detectMultiScale call it take me about 64 ms so it's ok but I don't understand why
I see that if I don't put rho in setSVMDetector and I put in detectMultiScale in hitThreshold with -3.8 it take me ~6 s and for example 4 take me ~64 ms... WTF?
You're shifting the hyperplane, so your number of detections will differ. I guess the differences in time are related to grouping, but still it way too much difference... If you provide your trained SVM model and test image, I may take a look if I have time
Thanks for your help! I found that it give me 39802 detections without activate mean-shift!