this is a pytorch implementation of K-means clustering algorithm
pip install fast-pytorch-kmeans
from fast_pytorch_kmeans import KMeans
import torch
kmeans = KMeans(n_clusters=8, mode='euclidean', verbose=1)
x = torch.randn(100000, 64, device='cuda')
labels = kmeans.fit_predict(x)
Tested on google colab with Intel(R) Xeon(R) CPU @ 2.00GHz and Nvidia Tesla T4 GPU
- n_init = 1
- max_iter = 100
- tol = -1 (to force 100 iterations)
- nredo = 1
- niter = 100
- max_point_per_centroid = 10**9 (to prevent subsample from dataset)
note: time cost for transfering data from cpu to gpu is also included
- max_iter = 100
- tol = -1 (to force 100 iterations)
- minibatch = None