subhadarship / kmeans_pytorch

kmeans using PyTorch
https://subhadarship.github.io/kmeans_pytorch
MIT License
479 stars 77 forks source link

Does not work with 2D, 3D features #18

Open morawi opened 3 years ago

morawi commented 3 years ago

How to set the num_features?

morawi commented 3 years ago

I gave the code a go, since I was iterating over K=1,..., n; seems that K=1 was the source of the problem. Although there might not be sense of using K=1, we can prevent the error using:

Line 57 
dimens = 0 if num_clusters==1 else 1
choice_cluster = torch.argmin(dis, dim=dimens)   # choice_cluster = torch.argmin(dis, dim=1) 

dim=dimens should replace all dim=1 instances

Or, adding throw error message whenever num_clusters <2