code: def k_means(boxes, k, dist=np.median):
      """
      yolo k-means methods
      refer: https://github.com/qqwweee/keras-yolo3/blob/master/kmeans.py
      Args:
          boxes: 需要聚类的bboxes
          k: 簇数(聚成几类)
          dist: 更新簇坐标的方法(默认使用中位数，比均值效果略好)
      """
      box_number = boxes.shape[0]
      last_nearest = np.zeros((box_number,))
      # np.random.seed(0)  # 固定随机数种子
  
      # init k clusters
      clusters = boxes[np.random.choice(box_number, k, replace=False)]
  
      while True:
          distances = 1 - wh_iou(boxes, clusters)
          current_nearest = np.argmin(distances, axis=1)
          if (last_nearest == current_nearest).all():
              break  # clusters won't change
          for cluster in range(k):
              # update clusters
              clusters[cluster] = dist(
                  boxes[current_nearest == cluster], axis=0
              )
  
          last_nearest = current_nearest
  
      return clusters
  
label_desc: Use image node_id 2 for calling a global function with example usage: k_means(boxes, k, dist) and returns: clusters