viscy-models
Neural network architectures for virtual staining microscopy.
Part of the VisCy project.
Installation
From PyPI (when published)
pip install viscy-models
For development (from monorepo root)
# Using uv (recommended)
uv pip install -e packages/viscy-models
# Or via workspace sync
uv sync --package viscy-models
Usage
from viscy_models import UNeXt2, FullyConvolutionalMAE
# All models are pure nn.Modules — no Lightning or Hydra coupling
model = UNeXt2(
in_channels=1,
out_channels=2,
in_stack_depth=5,
backbone="convnextv2_tiny",
)
# Contrastive encoders
from viscy_models import ContrastiveEncoder, ResNet3dEncoder
encoder = ContrastiveEncoder(
backbone="convnext_tiny",
in_channels=2,
in_stack_depth=15,
embedding_dim=768,
projection_dim=128,
)
# Variational autoencoders
from viscy_models import BetaVae25D, BetaVaeMonai
Models
UNet Family (viscy_models.unet)
| Model | Description |
|---|---|
UNeXt2 |
ConvNeXtV2-based encoder-decoder with 3D-to-2D stem and pixel shuffle head |
FullyConvolutionalMAE |
Fully convolutional masked autoencoder for self-supervised pretraining |
Unet2d |
Classic 2D UNet with configurable depth and residual connections |
Unet25d |
2.5D UNet with learned 3D-to-2D compression via skip interruption |
Unet3d |
3D U-Net (F-Net, Ounkomol et al. 2018) with recursive encoder-decoder. All spatial dims must be divisible by 2^depth. |
Contrastive Encoders (viscy_models.contrastive)
| Model | Description |
|---|---|
ContrastiveEncoder |
timm backbone (ConvNeXt/ResNet) with 3D-to-2D stem and projection MLP |
ResNet3dEncoder |
MONAI ResNetFeatures for native 3D contrastive learning |
Variational Autoencoders (viscy_models.vae)
| Model | Description |
|---|---|
BetaVae25D |
2.5D beta-VAE with timm encoder and custom decoder |
BetaVaeMonai |
Beta-VAE wrapping MONAI's VarAutoEncoder |
Heads (viscy_models.components.heads)
Pluggable task heads for multi-task learning. Attach to ContrastiveModule via auxiliary_heads.
| Class | Description |
|---|---|
BaseHead |
Abstract base — subclass to add custom heads. Defines forward, compute_loss, log_metrics |
ClassificationHead |
Classification on backbone features. Uses MLP + optional CosineClassifier. Logs top-1 and top-k accuracy |
MLP |
Configurable projection/classification MLP with BN/LN and dropout |
CosineClassifier |
L2-normalised linear head with learnable temperature — recommended for large class counts |
Label routing via SampleMeta
Auxiliary heads consume labels from anchor_meta["labels"] in the batch — a dict[str, int] populated by the dataset. The batch_key on each head selects which label to use:
# Dataset populates anchor_meta with integer labels
anchor_meta = [{"labels": {"condition": 0, "gene_ko": 42}}]
# Head config — batch_key must match a key in anchor_meta["labels"]
ClassificationHead(
head_name="gene_ko", # used for logging
batch_key="gene_ko", # key in anchor_meta["labels"]
in_dims=768,
hidden_dims=512,
num_classes=1001,
loss_weight=0.5,
)
Features
- Pure
nn.Modulearchitectures — no Lightning or Hydra dependencies - Shared components in
components/(stems, heads, decoder blocks, ConvBlocks) - Pluggable auxiliary heads via
BaseHead— extend for custom losses and metrics - State dict key compatibility with original VisCy checkpoints
- Immutable defaults for all model constructors
Dependencies
torch>=2.10timm>=1.0.15monai>=1.5.2numpy>=2.4.1
Documentation
In the works!
License
BSD-3-Clause - see LICENSE in repository root.
Metadata
Release files for viscy-models 0.1.0
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 |
|---|---|---|---|---|
| viscy_models-0.1.0.tar.gz | 76.7 kB | With provenance | Details for viscy_models-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| viscy_models-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for viscy_models-0.1.0-py3-none-any.whl |
Total release size: 161.9 kB
Release files / viscy_models-0.1.0.tar.gz
| Download URL | viscy_models-0.1.0.tar.gz |
|---|---|
| Size | 76.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c97f8a9f63cd80db7b59fadaf1afedc555aa04ab4d91636a059f148f5e31238
|
|
BLAKE2b-256 checksum How to use checksums |
5d4a5a0bdaa43e1615d2febeb26765fa73ebb3ae319bcc548a661d479116ccc9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / viscy_models-0.1.0-py3-none-any.whl
| Download URL | viscy_models-0.1.0-py3-none-any.whl |
|---|---|
| Size | 85.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
71ca20a41f87619b5bf460834e9d7dde1f8dbae4e775e40738d34e9fd3a1f742
|
|
BLAKE2b-256 checksum How to use checksums |
d071a2fb1f19a42aa00af838c22dc3ca182367d02e1b1227d4ab9b831d03611e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logSecurity for viscy-models 0.1.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for viscy_models-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logA 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.