lars76 / kmeans-anchor-boxes

k-means clustering with the Intersection over Union (IoU) metric as described in the YOLO9000 paper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Applying in yolov3

virraaj opened this issue · comments

Hi, Thank you for your contribution.
I am getting a numpy array of the distances of every pixel in the bounding box. Now I am trying to apply k-means to get the median of distance to the object in my case person. Can you check if my approach is correct?

self.cluster = kmeans.kmeans(np.array(self.kmeans_box_data),2,np.median(self.person_bounding_box))

where self.kmeans_box_data is ((xmax-xmin)/w),(ymax-ymin)/h) 2 is the number of clusters and self.person_bounding_box is the array of distance at every pixel in the bounding box.
I am getting the following exception:

src/kmeans.py", line 11, in iou
    x = np.minimum(clusters[:, 0], box[0])
IndexError: too many indices for array

And when k is greater than 2, I get the following error:

kmeans.py", line 64, in kmeans
    clusters = boxes[np.random.choice(rows, k, replace=False)]
  File "mtrand.pyx", line 1168, in mtrand.RandomState.choice
ValueError: Cannot take a larger sample than population when 'replace=False'

Any suggestions are appreciated.