diff --git a/utils/autoanchor.py b/utils/autoanchor.py index eef8f6499194..d055de312f69 100644 --- a/utils/autoanchor.py +++ b/utils/autoanchor.py @@ -126,9 +126,10 @@ def print_results(k, verbose=True): # Kmeans calculation LOGGER.info(f'{PREFIX}Running kmeans for {n} anchors on {len(wh)} points...') s = wh.std(0) # sigmas for whitening - k, dist = kmeans(wh / s, n, iter=30) # points, mean distance - assert len(k) == n, f'{PREFIX}ERROR: scipy.cluster.vq.kmeans requested {n} points but returned only {len(k)}' - k *= s + k = kmeans(wh / s, n, iter=30)[0] * s # points + if len(k) != n: # kmeans may return fewer points than requested if wh is insufficient or too similar + LOGGER.warning(f'{PREFIX}WARNING: scipy.cluster.vq.kmeans returned only {len(k)} of {n} requested points') + k = np.sort(np.random.rand(n * 2)).reshape(n, 2) * img_size # random init wh = torch.tensor(wh, dtype=torch.float32) # filtered wh0 = torch.tensor(wh0, dtype=torch.float32) # unfiltered k = print_results(k, verbose=False)