The code extracts overlapping nucleus and non-nucleus patches from cellular senescence images.
The extracted patches are later used for:
- Contrastive learning with encoder training
- Ranking patches
- Learning nucleus-cytoplasm relationships
- HFF
- HMC3
- H2O2
- Dox
- Pal
Users can change the folder names and paths according to their own dataset structure.
The patch extraction code reads:
- Control images
- Senescence images
and generates:
- Overlapping nucleus patches
- Overlapping non-nucleus patches
Update the folder paths before running the code:
control_path = "/path/to/control_images"
senescence_path = "/path/to/senescence_images"
output_path = "/path/to/output_folder"Example:
control_path = "/data/HFF/control"
senescence_path = "/data/HFF/h2o2"
output_path = "/data/HFF/output"Open and run:
Patch_extractor.ipynb
After patch extraction, the extracted nucleus and non-nucleus patches are used for contrastive learning.
This step trains an encoder with an MLP projection head using E-SupConLoss. The goal is to learn meaningful patch-level embeddings for control and senescence samples.
The training uses:
- Control nucleus patches
- Control non-nucleus patches
- Senescence nucleus patches
- Senescence non-nucleus patches
The trained encoder is later used for patch ranking and interaction learning.
This step uses the extracted patches from Step 1.
python training_Esupconloss.pyesupconloss_encoder.pth
After contrastive learning, the saved encoder from Step 2 is used to rank nucleus and non-nucleus patches.
This step trains a patch-level classification model using the frozen encoder learned from E-SupConLoss training.
The model learns to classify whether a patch belongs to:
- Control
- Senescence
The trained model is then used to rank the most important nucleus and non-nucleus patches.
This step uses:
- Extracted patches from Step 1
- Saved encoder from Step 2
python Ranking_patches.pyencoder_mlp_patch_classifier.pth
After ranking the patches, the top-k nucleus and non-nucleus patches are selected for senescence prediction.
This step uses a cross-attention network to learn relationships between nucleus and non-nucleus patches and generates a senescence probability score for each image.
The workflow includes:
- Patch extraction
- Patch ranking
- Top-k patch selection
- Cross-attention interaction learning
- Senescence probability prediction
This step uses:
- Control and senescence images
python cross_attention_senescence_scoring.pyThe model generates a probability score indicating whether the image belongs to:
- Control
- Senescence