Neural network architectures primarily for AI x Imaging
Project description
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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file viscy_models-0.1.0a0.tar.gz.
File metadata
- Download URL: viscy_models-0.1.0a0.tar.gz
- Upload date:
- Size: 76.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
387dafd4a25204ece177b5315feb8a754b1a3ade0c982cc85a36bbeadf1a83e7
|
|
| MD5 |
ad904d07ad89dec2b6051f9f8a2e039b
|
|
| BLAKE2b-256 |
5a72faebd71be896282174d6624a672eab5fe0efc2451b974ab060601e21a04b
|
Provenance
The following attestation bundles were made for viscy_models-0.1.0a0.tar.gz:
Publisher:
release.yml on mehta-lab/VisCy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
viscy_models-0.1.0a0.tar.gz -
Subject digest:
387dafd4a25204ece177b5315feb8a754b1a3ade0c982cc85a36bbeadf1a83e7 - Sigstore transparency entry: 1843504968
- Sigstore integration time:
-
Permalink:
mehta-lab/VisCy@85f0b889661d3f0850fe8534527f606986a6735e -
Branch / Tag:
refs/tags/viscy-models-v0.1.0a0 - Owner: https://github.com/mehta-lab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@85f0b889661d3f0850fe8534527f606986a6735e -
Trigger Event:
release
-
Statement type:
File details
Details for the file viscy_models-0.1.0a0-py3-none-any.whl.
File metadata
- Download URL: viscy_models-0.1.0a0-py3-none-any.whl
- Upload date:
- Size: 85.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4f68b6266eeb392450e29d5a2d615ceea27e0b7c6d0e6ebd74db777f7448f1c
|
|
| MD5 |
e87028fb6aaf60f20c278690304f2481
|
|
| BLAKE2b-256 |
16d0ab3c340af06decb3ed30ea975bffd41a95ab2726aa97fdc2e1d60bb5ac5e
|
Provenance
The following attestation bundles were made for viscy_models-0.1.0a0-py3-none-any.whl:
Publisher:
release.yml on mehta-lab/VisCy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
viscy_models-0.1.0a0-py3-none-any.whl -
Subject digest:
a4f68b6266eeb392450e29d5a2d615ceea27e0b7c6d0e6ebd74db777f7448f1c - Sigstore transparency entry: 1843505022
- Sigstore integration time:
-
Permalink:
mehta-lab/VisCy@85f0b889661d3f0850fe8534527f606986a6735e -
Branch / Tag:
refs/tags/viscy-models-v0.1.0a0 - Owner: https://github.com/mehta-lab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@85f0b889661d3f0850fe8534527f606986a6735e -
Trigger Event:
release
-
Statement type: