clam
Use CLAM for weakly supervised computational pathology workflows on whole-slide images, from WSI patching through features, training, evaluation, and heatmaps.
SKILL.mdskills/repositories/repo-skills/clam/SKILL.md
GitHubCLAM
Use this repo skill when a task involves CLAM: data-efficient, weakly supervised computational pathology on whole-slide images with slide-level labels. CLAM workflows usually move from WSI segmentation and patch coordinates, to feature extraction, to CLAM/MIL training and evaluation, and finally to attention heatmap visualization.
Route First
- For raw WSIs, tissue masks, patch-coordinate
.h5files, stitched QC images, process lists, or segmentation presets, readsub-skills/wsi-preprocessing/SKILL.md. - For ResNet50, UNI, or CONCH feature extraction into
h5_files/andpt_files/, readsub-skills/feature-extraction/SKILL.md. - For dataset CSVs, train/validation/test splits,
main.py,eval.py, CLAM_SB/CLAM_MB/MIL choices, checkpoints, or metrics, readsub-skills/training-evaluation/SKILL.md. - For attention heatmaps,
create_heatmaps.py, YAML/process-list validation, ROI heatmaps, sampled patches, or checkpoint visualization, readsub-skills/heatmap-visualization/SKILL.md. - For install/import, OpenSlide, optional encoder checkpoints, GPU/runtime, or cross-workflow failures, start with
references/troubleshooting.md.
Pipeline Order
- Prepare WSIs with the fast coordinate pipeline: segment tissue, generate
patches/<slide>.h5, and optionally create masks/stitches for QC. - Extract patch features from those coordinate bags and original slides into feature
h5_files/andpt_files/. - Prepare dataset CSVs and splits, then train or evaluate CLAM/MIL models against the feature root.
- Use trained checkpoints plus heatmap YAML configuration to render attention heatmaps and sampled high-attention patches.
Key CLAM Facts
- CLAM is script-oriented rather than an installable Python package; public workflows run repository scripts such as
create_patches_fp.py,extract_features_fp.py,main.py,eval.py, andcreate_heatmaps.pyfrom a CLAM working tree or equivalent copy. - The documented environment targets Python 3.10 with OpenSlide, PyTorch, torchvision, timm, h5py, pandas, PyYAML, OpenCV, matplotlib, scikit-learn, scipy, tqdm, openslide-python, smooth-topk, and tensorboardX.
resnet50_truncis the default encoder;uni_v1needsUNI_CKPT_PATH;conch_v1needs the CONCH package plusCONCH_CKPT_PATH.- ResNet50 and UNI features use
--embed_dim 1024; CONCH features use--embed_dim 512in training, evaluation, and heatmap configs. - Heavy native runs can require WSIs, OpenSlide system libraries, GPU memory, pretrained encoder checkpoints, and trained model checkpoints. Use bundled helpers for command/config preflight before launching expensive jobs.
Public Setup Check
From a CLAM working tree, follow the upstream public setup path:
conda env create -f env.yml
conda activate clam_latest
For optional CONCH feature extraction, also install the upstream CONCH package and set CONCH_CKPT_PATH; for UNI, set UNI_CKPT_PATH to the downloaded checkpoint. After setup, run this minimal source-tree import check from the CLAM working tree before launching heavy workflows:
python -c "import torch, openslide, pandas; from models.model_clam import CLAM_SB; from dataset_modules.dataset_generic import Generic_MIL_Dataset; print('CLAM import ok')"
References
- Read
references/pipeline-overview.mdfor a concise end-to-end map of CLAM inputs, scripts, outputs, and handoffs between sub-skills. - Read
references/troubleshooting.mdfor cross-cutting install/import, OpenSlide, encoder, data-layout, GPU, and script-working-directory failures. - Read
references/repo-provenance.mdwhen deciding whether this skill is stale relative to the source repository. references/repo-routing-metadata.jsonis structured metadata used by the managed repo-skills router during import.
Bundled Scripts
- Run
scripts/clam_preflight.py --helpfor a safe, dependency-light checklist that validates expected CLAM workflow paths and reminds agents which sub-skill owns each stage. - Sub-skills include deeper workflow helpers for preprocessing command generation, preset CSV creation, feature extraction command generation, split/train/eval command generation, and heatmap YAML validation.
Safety Notes
- Do not tell a future user to rely on this generated skill's source checkout or artifact reports at runtime; use bundled references and scripts.
- Do not run WSI processing, feature extraction, model training, checkpoint evaluation, or heatmap generation without confirming required data, checkpoints, runtime hardware, and output locations.
- Prefer fast dry-run helpers and YAML/CSV validation before launching GPU-heavy or storage-heavy CLAM jobs.