Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔬 Cancer Classification using Convolutional Neural Networks

A deep learning project comparing three CNN architectures for multi-class cancer classification from histopathological images.

Python TensorFlow License

Overview

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.

Dataset

The dataset is too large to host in this repo. Download it from the link above and extract it locally (see Usage).

Project Structure

├── 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

Usage

Install

pip install -r requirements.txt

1. Prepare the dataset

Download 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/processed

2. Train a model

python scripts/train.py --model baseline
python scripts/train.py --model enhanced
python scripts/train.py --model transfer

Each 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>/.

Results

Exploratory Data Analysis

Sample images Class distribution
Sample images Class distribution

Baseline Model — 81.4% test accuracy

Loss / Accuracy Confusion Matrix ROC Curve
Baseline loss/accuracy Baseline confusion matrix Baseline ROC curve

Enhanced Model — 92.9% test accuracy

Adds dropout, L2 regularization, strided convolutions, and a tuned learning rate on top of the baseline architecture.

Loss / Accuracy Confusion Matrix ROC Curve
Enhanced loss/accuracy Enhanced confusion matrix Enhanced ROC curve

Transfer Learning Model (VGG16) — 96.1% test accuracy

A frozen, ImageNet-pretrained VGG16 backbone with the same custom classification head as the enhanced model.

Loss / Accuracy Confusion Matrix ROC Curve
Transfer learning loss/accuracy Transfer learning confusion matrix Transfer learning ROC curve

Key Findings

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

Author

Ivaylo Papazov

License

This project is licensed under the MIT License.

About

Deep learning approach to cancer image classification using three CNN architectures: two custom networks and one transfer learning implementation. Demonstrates multiclass classification for medical imaging diagnostics.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages