STHELAR-Adapt is research software for adapting CellViT to nuclei instance segmentation and spatial-transcriptomics-informed cell typing in STHELAR 40× H&E images. It combines a frozen pretrained CellViT backbone with compact, domain-specific parameter-efficient states.
Hugging Face collection · Thesis result provenance · Adapter inventory
Selected STHELAR-Adapt architecture: LoRA and AdaptFormer specialize the encoder while only the final nucleus output heads are trained in the decoder.
STHELAR links H&E morphology to cell identities derived from spatial transcriptomics. This repository groups the foreground labels into Immune, Stromal, Epithelial, Melanocyte, and Other, and adapts two CellViT backbones:
- CellViT-SAM-H-x40
- CellViT-256-x40
The final MSc evaluation asks whether the selected PEFT configuration preserves CellViT performance when an entire slide is held out. Kidney–Liver–Tonsil (KLT) uses three stochastic seeds per reciprocal direction; the nine tissue-specific tasks use seed 42.
The selected configuration uses Q/V LoRA with rank 8, alpha 8, and zero dropout; AdaptFormer bottlenecks with reduction 16 and GELU; and trainable final NP (nuclei probability), HV (horizontal/vertical), and NT (nuclei type) 1×1 heads. The pretrained encoder weights and decoder body remain frozen. For CellViT-256, the auxiliary tissue classifier also remains frozen.
The deployment model is one architecture-matched pretrained base plus one compact domain-specific state. The public release loader validates the base hash, adapter payload hash, tensor inventory, and exact-verification record before returning an eval-mode model:
from utils.sthelar_release_loader import load_verified_adapter
model, evidence = load_verified_adapter(
base_checkpoint="/path/to/CellViT-SAM-H-x40.pth",
package_dir="/path/to/downloaded-adapter-package",
device="cpu",
)A domain state contains the LoRA and AdaptFormer parameters, final output-head state, and required mutable normalization buffers. Switching domains means loading a different state onto the same compatible base. SAM-H and CellViT-256 states are architecture-specific and cannot be interchanged.
One immutable architecture-matched base is shared across compact tissue or multi-tissue specializations.
The official CellViT base checkpoints are required separately and are not redistributed by STHELAR-Adapt.
The final evaluation uses reciprocal complete-slide holdout. KLT values are equal-weight Fold A/B means after averaging each fold over seeds 42, 43, and 44. Nine-tissue values use seed 42 and weight the two reciprocal directions and the nine tissues equally.
| Evaluation | Backbone | Method | bPQ | mPQ | F1 detection | F1 type |
|---|---|---|---|---|---|---|
| KLT complete-slide | SAM-H | PEFT | 0.564 | 0.228 | 0.853 | 0.492 |
| KLT complete-slide | SAM-H | FullFT | 0.564 | 0.214 | 0.848 | 0.508 |
| KLT complete-slide | CellViT-256 | PEFT | 0.517 | 0.187 | 0.847 | 0.471 |
| KLT complete-slide | CellViT-256 | FullFT | 0.552 | 0.200 | 0.849 | 0.482 |
| Nine-tissue complete-slide | SAM-H | PEFT | 0.442 | 0.175 | 0.808 | 0.381 |
| Nine-tissue complete-slide | SAM-H | FullFT | 0.445 | 0.187 | 0.806 | 0.418 |
| Nine-tissue complete-slide | CellViT-256 | PEFT | 0.420 | 0.151 | 0.791 | 0.348 |
| Nine-tissue complete-slide | CellViT-256 | FullFT | 0.433 | 0.168 | 0.790 | 0.388 |
Nucleus detection is preserved particularly closely. ST-informed typing is more difficult: mPQ and F1 type show larger and more heterogeneous deficits. SAM-H preserves class-agnostic segmentation especially closely, whereas CellViT-256 shows a clearer PEFT bPQ deficit. The backbone comparison is a practical comparison between different architectures and pretraining, not a controlled scaling law.
Representative overlays across nine tissues, shown as Ground truth, Linear Probing, and the selected PEFT adapter; colors denote the five grouped cell identities.
The earlier historical within-slide development benchmark was used to select the PEFT design. It is not the final cross-slide thesis evaluation; its tables and actual seed coverage remain available in the scientific audit and source-of-truth map.
The matched systems measurements used training batch size 4 and report peak allocated GPU memory. State size is the incremental serialized state required for one domain.
| Backbone | Method | Trainable | Peak VRAM | Serialized state |
|---|---|---|---|---|
| SAM-H | PEFT | 1.1176% | 9.362 GiB | 30.369 MiB |
| SAM-H | FullFT | 100% | 15.508 GiB | 2.607 GiB |
| CellViT-256 | PEFT | 0.7942% | 2.040 GiB | 1.548 MiB |
| CellViT-256 | FullFT | 100% | 2.667 GiB | 0.174 GiB |
For nine architecture-compatible domains:
| Backbone | Nine FullFT states | Shared-base PEFT |
|---|---|---|
| SAM-H | 23.463 GiB | 2.874 GiB |
| CellViT-256 | 1.569 GiB | 0.188 GiB |
Parameter efficiency does not imply universal runtime acceleration. Timings depend on the backbone, hardware, data pipeline, validation, checkpointing, and postprocessing. See the systems audit and raw systems table.
The canonical inventory
distinguishes unique local payloads, exact staging mirrors, publication
candidates, and publication status. PENDING_PUBLICATION means verified local
release material; it does not mean that a remote file is downloadable.
At this snapshot:
- SAM-H has local verified evaluation adapters and all-slides deployment states for KLT plus nine tissues.
- CellViT-256 has local verified evaluation adapters and all-slides deployment states for KLT plus nine tissues.
- Both backbones therefore have complete local all-slides deployment coverage (10/10 domains each).
- Remote availability must be checked independently in the Hugging Face collection before citing an adapter as publicly downloadable.
Fold-specific adapters reproduce reciprocal held-out-slide runs. All-slides adapters are deployment states trained using every designated slide with the established within-slide training/validation construction; they have no held-out-slide performance claim and do not alter the thesis evaluation.
git clone https://github.com/albtad01/STHELAR-Adapt.git
cd STHELAR-Adapt
conda env create -f environment.yml
conda activate sthelar-adapt
python -m pip install -r requirements.txtObtain the official architecture-matched checkpoint from the CellViT project. Expected base hashes are:
b324c10fddb0f80f5ab03a0459453a4c4848866934daf63435b46749a6b278cf CellViT-SAM-H-x40.pth
ee3986922fc500353db3d7692c566e19e1c694c8f10e47cf49dfd90160fc3b2b CellViT-256-x40.pth
Verify a base before loading a domain state:
echo "BASE_SHA256 /path/to/CellViT-base.pth" | sha256sum --checkThe loader works with verified packages for either supported backbone. Lower-level
SAM-H adapter composition remains available through load_cellvit_base and
load_sthelar_adapter in utils.cellvit_adapter_hub for advanced workflows.
Package-level verification is also available through
tools/verify_public_release_package.py.
Set portable local paths; curated configs expand ${DATA_ROOT} at runtime:
export DATA_ROOT=/path/to/cellvit_ready
export CELLVIT_SAM_H_X40_CHECKPOINT=/path/to/CellViT-SAM-H-x40.pthPrepare one reciprocal KLT direction and train the selected SAM-H configuration:
python preprocessing/sthelar/convert_hf_to_cellvit.py \
--config configs/slide_exp/preprocessing/preprocessing_sthelar40x_klt_5class_slideind_foldA_margin128.yaml
python cell_segmentation/run_cellvit.py --config \
configs/slide_exp/training/training_sthelar40x_klt_5class_slideind_foldA_lora_adaptformer_heads_seed42.yamlFold B reverses the training and held-out slides. Tissue-specific and
CellViT-256 configurations are under configs/slide_exp/,
and exact split assignments are under
manifests/slide_independent/. To evaluate an
existing run:
python utils/rerun_cellvit_inference.py \
--run_dir /path/to/run \
--checkpoint_name checkpoint_10.pth \
--gpu 0 --magnification 40These commands require the STHELAR-derived local data, the official upstream checkpoint, and appropriate compute. They do not download or embed either asset.
| Resource | Canonical location |
|---|---|
| Final raw/primary result registry | reports/workshop_master_results.csv |
| Thesis audit tables | thesis_audit/ |
| Result definitions and provenance | docs/thesis/RESULTS_SOURCE_MAP.md |
| Complete-slide configs | configs/slide_exp/ and configs/release/ |
| Split manifests | manifests/slide_independent/ |
| Adapter hashes and status | release/huggingface/FINAL_ADAPTER_INVENTORY.csv |
| Hugging Face publication plan | release/huggingface/HF_PUBLICATION_PLAN.md |
| Export and verification tools | tools/ |
- STHELAR provides few complete slides per tissue, and reciprocal direction can materially affect results.
- Tissue-specific results use one seed per direction; KLT uses three. Neither setting supports a patient-, site-, scanner-, or cohort-level generalization claim.
- ST-derived cell identities contain assignment uncertainty and are not interchangeable with morphology-only labels.
- Typing-sensitive mPQ and F1 type remain more difficult than nucleus detection.
- Performance may change with tissue, stain, scanner, magnification, preprocessing, label mapping, or base-checkpoint version.
- This software and all adapter states are research artifacts, not medical devices or clinically validated models.
No public bibliographic record is currently asserted for an STHELAR-Adapt or COMPAYL paper. Please cite this repository and the upstream resources used:
- Hörst et al., “CellViT: Vision Transformers for Precise Cell Segmentation and Classification,” Medical Image Analysis 94 (2024), 103143. doi:10.1016/j.media.2024.103143
- Giraud-Sauveur et al., “STHELAR, a Multi-Tissue Dataset Linking Spatial Transcriptomics and Histology for Cell Type Annotation,” Scientific Data (2026). doi:10.1038/s41597-026-06937-6
- Kirillov et al., “Segment Anything,” ICCV 2023.
- Chen et al., “Scaling Vision Transformers to Gigapixel Images via Hierarchical Self-Supervised Learning,” CVPR 2022.
The repository contains components subject to different upstream terms.
LICENSE reproduces the applicable CellViT component terms, and
NOTICE records CellViT, Segment Anything, HIPT, STHELAR, and PanNuke
provenance and modifications. STHELAR data and imagery are separately licensed
under CC BY 4.0. No CellViT/SAM base checkpoint or STHELAR source data is
included; review the upstream terms before redistribution or deployment.


