Skip to content

About

CNN architectures for classifying histopathology image patches as cancerous or normal: from a baseline CNN to a fine-tuned MobileNetV2 (0.947 validation AUC)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

🔬 CNNs for Cancer Image Patch Classification

Python TensorFlow Jupyter Best AUC

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.


Table of Contents


Overview

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.

Dataset

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).

Approach

  1. EDA — inspect class balance, view sample patches, and check per-channel RGB statistics and pixel-intensity distributions.
  2. 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.
  3. 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.
  4. 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

Results

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.

Repository Structure

CNNs-for-Cancer-Image-Patch-Classification/
├── cnn-medical-image-classification.ipynb   # Full study: EDA → modeling → results
└── README.md

Getting Started

  1. Clone the repository
    git clone https://github.com/abrahamperz/CNNs-for-Cancer-Image-Patch-Classification.git
    cd CNNs-for-Cancer-Image-Patch-Classification
  2. Get the data. Either run the notebook directly on Kaggle (the dataset is attached automatically), or download it locally via the Kaggle CLI:
    kaggle competitions download -c histopathologic-cancer-detection
    The notebook auto-locates the data folder that contains train_labels.csv; adjust the paths if you run it elsewhere.
  3. Install dependencies
    pip install tensorflow keras numpy pandas matplotlib opencv-python tifffile
  4. Run the notebook
    jupyter notebook cnn-medical-image-classification.ipynb

Future Work

  • 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.

About

CNN architectures for classifying histopathology image patches as cancerous or normal: from a baseline CNN to a fine-tuned MobileNetV2 (0.947 validation AUC)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages