A deep learning project comparing three CNN architectures for multi-class cancer classification from histopathological images.
This project implements and compares three CNN approaches for classifying cancer types from medical images:
| Model | Description | Test Accuracy |
|---|---|---|
| Baseline | Small CNN built from scratch, no regularization | 81.4% |
| Enhanced | Deeper CNN with dropout, L2 regularization, and strided convolutions | 92.9% |
| Transfer Learning | Frozen, ImageNet-pretrained VGG16 backbone + custom classification head | 96.1% |
See Results below for full per-class metrics, confusion matrices, and ROC curves.
- Size: 25,000 histopathological images, resized to 120x120
- Classes: 5 (colon adenocarcinoma, colon benign tissue, lung adenocarcinoma, lung benign tissue, lung squamous cell carcinoma)
- Source: LC25000 Lung and Colon Histopathological Image Dataset (paper)
The dataset is too large to host in this repo. Download it from the link above and extract it locally (see Usage).
├── cancer_cnn/ # Core library
│ ├── config.py # Paths, hyperparameters, label mapping
│ ├── data.py # Dataset loading, preprocessing, splitting
│ ├── visualize.py # EDA plots (sample images, class distribution)
│ ├── evaluation.py # Loss/accuracy curves, confusion matrices, ROC curves
│ └── models.py # The three CNN architectures
├── scripts/
│ ├── prepare_dataset.py # Raw images -> resized numpy arrays
│ └── train.py # Train one model end-to-end and save figures
├── results/figures/ # Saved output from each model
│ ├── eda/
│ ├── baseline/
│ ├── enhanced/
│ └── transfer_learning/
├── reports/
│ └── model_comparison_report.pdf # Detailed write-up and analysis
└── requirements.txt
pip install -r requirements.txtDownload the LC25000 dataset from the link above, extract it, then convert it into resized numpy arrays:
python scripts/prepare_dataset.py \
--raw-data-dir /path/to/lung_colon_image_set \
--processed-dir data/processedpython scripts/train.py --model baseline
python scripts/train.py --model enhanced
python scripts/train.py --model transferEach run trains the chosen architecture, prints test-set and validation-set classification reports, and saves loss/accuracy curves, a confusion matrix, and ROC curves to results/figures/<model>/.
| Sample images | Class distribution |
|---|---|
![]() |
![]() |
| Loss / Accuracy | Confusion Matrix | ROC Curve |
|---|---|---|
![]() |
![]() |
![]() |
Adds dropout, L2 regularization, strided convolutions, and a tuned learning rate on top of the baseline architecture.
| Loss / Accuracy | Confusion Matrix | ROC Curve |
|---|---|---|
![]() |
![]() |
![]() |
A frozen, ImageNet-pretrained VGG16 backbone with the same custom classification head as the enhanced model.
| Loss / Accuracy | Confusion Matrix | ROC Curve |
|---|---|---|
![]() |
![]() |
![]() |
- Transfer learning with a pretrained VGG16 backbone outperformed both custom architectures by a wide margin (96.1% vs. 81.4% baseline test accuracy), confirming that ImageNet features transfer well to histopathological images even though the two domains look nothing alike.
- Regularization (dropout + L2) and strided convolutions closed most of the gap between the baseline and transfer-learned model on their own, improving test accuracy from 81.4% to 92.9% without any pretrained weights.
- All three models struggle most on distinguishing lung adenocarcinoma from lung squamous cell carcinoma, the two visually closest classes in the dataset — this is where the confusion matrices show the most off-diagonal mass.
For the full write-up and analysis, see the detailed report.
Ivaylo Papazov
This project is licensed under the MIT License.










