Skip to content

modify the function init_centroids: - #1

Open
DanLiu0623 wants to merge 1 commit into
PaulChongPeng:masterfrom
DanLiu0623:patch-1
Open

modify the function init_centroids:#1
DanLiu0623 wants to merge 1 commit into
PaulChongPeng:masterfrom
DanLiu0623:patch-1

Conversation

@DanLiu0623

Copy link
Copy Markdown

use plus =1, the error occurs: centroids.append(boxes[centroid_index]) TypeError: only integer scalar arrays can be converted to a scalar index

use plus =1, the error occurs: centroids.append(boxes[centroid_index])  TypeError: only integer scalar arrays can be converted to a scalar index
@AhaEdgar

Copy link
Copy Markdown

请问,是不是修改了anchor boxes个数,运行k_means_yolo.py ,然后看loss最低的,就是最合适的anchor boxes个数以及anchor boxes 大小?是这样分析的吗?

返回值loss是所有box距离所属的最近的centroid的距离的和

def do_kmeans(n_anchors, boxes, centroids):
loss = 0
groups = []
new_centroids = []
for i in range(n_anchors):
groups.append([])
new_centroids.append(Box(0, 0, 0, 0))

for box in boxes:
    min_distance = 1
    group_index = 0
    for centroid_index, centroid in enumerate(centroids):
        distance = (1 - box_iou(box, centroid))
        if distance < min_distance:
            min_distance = distance
            group_index = centroid_index
    groups[group_index].append(box)
    loss += min_distance
    new_centroids[group_index].w += box.w
    new_centroids[group_index].h += box.h

for i in range(n_anchors):
    new_centroids[i].w /= len(groups[i])
    new_centroids[i].h /= len(groups[i])

return new_centroids, groups, loss

@ujsyehao

ujsyehao commented May 20, 2019

Copy link
Copy Markdown

use plus =1, the error occurs: centroids.append(boxes[centroid_index]) TypeError: only integer scalar arrays can be converted to a scalar index

just modify
centroids.append(boxes[centroid_index])
to
centroids.append(boxes[int(centroid_index)])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants