Ask Your Question

OpenCV Assertion failed in function 'setSVMDetector'

asked 2019-03-12 04:06:30 -0500

tomcat gravatar image

updated 2019-03-12 06:54:14 -0500

berak gravatar image

I am learning how to train custom HOG descriptor for pedestrians detection. When I pass parameters to the hog object using following code

rho, _, _ = svm.getDecisionFunction(0)
sv = svm.getSupportVectors()
hog.setSVMDetector(np.append(sv.ravel(), rho))
found = hog.detectMultiScale(img_test)

I came across this error:

error                                     Traceback (most recent call last)
<ipython-input-23-445de3dc92d7> in <module>
      1 rho, _, _ = svm.getDecisionFunction(0)
      2 sv = svm.getSupportVectors()
----> 3 hog.setSVMDetector(np.append(sv.ravel(), rho))

error: OpenCV(4.0.0) /Users/travis/build/skvark/opencv-python/opencv/modules/objdetect/src/hog.cpp:115: error: (-215:Assertion failed) checkDetectorSize() in function 'setSVMDetector'

A complete ipynotebook is available here The error is present on line 23.

The test image is present at this link

How do I solve this.

edit retag flag offensive close merge delete


In order to debug this issue I printed values which are going in numpy array as follows>> print(sv.ravel(), hroi, wroi) >> [0.22357965 0.05119441 0.04227823 ... 0.1384378 0.05082156 0.25953224] 128 64

tomcat gravatar imagetomcat ( 2019-03-12 04:22:42 -0500 )edit
  • please put your code here, not on an external notebook (where it will expire)
  • show us how you setup the SVM (LINEAR kernel ?)
  • the shape of the final SVMDetector ?
berak gravatar imageberak ( 2019-03-12 04:23:14 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-03-12 04:37:46 -0500

berak gravatar image

updated 2019-03-12 04:39:01 -0500

you need a LINEAR .SVM kernel (default is RBF), else the support vector cannot be compressed to an 1d "single" one.

also: SVM type should be C_SVR (regression, not classification)

edit flag offensive delete link more


LINEAR .SVM kernel solved the issue. However I cannot get anything in found where found = hog.detectMultiScale(img_test)

tomcat gravatar imagetomcat ( 2019-03-12 06:49:58 -0500 )edit
  • please have another look at trainHOG.cpp, on how to tweak SVM params
  • you probably need more better data
  • "Now that I have made a fairly accurate model " -- no. you trained / tested for classification, while the final algo does regression
berak gravatar imageberak ( 2019-03-12 06:57:30 -0500 )edit

Thanks for the pointers I probably need to make these changes before moving further

tomcat gravatar imagetomcat ( 2019-03-12 07:01:59 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-03-12 04:06:30 -0500

Seen: 148 times

Last updated: Mar 12