#DermaMNIST Classification using Simple CNN Classical 2D CNN baseline trained on binary DermaMNIST (Actinic Keratoses vs Basal Cell Carcinoma), serving as the classical counterpart in a QCNN vs CNN comparative study on skin lesion classification.
A classical Convolutional Neural Network (CNN) implementation for binary skin lesion classification on the DermaMNIST dataset, distinguishing Actinic Keratoses and Intraepithelial Carcinoma (AKIEC) from Basal Cell Carcinoma (BCC).
This repository serves as the classical baseline in a comparative study against a Quantum Convolutional Neural Network (QCNN).
📄 Companion repository (QCNN): [Link to your QCNN repo]
| Property | Details |
|---|---|
| Task | Binary classification — AKIEC (Class 0) vs BCC (Class 1) |
| Dataset | DermaMNIST (MedMNIST v2) |
| Image size | 28×28 pixels, grayscale |
| Framework | TensorFlow 2 / Keras |
| Total parameters | 420,610 |
| Test accuracy | ~55% |
| Training | 60 epochs, batch size 64 |
| Platform | Google Colab |
DermaMNIST is part of the MedMNIST v2 benchmark collection, derived from the HAM10000 dermoscopy dataset (Tschandl et al., 2018). Images are 28×28 pixels in RGB format, standardised across 7 lesion categories.
This project uses a binary subset of two classes:
| Label | Class | Description |
|---|---|---|
| 0 | AKIEC | Actinic Keratoses & Intraepithelial Carcinoma — precancerous lesion |
| 1 | BCC | Basal Cell Carcinoma — most common skin cancer |
The dataset is accessed via the medmnist Python package, which handles
downloading, caching, and loading automatically.
Input (28×28×1) │ ▼ Conv2D (32 filters, 3×3, same padding) → ReLU → MaxPooling2D (2×2) │ ▼ Conv2D (64 filters, 3×3, same padding) → ReLU → MaxPooling2D (2×2) │ ▼ Flatten (3136 units) │ ▼ Dense (128 units, ReLU) → Dropout (0.3) │ ▼ Dense (2 units, Softmax) → [P(AKIEC), P(BCC)]
| Layer | Output Shape | Parameters |
|---|---|---|
| Conv2D (32 filters) | (28, 28, 32) | 320 |
| MaxPooling2D | (14, 14, 32) | 0 |
| Conv2D (64 filters) | (14, 14, 64) | 18,496 |
| MaxPooling2D | (7, 7, 64) | 0 |
| Flatten | (3136,) | 0 |
| Dense (128) | (128,) | 401,536 |
| Dropout (0.3) | (128,) | 0 |
| Dense (2, softmax) | (2,) | 258 |
| Total | 420,610 |
| Parameter | Value |
|---|---|
| Loss function | Categorical cross-entropy |
| Optimiser | Adam (lr=0.001, weight_decay=0.0001) |
| Epochs | 60 |
| Batch size | 64 |
| Train/Val split | 80% / 20% |
| Class imbalance | sklearn compute_class_weight('balanced') |
| Gradient method | Backpropagation |
Applied online during training only via Keras ImageDataGenerator:
| Augmentation | Setting |
|---|---|
| Rotation | ±10° |
| Horizontal flip | Enabled (50% probability) |
| Zoom | ±10% |
| Metric | Value |
|---|---|
| Test Accuracy | ~55% |
| Chance baseline | 50% |
| Above chance | +5 percentage points |
The model correctly learns discriminative features from DermaMNIST dermoscopy images, exceeding the 50% chance baseline. The modest accuracy reflects the inherent difficulty of distinguishing AKIEC from BCC on 28×28 pixel grayscale images with a small training set (~670 samples).
Click the badge below to open directly in Colab:
Step 1 — Clone the repository
git clone https://github.com/your-username/your-repo-name.git
cd your-repo-nameStep 2 — Install dependencies
pip install tensorflow medmnist scikit-learn numpy matplotlibStep 3 — Run the notebook
jupyter notebook MSc_simple_CNN_dermaMNIST.ipynbtensorflow>=2.0 keras medmnist scikit-learn numpy matplotlib
├── MSc_simple_CNN_dermaMNIST.ipynb # Main Colab notebook ├── README.md # This file
Raw DermaMNIST images (uint8, [0, 255]) │ ▼ Load as grayscale (as_rgb=False) → shape: (N, 28, 28, 1) │ ▼ Normalise to [0.0, 1.0] → divide by 255.0 │ ▼ Filter for AKIEC (0) and BCC (1) only │ ▼ One-hot encode labels → [1,0] for AKIEC, [0,1] for BCC │ ▼ 80/20 train/validation split │ ▼ Apply class-weight balancing │ ▼ Online augmentation via ImageDataGenerator (training only) │ ▼ Feed to CNN → train for 60 epochs
This repository is the classical baseline in a QCNN vs CNN comparative study:
| Property | CNN (This repo) | QCNN (Companion repo) |
|---|---|---|
| Framework | TensorFlow / Keras | PennyLane + PyTorch |
| Input | Raw 28×28×1 image | 16-dim autoencoder latent vector |
| Trainable parameters | 420,610 | 51 |
| Test accuracy | ~55% | ~60% |
| Gradient method | Backpropagation | Parameter-shift rule |
| Training duration | 60 epochs | 200 steps |
| Hardware | GPU (Colab) | CPU (Colab) |
The QCNN achieves ~5 percentage points higher accuracy with 8,247× fewer parameters, demonstrating competitive quantum representational capacity in a low-data medical imaging regime.