How to speed up svm.predict?
computer-vision, machine-learning, object-detection, opencv, svm
Solution
(Answer posted to formalize my comments, above:)
The prediction algorithm for an SVM takes O(nSV * f) time, where nSV is the number of support vectors and f is the number of features. The number of support vectors can be reduced by training with stronger regularization, i.e. by increasing the hyperparameter C (possibly at a cost in predictive accuracy).
Problem
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 !