Ask Your Question
0

OpenCV Assertion failed in function 'setSVMDetector'

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

tomcat gravatar image

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

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

Comments

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 -0600 )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 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

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

berak gravatar image

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

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

Comments

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 -0600 )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 -0600 )edit

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

tomcat gravatar imagetomcat ( 2019-03-12 07:01:59 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 945 times

Last updated: Mar 12 '19