Skip to main content

KMeans-GPU: A PyTorch Module for KMeans.

Project description

kmeans-gpu

kmeans-gpu with pytorch (batch version). It is faster than sklearn.cluster.KMeans.

You can easily use KMeans as a nn.Module, and embed into your network structure.

Install

  1. From Git:
git clone git@github.com:densechen/kmeans-gpu.git
cd kmeans-gpu
pip install -r requirements.txt
python setup.py install

# check installation
python -c "import kmeans_gpu; print(kmeans_gpu.__version__)"
  1. From PyPI:
pip install kmeans-gpu

# check installation
python -c "import kmeans_gpu; print(kmeans_gpu.__version__)"

Demo

from kmeans_gpu import KMeans
import torch

# Config
batch_size = 128
feature_dim = 1024
pts_dim = 3
num_pts = 256
num_cluster = 15

# Create data
features = torch.randn(batch_size, feature_dim, num_pts)
# Pay attention to the different dimension order between features and points.
points = torch.randn(batch_size, num_pts, pts_dim)

# Create KMeans Module
kmeans = KMeans(
    n_clusters=num_cluster,
    max_iter=100,
    tolerance=1e-4,
    distance='euclidean',
    sub_sampling=None,
    max_neighbors=15,
)

# Forward
centroids, features = kmeans(points, features)

print(centroids.shape, features.shape)
# output: 
# >>> torch.Size([128, 15, 3]) torch.Size([128, 1024, 15])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kmeans_gpu-0.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distributions

kmeans_gpu-0.0.1-py3.7.egg (8.2 kB view details)

Uploaded Source

kmeans_gpu-0.0.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file kmeans_gpu-0.0.1.tar.gz.

File metadata

  • Download URL: kmeans_gpu-0.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

File hashes

Hashes for kmeans_gpu-0.0.1.tar.gz
Algorithm Hash digest
SHA256 11eef4ce99526d0cab03aac18687c366ee32fd284fa9cd0733b9bcfeccca8ae2
MD5 7992075fc6eb4dd14f2cf0fbadd37c56
BLAKE2b-256 92e64adddd76c616bc8c06224933b30cdc810f5dcd484ce6fcc92620bc201608

See more details on using hashes here.

File details

Details for the file kmeans_gpu-0.0.1-py3.7.egg.

File metadata

  • Download URL: kmeans_gpu-0.0.1-py3.7.egg
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

File hashes

Hashes for kmeans_gpu-0.0.1-py3.7.egg
Algorithm Hash digest
SHA256 26938c2c407845bcca4325fb43db2aa79a85b37a0a309686b4df4bc18f216e26
MD5 f2c2bca73f0060e8bf0c0eab7131d11c
BLAKE2b-256 2966377f6fcfc5c53e129a4ec0a56bbb1d4fac5c18d811ca724d4498c865aebe

See more details on using hashes here.

File details

Details for the file kmeans_gpu-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: kmeans_gpu-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

File hashes

Hashes for kmeans_gpu-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a771da60f968626084023ad15d7b2a04ff17e3a9c3e1a25accbe527905c0d1f
MD5 4e52b0336bfdf3f3a8c9b2600bfe7d87
BLAKE2b-256 846824c9c23c41ee1509a8e83ba1caa02329407cbbed5e3954ffa2010fc49733

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page