kmeans-gpu
kmeans-gpu with pytorch (batch version). It is faster than sklearn.cluster.KMeans. What's more, it is a differential operation which will back-propagate gradient to previous layers.
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])
Metadata
Release files for kmeans-gpu 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kmeans_gpu-0.0.5.tar.gz | 5.1 kB | Without provenance | Details for kmeans_gpu-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kmeans_gpu-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for kmeans_gpu-0.0.5-py3-none-any.whl |
Total release size: 11.4 kB
Release files / kmeans_gpu-0.0.5.tar.gz
| Download URL | kmeans_gpu-0.0.5.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fff62d46e3f1167bf22b144cb168c1471c5433942319e4e7eaa47ee3f1f4db37
|
|
BLAKE2b-256 checksum How to use checksums |
87c3816436cb7fd4e487cd190b53e85b42c3e2e4fdd8f0b29f7612e7feea97e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / kmeans_gpu-0.0.5-py3-none-any.whl
| Download URL | kmeans_gpu-0.0.5-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e7a79be558d507f4c8e3c892527df3832817020c649dd26a2a0cadd6bc2cb46
|
|
BLAKE2b-256 checksum How to use checksums |
6c7534e4182b4f1512b7ec48d25b56368a29896db9c556b160088064836189df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for kmeans-gpu 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.