PyTorch implementation and pretrained models for ChanSFormer, a channel-agnostic Vision Transformer for multi-channel images, accepted at NeurIPS 2026. See the paper for details.
ChanSFormer uses a shared patch embedding, individual channel CLS tokens, and disentangled channel-spatial attention. It naturally supports different numbers and combinations of input channels while preserving cross-channel interactions.
- Channel agnostic: the same backbone handles arbitrary channel counts without channel-specific embeddings.
- Efficient attention: channel attention and spatial attention replace expensive global attention over all channel-patch tokens.
- Supervised and self-supervised learning: supports standard classification and DINOv2 pretraining with channel-level representations.
| Directory | Description |
|---|---|
dichavit/ |
Supervised training and evaluation on CHAMMI and So2Sat |
channelvit/ |
Supervised training and evaluation on JUMP-CP |
dinov2/ |
DINOv2 pretraining and cross-dataset evaluation |
triton_channel_attention/ |
Optional fused Triton channel-attention kernel |
weights/ |
Local directory for checkpoints downloaded from GitHub Releases (ignored by Git) |
Each part has its own environment. The commands below were tested on Linux with CUDA 12 GPUs.
dichavit/ (Python 3.11, PyTorch 2.4.1)
micromamba create -n dichavit python=3.11 -y
micromamba activate dichavit
# or:
# conda create -n dichavit python=3.11 -y
# conda activate dichavit
pip install torch==2.4.1 torchvision==0.19.1
pip install wandb==0.19.11
pip install \
debugpy==1.5.1 dill==0.3.6 einops==0.4.1 GPUtil==1.4.0 h5py==3.8.0 \
humanize==4.6.0 hydra-core==1.3.2 numpy==1.26.4 omegaconf==2.3.0 \
pandas==1.5.1 Pillow==9.5.0 psutil==5.9.0 python-dotenv==1.0.0 \
Requests==2.30.0 scikit_image==0.21.0 scikit_learn==1.7.2 tqdm==4.65.0 \
torchmetrics==1.4.2 albumentations==1.4.16 pyarrow==17.0.0 \
umap-learn==0.5.9.post2 matplotlib==3.10.7 seaborn==0.13.2 gpustat \
timm==0.9.2 termcolor yacs==0.1.8
pip install faiss-gpu-cu12
pip install --force-reinstall numpy==1.26.4
channelvit/ can use the provided Dockerfile. Without Docker (Python 3.11, PyTorch 2.8.0; this setup has not been extensively tested):
micromamba create -n channelvit python=3.11 -y
micromamba activate channelvit
pip install torch==2.8.0 torchvision==0.23.0 --index-url https://download.pytorch.org/whl/cu128
pip install pytorch-lightning==2.6.1 lightning==2.6.1 timm==0.9.2 hydra-core==1.3.2 omegaconf==2.3.0 \
pandas==2.0.3 pyarrow==13.0.0 albumentations==1.3.1 opencv-python-headless==4.8.0.76 einops h5py \
scikit-image==0.21.0 boto3==1.24.59 s3fs==2022.11.0 tqdm wandb
pip install --force-reinstall numpy==1.26.4
cd channelvit && pip install -e . --no-deps
dinov2/ pretraining and evaluation were run with the same provided Dockerfile (CUDA 12.8, PyTorch 2.9.0, xFormers 0.0.33.post1). The same container also runs channelvit/. xFormers is required for training.
Alternatively, the dichavit environment also runs DINOv2 after installing:
micromamba activate dichavit
pip install xformers==0.0.28 fvcore==0.1.5.post20221221 iopath==0.1.10
| Dataset | Download | Expected directory |
|---|---|---|
| CHAMMI | Zenodo | CHAMMI/ containing Allen/, HPA/, CP/, and morphem70k_v2.csv |
| JUMP-CP | aws s3 cp --recursive --no-sign-request s3://insitro-research-2023-context-vit/jumpcp/ jumpcp/ |
jumpcp/ containing plate BR00116991 and its metadata |
| So2Sat LCZ42 | So2Sat-LCZ42 | So2Sat/ containing training.h5, validation.h5, and testing.h5 |
For faster JUMP-CP data loading, especially from network file systems such as NFS, we recommend converting the .npy images to compressed .npz files:
python channelvit/tools/npy2npz.py jumpcp/BR00116991 jumpcp/BR00116991_npz
Then enable use_npz in the training or evaluation command. On systems with sufficient memory, preloading the dataset onto a memory-backed filesystem such as /dev/shm can further reduce I/O overhead.
Pretrained checkpoints are hosted on GitHub Releases. Download the model files into weights/ before running the evaluation commands below.
The scripts below reproduce the supervised ChanSFormer experiments:
# CHAMMI, 1 GPU
CHAMMI_ROOT=/path/to/CHAMMI bash dichavit/scripts/train_chammi.sh
# So2Sat, 4 GPUs by default
SO2SAT_ROOT=/path/to/So2Sat bash dichavit/scripts/train_so2sat.sh
# JUMP-CP, 4 GPUs by default
JUMPCP_ROOT=/path/to/jumpcp bash channelvit/scripts/train_jumpcp.sh
Evaluate the released checkpoints:
CHAMMI_ROOT=/path/to/CHAMMI \
bash dichavit/scripts/eval_chammi.sh weights/chansformer_supervised_chammi.pth
SO2SAT_ROOT=/path/to/So2Sat \
bash dichavit/scripts/eval_so2sat.sh weights/chansformer_supervised_so2sat.pth
JUMPCP_ROOT=/path/to/jumpcp \
bash channelvit/scripts/eval_jumpcp.sh weights/chansformer_supervised_jumpcp.pth
We conducted an additional supervised experiment after the paper using per-image, per-channel self-normalization (the normalization used in our DINOv2 pretraining experiments) on CHAMMI. The values below are CHAMMI Avg scores over Allen and HPA; self-normalization gives ChanSFormer the best result.
| Method | Global Norm | Self Norm | Best |
|---|---|---|---|
| HyperViT | 54.54 | 64.71 | 64.71 |
| DepthwiseViT | 60.94 | 69.03 | 69.03 |
| TemplateMixingViT | 57.02 | 63.17 | 63.17 |
| ChAda-ViT | 63.88 | 62.11 | 63.88 |
| ChannelViT | 64.90 | 64.32 | 64.90 |
| DiChaViT | 69.68 | 69.29 | 69.68 |
| ChanSFormer | 68.83 | 71.30 | 71.30 |
The corresponding checkpoint is available in GitHub Releases as chansformer_supervised_chammi_selfnorm.pth; evaluate it with ++dataset.normalize_mode=selfnorm.
Pretrain ChanSFormer with DINOv2 on CHAMMI or the five fluorescence channels of JUMP-CP:
cd dinov2
bash scripts/cell_csf/train_chansformer.sh \
chammi /path/to/CHAMMI /path/to/output_chammi
bash scripts/cell_csf/train_chansformer.sh \
jumpcp_fluor5 /path/to/jumpcp /path/to/output_jumpcp
ChanSFormer includes a fused Triton implementation of channel attention:
pip install -e triton_channel_attention
python triton_channel_attention/tests/test_correctness.py
See triton_channel_attention/README.md for usage and benchmarks. The default backend is the standard PyTorch implementation.
For questions, please open an issue or contact Jingwei Zhang at jingwezhang@cs.stonybrook.edu.
This repository builds on DiChaViT, ChannelViT, DINOv2, and Cell-DINO. We thank the authors for releasing their code.
This work extends our earlier workshop paper and its implementation. The workshop implementation is released under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.
If you find ChanSFormer useful in your research, please cite:
@inproceedings{zhang2026chansformer,
title = {ChanSFormer: A Channel Agnostic Vision Transformer for Multi-Channel Cell Painting Images},
author = {Zhang, Jingwei and Sivanandan, Srinivasan and Samaras, Dimitris},
booktitle = {Advances in Neural Information Processing Systems},
year = {2026}
}
