How sposso/deep_learning_to_improve_breast_cancer_pytorch works
Project Type and Purpose
• This is a research‐oriented deep learning pipeline in Python (PyTorch) for breast cancer detection on mammograms.
• It implements a two‐stage classifier:
• Patch‐level classifier (ResNet50 backbone)
• Whole‐image classifier (fine-tuned with additional ResNet blocks)
• It also provides preprocessing (watermark removal, patch extraction), model training, inference, and heatmap generation.
High-Level Components
A. Data Ingestion & Splitting
• Folder: /data
• Key files: split.py, sample.csv, train.csv, validation.csv, test.csv
• Output: stratified CSV partitions
B. Preprocessing & Patch Generation
• Folder: /Patches
• tools.py (segment_breast), generating_patches.py
• Output: PNG patches saved to disk, organized by class
C. Patch-Level Classifier Training
• Folder: /patch_classifier
• train_function.py, tools.py
• Backbone: ResNet50 (pretrained on ImageNet)
• Staged training (three stages, gradual layer unfreezing)
• Output: best_s_patch_model.pt, best_s10_patch_model.pt in /trained_models
D. Whole-Image Classifier Training
• Folder: /whole_image_classifier
• whole_classifier_model.py, main.py, tools.py
• Reuses patch model without top layers + two ResNet blocks + new FC
• Two‐stage training strategy
• Output: best_whole_image_classifier.pt in /trained_models
E. Heatmap Generation (Inference)
• Folder: /Heatmaps
• main.py (my_prob_heatmap), compact_heatmap_func.py, tools.py
• Sliding‐window inference using patch classifier → heatmap matrix
F. Shared Utilities
• Folder: /utils
• train_util.py, classifier.py, tools.py
• Common data loaders, training loops, metric calculators
G. Orchestration & Entry Points
• top-level main.py
• README.md describes usage steps and dependencies
Relationships & Data Flow
1. Raw Mammogram Data (DICOM) → Data Ingestion & Splitting
2. Splitted Data CSVs → Preprocessing & Patch Generation → Patch Dataset (PNG patches)
3. Patch Dataset → Patch-Level Classifier Training → Patch Models in /trained_models
4. Patch Model → Whole-Image Classifier Training → Whole Image Model in /trained_models
5. Patch Model + Full Mammogram → Heatmap Generation → Heatmap Outputs
Architectural Patterns & Principles
• Modular pipeline: separate folders for each stage (Single Responsibility).
• Reusable utilities: common code in /utils.
• Layered training strategy: freeze/unfreeze layers for controlled fine-tuning.
• Clear data flow: raw → preprocess → train → inference.
Technologies & Frameworks
• PyTorch (model definitions, training loops)
• NumPy/Pandas (CSV handling, array ops)
• PIL or OpenCV (PNG I/O, image resizing)
• DICOM readers (in Patches/tools.py for watermark removal)
• CLI scripts (Python entry points).
Final Checklist
• [ ] All seven main components labeled
• [ ] Saving/loading of models represented explicitly
• [ ] Utility module connections shown
• [ ] Annotations for important parameters (batch sizes, epochs, learning rates)