This commit is contained in:
Glenn Jocher 2020-01-06 13:59:08 -08:00
parent af23270482
commit fd0769c476
1 changed files with 2 additions and 2 deletions

View File

@ -782,7 +782,7 @@ def kmean_anchors(path='../coco/train2017.txt', n=9, img_size=(320, 640)):
from scipy.cluster.vq import kmeans from scipy.cluster.vq import kmeans
print('Running kmeans for %g anchors on %g points...' % (n, len(wh))) print('Running kmeans for %g anchors on %g points...' % (n, len(wh)))
s = wh.std(0) # sigmas for whitening s = wh.std(0) # sigmas for whitening
k, dist = kmeans(wh / s, n, iter=20) # points, mean distance k, dist = kmeans(wh / s, n, iter=30) # points, mean distance
k *= s k *= s
k = print_results(thr, wh, k) k = print_results(thr, wh, k)
@ -798,7 +798,7 @@ def kmean_anchors(path='../coco/train2017.txt', n=9, img_size=(320, 640)):
wh = torch.Tensor(wh) wh = torch.Tensor(wh)
f, ng = fitness(thr, wh, k), 1000 # fitness, generations f, ng = fitness(thr, wh, k), 1000 # fitness, generations
for _ in tqdm(range(ng), desc='Evolving anchors'): for _ in tqdm(range(ng), desc='Evolving anchors'):
kg = (k.copy() * (1 + np.random.random() * np.random.randn(*k.shape) * 0.20)).clip(min=2.0) kg = (k.copy() * (1 + np.random.random() * np.random.randn(*k.shape) * 0.30)).clip(min=2.0)
fg = fitness(thr, wh, kg) fg = fitness(thr, wh, kg)
if fg > f: if fg > f:
f, k = fg, kg.copy() f, k = fg, kg.copy()