Ask Your Question

Umar Farooq's profile - activity

2017-05-31 21:59:00 -0600 commented question Why does my custom HOG detector always draws a rectangle on the center of image even when I have obtained good accuracies on Test data?

Hi, thanks for your reply. The problem is same even if I don't apply the non max suppression. I have already provided the codes. I think, the problem is with SVM training and/or Support vectors extraction. Can you please lookup those parts and maybe suggestion something? :/

2017-05-27 00:52:04 -0600 received badge  Enthusiast
2017-05-25 05:26:11 -0600 commented question Why does my custom HOG detector always draws a rectangle on the center of image even when I have obtained good accuracies on Test data?

svm = cv2.ml.SVM_create() svm.setType(cv2.ml.SVM_EPS_SVR) svm.setKernel(cv2.ml.SVM_LINEAR) svm.setGamma(0) svm.setC(10) svm.setNu(0.5) svm.setP(0.1) svm.setC(0.01) svm.setTermCriteria((cv2.TermCriteria_MAX_ITER+cv2.TermCriteria_EPS, 1000, 1e-3))

Unfortunately, this didn't work either. :/

2017-05-25 04:38:17 -0600 commented question Why does my custom HOG detector always draws a rectangle on the center of image even when I have obtained good accuracies on Test data?

Hi, thanks for your reply. I was using these parameters for SVM training: svm = cv2.ml.SVM_create() svm.setType(cv2.ml.SVM_C_SVC) svm.setKernel(cv2.ml.SVM_LINEAR) svm.setGamma(0.0001) svm.setC(10)

Now, I tried with regression too: svm = cv2.ml.SVM_create() svm.setType(cv2.ml.SVM_EPS_SVR) svm.setKernel(cv2.ml.SVM_LINEAR) svm.setP(0.1)

The support vectors are again not even close to the default support vectors and the rectangle is still being drawn in the center.

2017-05-25 03:29:36 -0600 asked a question Why does my custom HOG detector always draws a rectangle on the center of image even when I have obtained good accuracies on Test data?

I am trying to make a custom HOG detector. Before working on my dataset, I am trying to verify the results on INRIA dataset. I have extracted features from hog.compute function and then used those features to train an SVM classifier.

Using the svm.predict command, I tested the accuracies on test data provided by INRIA. I got 97.3% accuracy on pos test data, and 99.6% on neg test data (neg images were resized to 64x128. I tried with cropping to 64x128 as well and the accuracy was 95.4%)

I used the following code to find the support vectors and rho to provide to the setSVMdetector function:

(rho, alpha, supportVectorIndices) = svm.getDecisionFunction(0)
supportVectors = svm.getSupportVectors().ravel()
supportVectors = np.append(supportVectors, -rho)
pickle.dump(supportVectors, open("svm.pickle", 'wb'))
print("FINISHED!")

However, when I run the code, the rectangle is always drawn in the center before or after the NMS. Check here: image description

Below is the code provided by OpenCV for HOG detector. I have just made a change in the setSVMDetector function where I am providing my trained support vectors now.

hog = cv2.HOGDescriptor() svm = pickle.load(open("svmcoeff.pickle", 'rb')) hog.setSVMDetector(np.array(svm))

for i in range(1,9): image = cv2.imread('test-'+str(i)+'.png') image = imutils.resize(image, width=min(300, image.shape[1])) orig = image.copy() (rects, weights) = hog.detectMultiScale(image)

for (x, y, w, h) in rects: cv2.rectangle(orig, (x, y), (x + w, y + h), (0, 0, 255),2) rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects]) pick = non_max_suppression(rects, probs=None,overlapThresh=0.65)

for (xA, yA, xB, yB) in pick: cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2) cv2.imshow("Before NMS", orig) cv2.imshow("After NMS", image) key = cv2.waitKey(0) if key == 27: continue

2017-05-20 05:50:37 -0600 commented question Why does my custom HOG detector always draws a rectangle on the center of image and not on the person?

Well, the results before non max suppression are the same i.e. It always draws a rectangle in the center.

2017-05-20 05:25:33 -0600 asked a question Why does my custom HOG detector always draws a rectangle on the center of image and not on the person?

I have extracted features from hog.compute function and then used those features to train an SVM classifier. I used a script that I found online to separate rho and support vectors from the classified file.

tree = ET.parse('svm_data.xml')
root = tree.getroot()
SVs = root.getchildren()[0].getchildren()[-2].getchildren()[0]

rho = float( root.getchildren()[0].getchildren()[-1].getchildren()[0].getchildren()[1].text)
svmvec = [float(x) for x in re.sub( '\s+', ' ', SVs.text).strip().split(' ')]
svmvec.append(-rho)
pickle.dump(svmvec, open("svm.pickle", 'wb'))

This code saved the rho and support vectors to a different file which I provided to the hog.DetectMultiScale function. Initially I got the CheckDetectorSize errors, but somehow i dealt with them. But now that it finally executes, why does it always draw a rectangle on the center instead of a person? Check:

The final code that uses the file generated from the above code, to draw rectangles on the detected area(s):

hog = cv2.HOGDescriptor("hog.xml") svm = pickle.load(open("svmcoeff.pickle", 'rb')) hog.setSVMDetector(np.array(svm))

for i in range(1,9): image = cv2.imread('test-'+str(i)+'.png') image = imutils.resize(image, width=min(300, image.shape[1])) orig = image.copy()

    (rects, weights) = hog.detectMultiScale(image)

    for (x, y, w, h) in rects:
            cv2.rectangle(orig, (x, y), (x + w, y + h), (0, 0, 255),2)

    rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])
    pick = non_max_suppression(rects, probs=None,overlapThresh=0.65)

    for (xA, yA, xB, yB) in pick:
            cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2)

    cv2.imshow("Before NMS", orig)
    cv2.imshow("After NMS", image)

    key = cv2.waitKey(0)
    if key == 27: # escape
            continue