Skip to content

assadiab/Breast_Cancer_Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

37 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ—οΈ Breast Cancer Detection

AI-assisted breast cancer detection on screening mammography β€” RSNA Kaggle Competition.

Collaborative project β€” M2 Biologie-Informatique, UniversitΓ© Paris CitΓ©
Encadrants : Tatiana Galochkina Β· FrΓ©dΓ©ric Guyon Β· Jean-Christophe Gelly


Author

Assa Diabira β€” M2 Biologie-Informatique, UniversitΓ© Paris CitΓ©
Multi-Head Expert model: 4 medical backbones + cross-attention fusion


Project Structure

Breast_Cancer_Detection/
β”œβ”€β”€ main.py                        ← entry point : train / eval / infer
β”œβ”€β”€ inference.py                   ← load model + predict on DICOM files
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
β”œβ”€β”€ .gitignore
β”‚
β”œβ”€β”€ core/                          ← shared utilities
β”‚   β”œβ”€β”€ configuration.py
β”‚   β”œβ”€β”€ dataset_manager.py
β”‚   └── loader.py
β”‚
β”œβ”€β”€ preprocess/                    ← DICOM preprocessing pipeline
β”‚   β”œβ”€β”€ pipeline.py                ← PreprocessPipeline (5 modes)
β”‚   β”œβ”€β”€ cropping.py                ← ROI crop + pectoral muscle removal
β”‚   β”œβ”€β”€ windowing.py               ← adaptive windowing by BI-RADS density
β”‚   └── resampler.py               ← isotropic resampling
β”‚
β”œβ”€β”€ models/                        ← Multi-Head Expert model
β”‚   β”œβ”€β”€ multi_head_expert.py       ← 4 expert backbones + fusion
β”‚   β”œβ”€β”€ baseline_cnn.py            ← baseline for comparison
β”‚   β”œβ”€β”€ losses.py                  ← FocalAUCLoss (70% Focal + 30% AUC)
β”‚   β”œβ”€β”€ trainer.py                 ← Trainer class (OOP)
β”‚   └── dataset.py                 ← MammographyDataset (PyTorch)
β”‚
β”œβ”€β”€ notebooks/
β”‚   β”œβ”€β”€ eda.ipynb                  ← Exploratory Data Analysis
β”‚   β”œβ”€β”€ preprocessing_benchmark.ipynb
β”‚   β”œβ”€β”€ training_baseline.ipynb
β”‚   └── training_multihead.ipynb
β”‚
└── results/
    β”œβ”€β”€ metrics/                   ← JSON metrics from Kaggle runs
    └── figures/                   ← ROC curves, confusion matrices

Model Architecture β€” Multi-Head Expert (DIABIRA v3)

DICOM image
    ↓ PreprocessPipeline (crop β†’ adaptive windowing β†’ resize)
float32 [1, H, W]  (grayscale, values in [0, 1])
    ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    4 EXPERT BACKBONES                        β”‚
β”‚  1. EfficientNetV2-S  mammoscreen  (RSNA breast, AUC 0.945) β”‚
β”‚  2. DenseNet121       TorchXRayVision RSNA X-ray            β”‚
β”‚  3. ResNet50          RadImageNet (1.35M medical images)     β”‚
β”‚  4. ConvNeXt-Small    ImageNet-21k (RSNA Kaggle winner)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    ↓ each β†’ 512-dim embedding
Expert-Aware Fusion:
  cross-attention (4 heads) β†’ per-expert MLP β†’ dynamic gating (softmax)
    ↓
MLP classifier: 512 β†’ 256 β†’ 128 β†’ 1  [GELU, Dropout]
    ↓
BCEWithLogitsLoss  (no Sigmoid on model output)

106M parameters total. Freeze backbones for phase 1 β†’ 6.3M trainable.


Installation

git clone https://github.com/assadiab/Breast_Cancer_Detection.git
cd Breast_Cancer_Detection
pip install -r requirements.txt

Key dependencies: torch, torchvision, timm, torchxrayvision, monai, huggingface_hub, safetensors, albumentations, pydicom, opencv-python, scikit-learn.

Optional β€” RadImageNet weights for Expert 3 (ResNet50): Download from Google Drive and place in checkpoints/radImageNet/.
Expert 1 (mammoscreen) and Expert 2 (TorchXRayVision) download automatically on first run.


Training

Quick start

# Multi-Head Expert model
python main.py train \
  --csv train.csv \
  --images-dir /path/to/dicom/images \
  --preprocess-mode full \
  --epochs 20 --batch-size 8 --lr 1e-4 \
  --checkpoint-dir checkpoints/

# Baseline CNN
python main.py train \
  --csv train.csv \
  --images-dir /path/to/dicom/images \
  --model baseline --epochs 30 \
  --checkpoint-dir checkpoints/baseline/

Three-phase training (recommended)

from models.multi_head_expert import MultiHeadMammoModel
from models.trainer import Trainer

model = MultiHeadMammoModel(embed_dim=512)

# Phase 1 β€” frozen backbones (6.3M trainable params)
model.freeze_backbones()
Trainer(model, train_loader, val_loader, device, lr=1e-3, n_epochs=10).train()

# Phase 2 β€” unfreeze last 2 blocks
model.unfreeze_backbones(last_n_blocks=2)
Trainer(model, train_loader, val_loader, device, lr=1e-4, n_epochs=10).train()

# Phase 3 β€” full fine-tuning (106M params)
model.unfreeze_all()
Trainer(model, train_loader, val_loader, device, lr=5e-5, n_epochs=10).train()

Preprocessing modes

from preprocess.pipeline import PreprocessPipeline

pipeline = PreprocessPipeline(config, mode="full", target_hw=(1024, 512))
# modes: "raw" | "crop_only" | "window_only" | "full" | "full_iso"

img = pipeline.process_one(patient_id, image_id, laterality, view, density, dicom_path)
# returns float32 numpy (H, W), values in [0, 1]

Evaluation & inference

# Evaluate on validation set
python main.py eval \
  --csv val.csv \
  --images-dir /path/to/dicom \
  --checkpoint checkpoints/best_model.pth

# Predict on new DICOM files
python main.py infer \
  --images-dir /path/to/new/dicoms \
  --checkpoint checkpoints/best_model.pth \
  --output predictions.csv

Preprocessing Pipeline

Three stages applied before model input:

1. ROI Cropping β€” Otsu thresholding β†’ morphological ops β†’ pectoral muscle removal (Hough lines, MLO views) β†’ standardized left orientation β†’ bounding box with mm margins.

2. Adaptive Windowing β€” Density-aware: percentile clipping β†’ gamma correction β†’ CLAHE (relative tile size) β†’ weighted fusion. Tuned per BI-RADS density (A/B/C/D).

3. Resize to target resolution (default 1024Γ—512).


Results

Model ROC-AUC PR-AUC F1 Recall
EfficientNet-B0 0.63 0.14 0.13 0.18
ConvNeXt-Base 0.62 0.15 0.20 0.26
ResNet-50 + Meta 0.59 0.13 0.19 0.21
Multi-Head v1 0.66 0.15 0.22 0.23
Multi-Head v3 in progress β€” Kaggle GPU β€” β€” β€”

Metrics from Kaggle GPU runs β†’ results/metrics/


Dataset

RSNA Screening Mammography Breast Cancer Detection β€” 54,706 DICOM images, 11,913 patients, 2.12% cancer rate.

Patient-wise stratified split (no data leakage): 70% train / 15% val / 15% test.
Class imbalance: pos_weight=13.7 + FocalLoss (Ξ³=2.5, Ξ±=0.75) + patient-aware oversampling.

Data is not versioned here (DICOM files too large for GitHub).


References

About

πŸŽ—οΈDeep Learning models for breast cancer detection on mammograms

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors