how to get detector from trained svm classifier?

asked 2015-10-19 22:10:06 -0500

Carrot_Luobo gravatar image

updated 2015-10-19 22:19:35 -0500

I have trained a classifer using https://github.com/Itseez/opencv/blob.... The number of positive samples is 48404 and negative samples is 46112. When I used this classifer to detect pedestrain, it's very slow and the accuracy is low. The detection time is 48741 ms. The result likes this. image description But after I changed memcpy(&hog_detector[0], sv.ptr(), sv.colssizeof(hog_detector[0])); hog_detector[sv.cols] = (float)-rho;* to for (int i = 0; i < sv.cols; i++) { hog_detector[i] = -1.0 * sv.at<float>(0, i); } hog_detector[sv.cols] = (float)rho; in function void get_svm_detector(const Ptr<svm>& svm, vector< float > & hog_detector ). It runs faster. The detection time is 229 ms. And the result likes this.image description The classifier file is here.

%YAML:1.0 opencv_ml_svm: format: 3 svmType: C_SVC kernel: type: LINEAR C: 1.0000000000000000e-002 term_criteria: { epsilon:1.0000000000000000e-003, iterations:1000 } var_count: 3780 class_count: 2 class_labels: !!opencv-matrix rows: 2 cols: 1 dt: i data: [ -1, 1 ] sv_total: 1 support_vectors: - [ -2.61618104e-002, 3.29752220e-003, -1.29569806e-002, -1.12012550e-002, -8.74134805e-003, -6.53320318e-003, -3.21041122e-002, -2.55674440e-002, -3.50760855e-002, 3.24817514e-003, 3.41469869e-002, 1.29222346e-003, 9.22481716e-003, 6.77467836e-003, 1.76859535e-002, -1.00619644e-002, 2.88390107e-002, 3.63118458e-003, 1.11764949e-002, -6.04125811e-003, -1.21065676e-002, 1.03153777e-003, 4.79206350e-003, -1.64222717e-002, -1.88224390e-002, 1.62412897e-002, 1.12246191e-002, -2.35342365e-002, -2.75968462e-002, -2.44492255e-002, -1.75507385e-002, -1.55860670e-002, 6.22355659e-003, -1.01223858e-002, 4.47303429e-003, -1.75614469e-002, 3.16085070e-002, 3.35494950e-002, -1.66904479e-002, -1.37733119e-002, -3.94618288e-002, -2.60138232e-003, -2.71661766e-003, 7.18792621e-003, -9.18724050e-004, -4.07458469e-003, 3.13395336e-002, 9.37333424e-003, -1.52530726e-002, 9.07706795e-004, 1.94377359e-002, -1.75151993e-002, 1.08474717e-002, 3.96036310e-003, 2.15834118e-002, 2.32734717e-002, 1.88815035e-002, 1.57858804e-002, 3.23888892e-003, 3.68875405e-003, -1.83888581e-002, -6.14443002e-003, -1.16924709e-002, -1.67173408e-002, 7.59448856e-003, -8.33225157e-003, -1.45257283e-002, -1.08752074e-002, 1.07218837e-002, -8.17408785e-003, -5.13659185e-003, -1.44050429e-002, -2.39342893e-003, 1.92435868e-002, 6.73404848e-003, -1.64275095e-002, -1.90112870e-002, 6.39248407e-003, -9.23749991e-003, 1.19611761e-002, -8.10686219e-003, -1.00341253e-002, 2.47316696e-002, 1.70847308e-002, -3.35685574e-002, 5.13448264e-004, -6.48480561e-003, -5.78575348e-003, -3.38072260e-003, -2.71195117e-002, 1.01758093e-002, 3.86057384e-002, 8.95520020e-003, 3.46415589e-004, -4.19306494e-002, 2.00298688e-004, 5.11392672e-003, 1.15226433e-002, 5.49867377e-003, -1.21823279e-002, -1.02344630e-002, -5.06448708e-002, -7.71879405e-003, 5.62696345e-003, -6.04462810e-004, 1.87349077e-002, 3.13645159e-003, 2.87968628e-002, 9.70883295e-003, -4.77860589e-003, 2.40449719e-002, -1.66048110e-002, -7.71959429e-004, 2.48634256e-003, -1.43477162e-002, -3.25499848e-003, 2.71445257e-003, -3.28949769e-003, -1.05718896e-002, -3.32521554e-003, -2.63770260e-002, 4.32192069e-003, 3.45772854e-003, -7.55985687e-003, 2.87076924e-004, -4.84112464e-003, -3.73025308e-003, -2.67593772e-003, -5.01684844e-003, -1.40723854e-003, 1.30347221e-003, -1.28104945e-003, -9.75206960e-003, 1.02300942e-002, 2.87724398e-002, -1.70896929e-002, -3.62180127e-003, -9.85278841e-003, -4.72208159e-003, -2.08622348e-002, 1.79161131e-003, 4.86647896e-003, -8.62068217e-003, 1.08850086e-002, 1.50047913e-002, 1.44095696e-003, 2.39002258e-002, 9.12052696e-004, -1.88567431e-003, -8.95227422e-004, 9.41945426e-003, -2.34682346e-003, 1.45589076e-002, -9.93138831e-003, -6.70361286e-003, 1.47702936e-002, -3.44369896e-002, 1.12099899e-002, 2.96752919e-002, 6.11413456e-003, 1.34498149e-003, -3.65853542e-003, 1.78316254e-002, 2.25753915e-002, 1.68638453e-002, 2.69341492e-003, -2.81611588e-002, -1.53523451e-003, 1.56830717e-003, 3 ... (more)

edit retag flag offensive close merge delete

Comments

Start by removing that huge chunck of model and add a pastebin link instead. As to your problem, it seems that you might have found a bug in the sourcecode. Mind making an issue for it at the github page?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-20 04:33:36 -0500 )edit
1

but why changing the sign of rho?

LorenaGdL gravatar imageLorenaGdL ( 2015-10-20 05:05:26 -0500 )edit