Model Training & SlideLab Pipeline
The ColabBio training workflow combines SlideLab preprocessing and PyTorch Multiple Instance Learning (ABMIL) within a distributed Nextflow DSL2 pipeline.
graph TD
WSI["Raw Gigapixel Slide (.svs, .tiff)"] --> SL1["SlideLab: Tissue Masking (Otsu/HSV)"]
SL1 --> SL2["SlideLab: Color Normalization (Macenko / Vahadane)"]
SL2 --> SL3["SlideLab: Tile Extraction (512x512)"]
SL3 --> SL4["Feature Extraction: ResNet50 / UNI / CTransPath"]
SL4 --> H5["HDF5 Tile Embeddings (.h5)"]
H5 --> TRAIN["ABMIL Attention Training (PyTorch)"]
CLINICAL["OMOP / FHIR Tabular Covariates"] --> TRAIN
TRAIN --> METRICS["Validation (AUC, Precision, F1, Loss)"]
TRAIN --> WEIGHTS["Model Weights (.pt / .onnx)"]
METRICS --> MLFLOW["MLflow Tracking Server"]
WEIGHTS --> MLFLOW_REGISTRY["MLflow Model Registry"]
1. SlideLab Preprocessing Pipeline
Section titled “1. SlideLab Preprocessing Pipeline”SlideLab transforms heterogeneous gigapixel pathology slides into compact, normalized feature embeddings.
Steps Executed by SlideLab:
Section titled “Steps Executed by SlideLab:”- Tissue Masking: Identifies valid tissue regions while discarding background glass, marker ink, and air bubbles using adaptive HSV and Otsu thresholding.
- Color Normalization: Applies Macenko or Vahadane optical density matrix decomposition to eliminate staining variations across hospital laboratories.
- Tiling: Divides high-magnification tissue regions into non-overlapping
512x512patches at20x(0.50 µm/px). - Embedding Generation: Passes tiles through pre-trained foundation models (UNI, CONCH, CTransPath) to generate dense feature matrices saved in HDF5 (
.h5) format.
2. Distributed & Incremental Training (INCREMENTAL_BATCH_TRAIN)
Section titled “2. Distributed & Incremental Training (INCREMENTAL_BATCH_TRAIN)”The training process reads preprocessed .h5 embeddings and clinical tables through MedVFS paths, supporting checkpoint resumption (V_{n-1} -> V_n) and rolling time-window filters:
process INCREMENTAL_BATCH_TRAIN { tag "Train: ${model_name} [${period_from ?: 'Rolling ' + rolling_window_days + 'd'}]" container 'ghcr.io/colabbio/slidelab:latest'
input: path dataset_manifest val model_name val experiment_name val tracking_uri val period_from val period_to val resume_weights_path val epochs val rolling_window_days
output: path "output_model/model_weights.pt", emit: weights path "output_model/validation_report.json", emit: validation_json path "output_model/validation_report.md", emit: validation_report val model_name, emit: model_name
script: """ python3 /opt/colabbio/scripts/incremental_training_pipeline.py \ --manifest "${dataset_manifest}" \ --model-name "${model_name}" \ --experiment-name "${experiment_name}" \ --tracking-uri "${tracking_uri}" \ --period-from "${period_from}" \ --period-to "${period_to}" \ --rolling-window-days ${rolling_window_days ?: 0} \ --resume-weights "${resume_weights_path}" \ --epochs ${epochs} \ --output-dir ./output_model """}3. MLflow Tracking & PAC Bound Statistical Certification
Section titled “3. MLflow Tracking & PAC Bound Statistical Certification”During training and validation, the pipeline logs hyperparameters, epoch loss curves, data lineage SHA-256 hashes, and PAC statistical validation bounds directly to MLflow Tracking Server:
- Logged Hyperparameters:
epochs,learning_rate,resumed_from,rolling_window_days. - Logged Lineage & Tags:
cohort_hash(SHA-256),period_from,period_to,certification_status. - Logged Metrics:
loss,accuracy,auc_roc,pac_bound(pac_epsilon < 0.080),ks_p_value(p < 0.015). - Clinical Artifacts: Checkpoint weights (
model_weights.pt),validation_report.json, and the regulatory summaryvalidation_report.mdexported for HL7 FHIRDiagnosticReport.