Official PyTorch implementation of our pathology-aware multimodal framework for weakly supervised prostate cancer grading from whole-slide images (WSIs). The proposed framework integrates multi-scale visual representations with large language model (LLM)-generated histopathology concepts through cross-attention and hierarchical semantic fusion for accurate Grade Group prediction.
Whole-slide images contain gigapixel-resolution tissue with substantial morphological heterogeneity, making weakly supervised prostate cancer grading challenging.
This repository implements a pathology-aware multimodal framework consisting of:
- Multi-scale patch extraction
- Iterative Refinement Module (IRM)
- Frozen LLM-generated histopathology concepts
- Text-guided cross-attention
- Hierarchical multi-scale semantic fusion
- Semantic prototype learning
- Cosine similarity classification
The framework is designed for efficient weakly supervised learning without requiring pixel-level annotations.
ProstateSemanticMIL/
configs/
datasets/
preprocessing/
prompts/
models/
losses/
trainer/
utils/
train.py
test.py
infer.py
README.md
requirements.txt
LICENSE
Create a new environment
conda create -n prostate python=3.7
conda activate prostateInstall dependencies
pip install -r requirements.txtThe repository expects precomputed multi-scale feature bags.
Example structure:
data/
metadata/
tcga_prad_folds.csv
features/
TCGA-XX-0001.pt
TCGA-XX-0002.pt
...
Each feature file should contain
{
"5x": Tensor[N5,2048],
"10x": Tensor[N10,2048],
"20x": Tensor[N20,2048]
}Generate pathology descriptions using Gemini.
python -m prompts.generate_descriptionsGenerate frozen text embeddings.
python -m prompts.build_prompt_embeddingsTrain one fold
python train.py --config configs/default.yaml --fold 0Train all folds
python run_five_folds.pyResume training
python train.py \
--config configs/default.yaml \
--resume outputs/fold0/last.ptpython test.py \
--config configs/default.yaml \
--checkpoint outputs/fold0/best.ptSingle-slide prediction
python infer.py \
--config configs/default.yaml \
--checkpoint outputs/fold0/best.pt \
--features data/features/TCGA-XX-0001.ptExtracts tissue patches from
-
5×
-
10×
-
20×
magnifications.
Progressively removes less informative patches and retains only Top-M patches for efficient global reasoning.
Gemini 2.5 Pro generates pathology-aware descriptions for each Grade Group.
Descriptions are encoded using a frozen biomedical language model.
Visual tokens act as queries.
Text tokens act as keys and values.
This enables pathology-guided visual feature refinement.
Semantic-enhanced representations from all magnifications are aggregated using a transformer encoder with a learnable CLS token.
Each Grade Group is represented by a semantic prototype.
Prediction is performed using cosine similarity.
This work was conducted at the University of Connecticut.
This repository is released under the MIT License.