Skip to content Skip to sidebar Skip to footer

Do I Need To Calculate Hist At Prediction Time In Svm?

I am training my dataset with the below code: for file in glob.glob('C:\*.png'): image = cv2.imread(file, 1) image = cv2.resize(img, (60, 120)) hog = cv2.HOGDescriptor(

Solution 1:

According to your code, all the samples belong to the same class:

labels.append(-1)

Your SVM classifier can't learn anything from this. You need to present to SVM both positive examples (labeled as 1) and negative ones (usually labeled as 0 or -1). It would be helpful if your dataset is balanced: that is amount of positive and negative images is roughly the same.

After your SVM is trained properly, and hog is made aware of it (by hog.setSVMDetector()) using hog.detectMultiScale() or hog.detect() will "automatically" report positive matches. It combines two operation: calculates HOG descriptors and classifies them using provided SVM. In addition hog.detectMultiScale() automatically increases the image and optionally groups the overlapped detections.

Now why you need hog.compute(image) on the training phase: this calculates raw HOG descriptors. This is the input to your classifier. Those descriptors is just a bunch of numbers calculated in specific way, and by themselves do not indicate if there is an object that you are looking for in the image. To make this decision, you need some kind of a classifier, and SVM is just a possible choice. You do not have to use it, it just usually produces very good results, and is included as a default.

Update See how prediction is done in the OpenCV example:

Post a Comment for "Do I Need To Calculate Hist At Prediction Time In Svm?"