# Revision history [back]

### SVM weights to HOGDescriptor

Hey,

I am working on a detection algorithm and I got a working SVM classifier that uses HOG features calculated with a HOGDescriptor object. If I manually test this classifier (ie. feed it with positive and negative examples that have not been used for training), it classifies them fine. The step where I go from my SVM classifier to the HOGDescriptor is where I assume it goes wrong, it doesn't identify a single object correctly. I have no idea where to start how to debug this..

Here is my code: https://dl.dropboxusercontent.com/u/40610835/HOG%20Detection.html

Any help is greatly appreciated!

Best regards, Hans

### SVM weights to HOGDescriptor

Hey,

I am working on a detection algorithm and I got a working SVM classifier that uses HOG features calculated with a HOGDescriptor object. If I manually test this classifier (ie. feed it with positive and negative examples that have not been used for training), it classifies them fine. The step where I go from my SVM classifier to the HOGDescriptor is where I assume it goes wrong, it doesn't identify a single object correctly. I have no idea where to start how to debug this..

Here is my code: https://dl.dropboxusercontent.com/u/40610835/HOG%20Detection.html

Any help is greatly appreciated!

Best regards, Hans

Update:

To make things clearer so you don't have to go through the entire code, this is where I read in data from the stored SVM classifier:

# load the stored SVM
f = open('model.svm', 'r')
rho = model['my_svm']['decision_functions'][0]['rho']
svm_detector = np.array(model['my_svm']['support_vectors'])[0,:]
hog.setSVMDetector(np.hstack([svm_detector, rho]))


There is only one support vector in my classifier, I assumed the SVM weights I need to give to HOGDescriptor are these weights with appended the threshold. The HOGDescriptor is initialised as follows :

self.hog = cv2.HOGDescriptor((64,64), (16,16), (8,8), (8,8), 9)


Detection is then simply done using :

locations, weights = hog.detectMultiScale(image)


I didn't quite understand what the parameters in detectMultiScale do exactly and there isn't much documentation regarding their effects. I supplied the SVM with objects of size 64x64 which didn't differ much from the default size of 64x128 so I kept the rest of the parameters the same.

### SVM weights to HOGDescriptor

Hey,

I am working on a detection algorithm and I got a working SVM classifier that uses HOG features calculated with a HOGDescriptor object. If I manually test this classifier (ie. feed it with positive and negative examples that have not been used for training), it classifies them fine. The step where I go from my SVM classifier to the HOGDescriptor is where I assume it goes wrong, it doesn't identify a single object correctly. I have no idea where to start how to debug this..

Here is my code: https://dl.dropboxusercontent.com/u/40610835/HOG%20Detection.html

Any help is greatly appreciated!

Best regards, Hans

Update:

To make things clearer so you don't have to go through the entire code, this is where how I read in data from the stored SVM classifier:

# load the stored SVM
f = open('model.svm', 'r')
rho = model['my_svm']['decision_functions'][0]['rho']
svm_detector = np.array(model['my_svm']['support_vectors'])[0,:]
hog.setSVMDetector(np.hstack([svm_detector, rho]))


There is only one support vector in my classifier, I assumed the SVM weights I need to give to HOGDescriptor HOGDescriptor.setSVMDetector are these weights with appended the threshold. threshold (stored as 'rho' in the yaml file). The HOGDescriptor is initialised as follows :

self.hog = cv2.HOGDescriptor((64,64), (16,16), (8,8), (8,8), 9)


Detection is then simply done using :

locations, weights = hog.detectMultiScale(image)


I didn't quite understand what the parameters in detectMultiScale do exactly and there isn't much documentation regarding their effects. I supplied the SVM with objects of size 64x64 which didn't differ much from the default size of 64x128 so I kept the rest of the parameters the same.same. I tried 'playing' around with them, but did not achieve much better results.

The summary of my issue now is: If I manually cut out unseen positive/negative examples, my SVM classifier of OpenCV correctly classifies its labels (using SVM.predict). However if I use this classifier inside a HOGDescriptor with mostly default parameters and use HOGDescriptor.detectMultiScale, I get unexpected results (ie. only a few detections at false locations). I have two assumptions, either my parameters are incorrect or my process of getting the SVM weights from the SVM classifier to the HOGDescriptor is false.

### SVM weights to HOGDescriptor

Hey,

I am working on a detection algorithm and I got a working SVM classifier that uses HOG features calculated with a HOGDescriptor object. If I manually test this classifier (ie. feed it with positive and negative examples that have not been used for training), it classifies them fine. The step where I go from my SVM classifier to the HOGDescriptor is where I assume it goes wrong, it doesn't identify a single object correctly. I have no idea where to start how to debug this..

Here is my code: https://dl.dropboxusercontent.com/u/40610835/HOG%20Detection.html

Any help is greatly appreciated!

Best regards, Hans

Update:

To make things clearer so you don't have to go through the entire code, this is how I read in data from the stored SVM classifier:

# load the stored SVM
f = open('model.svm', 'r')
rho = model['my_svm']['decision_functions'][0]['rho']
svm_detector = np.array(model['my_svm']['support_vectors'])[0,:]
hog.setSVMDetector(np.hstack([svm_detector, rho]))


There is only one support vector in my classifier, I assumed the SVM weights I need to give to HOGDescriptor.setSVMDetector are these weights with appended the threshold (stored as 'rho' in the yaml file). The HOGDescriptor is initialised as follows :

self.hog = cv2.HOGDescriptor((64,64), (16,16), (8,8), (8,8), 9)


Detection is then simply done using :

locations, weights = hog.detectMultiScale(image)


I didn't quite understand what the parameters in detectMultiScale do exactly and there isn't much documentation regarding their effects. I supplied the SVM with objects of size 64x64 which didn't differ much from the default size of 64x128 so I kept the rest of the parameters the same. I tried 'playing' around with them, but did not achieve much better results.

The summary of my issue now is: If I manually cut out unseen positive/negative examples, my SVM classifier of OpenCV correctly classifies its labels (using SVM.predict). However if I use this classifier inside a HOGDescriptor with mostly default parameters and use HOGDescriptor.detectMultiScale, I get unexpected results (ie. only a few detections at false locations). I have two assumptions, either my parameters are incorrect or my process of getting the SVM weights from the SVM classifier to the HOGDescriptor is false.