A study of convolutional neural network architectures for binary classification of histopathology image patches — distinguishing 96×96 px patches that contain metastatic tumor tissue from those that do not.
The work is based on the Histopathologic Cancer Detection competition on Kaggle, whose data comes from the PatchCamelyon (PCam) benchmark, derived in turn from the Camelyon16 challenge.
The task is a binary image classification problem: given a 96×96 px patch cropped from a larger digital pathology scan, predict whether the center 32×32 px region contains metastatic tumor tissue. Automating this kind of screening can help pathologists triage slides faster and more consistently.
The full workflow — EDA, preprocessing, model building, training, and evaluation — lives in a single, self-documenting notebook.
| Property | Value |
|---|---|
| Source | PatchCamelyon (PCam), via the Kaggle Histopathologic Cancer Detection dataset |
| Labeled examples | 220,025 |
| Image format | 96×96 px, 3-channel RGB |
| Positive class share | ~40% |
| Evaluation metric | Area under the ROC curve (AUC) |
The dataset is not included in this repository. Download it from the source (see Getting Started).
- EDA — inspect class balance, view sample patches, and check per-channel RGB statistics and pixel-intensity distributions.
- Preprocessing — train on a balanced subset (equal positive/negative
examples) to fit within memory limits. Normalization (
Rescaling) and center-cropping are baked into the model as its first layers. - Modeling — five models of increasing sophistication are trained and compared, each isolating the effect of one design choice, all using the Adam optimizer, binary cross-entropy loss, and early stopping.
- Evaluation — training/validation curves plus validation AUC on a held-out 20% split.
| Model | Technique it introduces | Parameters |
|---|---|---|
| Model #1 | Baseline — 3 conv blocks + 1 dense head | 159,041 |
| Model #2 | 5 conv blocks + batch normalization | 1,702,145 |
| Model #3 | Deeper dense head (more capacity) | 2,610,945 |
| Model #4 | Model #2 + data augmentation | 1,702,145 |
| Model #5 | Transfer learning — MobileNetV2 + fine-tuning | ~2.3M |
All models are compared on the same held-out 20% validation split using AUC. Best result: the fine-tuned MobileNetV2 (Model #5) at 0.947 validation AUC.
| Model | Approach | Validation AUC |
|---|---|---|
| Model #1 | 3-block CNN (baseline) | 0.856 |
| Model #2 | 5-block CNN + batch norm | 0.925 |
| Model #3 | 5-block CNN + deep head | 0.930* |
| Model #4 | Model #2 + augmentation | 0.914 |
| Model #5 | MobileNetV2, frozen | 0.914 |
| Model #5 | MobileNetV2, fine-tuned | 0.947 🏆 |
* Model #3 reaches a high peak, but its validation loss diverges, so the score is not trustworthy — more capacity without more regularization simply overfits.
Key findings
- Capacity has diminishing returns — the mid-sized Model #2 beat the heavier Model #3.
- Augmentation improved generalization more than peak score: Model #4's validation loss stopped diverging, giving the cleanest from-scratch curves.
- Transfer learning was the highest-leverage move — a pre-trained MobileNetV2, then fine-tuned, reached the best AUC with far less training than the custom CNNs.
- More data was not a guaranteed win — doubling the balanced training set did not improve results here.
CNNs-for-Cancer-Image-Patch-Classification/
├── cnn-medical-image-classification.ipynb # Full study: EDA → modeling → results
└── README.md
- Clone the repository
git clone https://github.com/abrahamperz/CNNs-for-Cancer-Image-Patch-Classification.git cd CNNs-for-Cancer-Image-Patch-Classification - Get the data. Either run the notebook directly on Kaggle (the dataset is
attached automatically), or download it locally via the
Kaggle CLI:
The notebook auto-locates the data folder that contains
kaggle competitions download -c histopathologic-cancer-detection
train_labels.csv; adjust the paths if you run it elsewhere. - Install dependencies
pip install tensorflow keras numpy pandas matplotlib opencv-python tifffile
- Run the notebook
jupyter notebook cnn-medical-image-classification.ipynb
- Use streaming input pipelines (
tf.data) to train on the full dataset without memory limits. - Try stronger backbones (EfficientNet, ResNet) and systematically tune how many layers to unfreeze during fine-tuning.
- Add learning-rate schedules and other non-default hyperparameters to tame the validation-metric swings seen in the from-scratch models.
- Explore test-time augmentation and model ensembling for a further robustness gain.