3D shape analysis using deep learning
Project description
Cellshape-cluster is an easy-to-use tool to analyse the cluster cells by their shape using deep learning and, in particular, deep-embedded-clustering. The tool provides the ability to train popular graph-based or convolutional autoencoders on point cloud or voxel data of 3D single cell masks as well as providing pre-trained networks for inference.
To install
pip install cellshape-cluster
Usage
Basic usage:
import torch
from cellshape_cloud import CloudAutoEncoder
from cellshape_cluster import DeepEmbeddedClustering
autoencoder = CloudAutoEncoder(
num_features=128,
k=20,
encoder_type="dgcnn"
)
model = DeepEmbeddedClustering(autoencoder=autoencoder,
num_clusters=10,
alpha=1.0)
points = torch.randn(1, 2048, 3)
recon, features, clusters = model(points)
To load a trained graph-based autoencoder and perform deep embedded clustering:
import torch
from torch.utils.data import DataLoader
import cellshape_cloud as cloud
import cellshape_cluster as cluster
from cellshape_cloud.vendor.chamfer_distance import ChamferDistance
dataset_dir = "path/to/pointcloud/dataset/"
autoencoder_model = "path/to/autoencoder/model.pt"
num_features = 128
k = 20
encoder_type = "dgcnn"
num_clusters = 10
num_epochs = 1
learning_rate = 0.00001
gamma = 1
divergence_tolerance = 0.01
output_dir = "path/to/output/"
autoencoder = CloudAutoEncoder(
num_features=128,
k=20,
encoder_type="dgcnn"
)
checkpoint = torch.load(autoencoder_model)
autoencoder.load_state_dict(checkpoint['model_state_dict']
model = DeepEmbeddedClustering(autoencoder=autoencoder,
num_clusters=10,
alpha=1.0)
dataset = cloud.PointCloudDataset(dataset_dir)
dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=False) # it is very important that shuffle=False here!
dataloader_inf = DataLoader(dataset, batch_size=1, shuffle=False) # it is very important that batch_size=1 and shuffle=False here!
optimizer = torch.optim.Adam(
model.parameters(),
lr=learning_rate * 16 / batch_size,
betas=(0.9, 0.999),
weight_decay=1e-6,
)
reconstruction_criterion = ChamferDistance()
cluster_criterion = nn.KLDivLoss(reduction="sum")
train(
model,
dataloader,
dataloader_inf,
num_epochs,
optimizer,
reconstruction_criterion,
cluster_criterion,
update_interval,
gamma,
divergence_tolerance,
output_dir
)
Parameters
autoencoder
: CloudAutoEncoder or VoxelAutoEncoder.
Instance of autoencoder class from cellshape-cloud or cellshape-voxelnum_clusters
: int.
The number of clusters to use in deep embedded clustering algorithm.alpha
: float.
Degrees of freedom for the Student's t-distribution. Xie et al. (ICML, 2016) let alpha=1 for all experiments.
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
cellshape-cluster-0.0.19.tar.gz
(11.4 kB
view details)
Built Distribution
File details
Details for the file cellshape-cluster-0.0.19.tar.gz
.
File metadata
- Download URL: cellshape-cluster-0.0.19.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59b86ba4b22146ff38fc6bf52ef7f97e6a8a4979a771b371ac3139e4f55c1b94 |
|
MD5 | 545a1b75efec200324585d9d92f6c237 |
|
BLAKE2b-256 | 7b2f71d7a5d9731400dc4792e670296dc5464ce064cf9d27afdaf97ac183cd78 |
File details
Details for the file cellshape_cluster-0.0.19-py3-none-any.whl
.
File metadata
- Download URL: cellshape_cluster-0.0.19-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 121b1474fe9eab4e9e6ec2c0d03b5df25dadd2ad5ae4a63785c2021b83536f3b |
|
MD5 | 07995c99e39fcc9de03c5b3a90e39947 |
|
BLAKE2b-256 | 99bacfb88694d0e998a67e5acd2ffbff8de838913b1d1296084b1e49a7d104b8 |