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
- 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__)"
- 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
Release history Release notifications | RSS feed
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.2.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file kmeans_gpu-0.0.2.tar.gz
.
File metadata
- Download URL: kmeans_gpu-0.0.2.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc387dcf16c44efdfe94aa635534cb1b942d1ae58afd20dc64bc07a4f68556e1 |
|
MD5 | c2beb22822978b46bf8d13c7b0eb046a |
|
BLAKE2b-256 | 5b4ff2b4997ec6320c7bc563b8891622115508cad68442a798149dca16170b59 |
File details
Details for the file kmeans_gpu-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: kmeans_gpu-0.0.2-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 375dedba1410c1ae4e1a95bf9f9a26533b41d435bc1de2d97a481a4ffbdb3cea |
|
MD5 | c98c8769aa37243bffff29d23466ebfb |
|
BLAKE2b-256 | c059bfa923aa3c6cd63060b193416656dda4fe3a938f6e9b027240b3a8b432b7 |