MedMNIST PyTorch Classifier & Grad-CAM
Residual CNN & Pure-PyTorch Grad-CAM Explainability for 2D Medical Imaging
Built a modular PyTorch 2D medical image classification pipeline (MedResNet residual CNN) with inverse-frequency class-weighted CrossEntropyLoss, AdamW, cosine annealing, and a pure-PyTorch Grad-CAM saliency implementation using forward and backward hooks, achieving 0.9673 held-out test ROC-AUC on PneumoniaMNIST.
Held-Out Test ROC-AUC
0.9673
Evaluated once on 624 untouched PneumoniaMNIST paediatric chest X-rays
Validation ROC-AUC
0.9968
97.14% validation accuracy and 0.9637 Macro F1 on best checkpoint
Explainability
Pure-PyTorch Grad-CAM
Forward and full backward hooks on stage3.conv2 with bilinear upsampling
Test Coverage
3/3 Pytest Passing
Automated checks for forward shapes, [0, 1] saliency bounds, and weight updates
System Architecture & Quantitative Results
src/data.py, src/model.py, src/gradcam.py, src/train.py, src/evaluate.py) supporting greyscale and RGB 2D MedMNIST clinical imaging benchmarks (PneumoniaMNIST, BreastMNIST, PathMNIST, OrganAMNIST).- Residual CNN Architecture (
src/model.py): 3-stage MedResNet with projection skip connections, BatchNorm, global average pooling, and dropout, exposingstage3.conv2as the Grad-CAM target layer. - Pure-PyTorch Grad-CAM (
src/gradcam.py): Captures spatial activations and class-score gradients via forward and full backward hooks, global-average-pools gradients into channel weights, applies ReLU, and upsamples to input resolution. - Reproducible Training & Evaluation (
src/train.py,src/evaluate.py): Deterministic seeding, AdamW with CosineAnnealingLR, JSON metrics logging, and automated ROC, confusion matrix, and saliency grid generation.
ROC Curve, Confusion Matrix & Grad-CAM Saliency Overlays
[Fig. 1]Grad-CAM Saliency Overlays on Held-Out Test Chest X-Rays
Class-discriminative Grad-CAM heatmaps generated from the final convolutional layer of MedResNet, highlighting lung opacity regions driving each prediction.

[Fig. 2]Held-Out Test ROC Curve & Confusion Matrix
0.9673 held-out test ROC-AUC, 88.78% test accuracy, and 0.8729 Macro F1 across 624 paediatric chest X-rays using class-weighted CrossEntropyLoss.

