Ask Your Question
0

Slow SVM.predict speed

asked 2013-04-24 07:19:04 -0600

sub_o gravatar image

I'm writing a sliding window to extract features and feed it into CvSVM's predict function. However, what I've stumbled upon is that the svm.predict function is relatively slow.

Basically the window slides thru the image with fixed stride length, on number of image scales.

  • The speed traversing the image plus extracting features for each window takes around 1000 ms (1 sec).
  • Inclusion of weak classifiers trained by adaboost resulted in around 1200 ms (1.2 secs)
  • However when I pass the features (which has been marked as positive by the weak classifiers) to svm.predict function, the overall speed slowed down to around 16000 ms ( 16 secs )
  • Trying to collect all 'positive' features first, before passing to svm.predict utilizing TBB's threads resulted in 19000 ms ( 19 secs ), probably due to the overhead needed to create the threads, etc.

My OpenCV build was compiled to include both TBB (threading) and OpenCL (GPU) functions.

Has anyone managed to speed up OpenCV's SVM.predict function ?

I've been stuck in this issue for quite sometime, since it's frustrating to run this detection algorithm thru my test data for statistics and threshold adjustment.

Thanks a lot for reading thru this !

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-04-24 07:33:47 -0600

zerog80 gravatar image

How many features are you extracting for each window?

edit flag offensive delete link more

Comments

3780 features. I found out that there's 4417 support vectors in my SVM. Maybe I should train with different C value, or I should switch to RandomForest

sub_o gravatar imagesub_o ( 2013-04-24 07:38:07 -0600 )edit

Woa, that's a lot! I suppose that's the primary reason for the slow down... have you tried LIBLINEAR (http://www.csie.ntu.edu.tw/~cjlin/liblinear)? Radial-basis functions are the most general kernels, but if your problem can be well described even with linear kernels, you can benefit from greater speed using this optimized SVM library.

zerog80 gravatar imagezerog80 ( 2013-04-24 09:18:59 -0600 )edit
1

Yeah, I was using linear C_SVM with C set to 0.001, it ended up with more than 4000 support vectors. I've since reduced it to 0.1, giving me around 650 support vecs, and the whole thing sped up to around 4 seconds now.

sub_o gravatar imagesub_o ( 2013-04-24 13:43:56 -0600 )edit

Question Tools

Stats

Asked: 2013-04-24 07:19:04 -0600

Seen: 1,495 times

Last updated: Apr 24 '13