Giter VIP home page Giter VIP logo

fast_pytorch_kmeans's Introduction

Fast Pytorch Kmeans

this is a pytorch implementation of K-means clustering algorithm

Installation

pip install fast-pytorch-kmeans

Quick Start

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)

Speed Comparison

Tested on google colab with Intel(R) Xeon(R) CPU @ 2.00GHz and Nvidia Tesla T4 GPU

sklearn: sklearn.cluster.KMeans

  • n_init = 1
  • max_iter = 100
  • tol = -1 (to force 100 iterations)

faiss: faiss.Clustering

  • 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

fast-pytorch: fast_pytorch_kmeans.KMeans

  • max_iter = 100
  • tol = -1 (to force 100 iterations)
  • minibatch = None

1. n_samples=100,000, n_features=256, time spent for 100 iterations

2. n_samples=100,000, n_clusters=256, time spent for 100 iterations

3. n_features=256, n_clusters=256, time spent for 100 iterations

4. n_features=32, n_clusters=1024, time spent for 100 iterations

5. n_features=1024, n_clusters=32, time spent for 100 iterations

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.