AI-Powered Skin Cancer Detection

A deep learning solution for early detection and classification of skin lesions

Project Overview

This project implements a Convolutional Neural Network (CNN) to classify skin lesions into seven distinct diagnostic categories. The model assists healthcare professionals in early detection of skin cancer, particularly melanoma, by analyzing dermoscopic images with high accuracy.

Built with modern deep learning frameworks and deployed as a web application, this project demonstrates end-to-end machine learning development—from data preprocessing to model deployment.

Dataset: HAM10000

The model is trained on the Skin Cancer MNIST: HAM10000 dataset, containing over 10,000 dermoscopic images of pigmented skin lesions, collected from diverse patient populations.

Seven Diagnostic Classes:

  • Melanocytic Nevi (nv) - Benign moles
  • Melanoma (mel) - Malignant skin cancer
  • Benign Keratosis (bkl) - Benign lesions
  • Basal Cell Carcinoma (bcc) - Common skin cancer
  • Actinic Keratoses (akiec) - Pre-cancerous lesions
  • Vascular Lesions (vasc) - Blood vessel lesions
  • Dermatofibroma (df) - Benign skin growths

Data Preprocessing: Applied data augmentation techniques including random rotations and horizontal/vertical flips to increase dataset size to over 13,000 training samples, improving model generalization.

Model Architecture

The neural network employs a carefully designed architecture optimized for medical image classification:

CNN Layers:

  • Layer 1Conv2D (32 filters) + ReLU activation + MaxPooling (2×2)
  • Layer 2Conv2D (128 filters) + ReLU activation + MaxPooling (2×2) + Dropout (0.5)
  • Layer 3Flatten - Convert 2D features to 1D vector
  • Layer 4Dense (128 neurons) + ReLU activation
  • Layer 5Dense (32 neurons) + ReLU activation
  • OutputDense (7 neurons) + Softmax activation - Multi-class classification

Training Configuration

  • Optimizer: Adam
  • Loss Function: Categorical Crossentropy
  • Batch Size: 32
  • Image Resolution: 128×128 pixels

Performance Metrics

  • Accuracy - Overall classification rate
  • Precision - True positive accuracy
  • Recall - Sensitivity to positive cases
  • F1-Score - Harmonic mean of precision/recall

Technology Stack

Machine Learning

  • • TensorFlow / Keras
  • • NumPy & Pandas
  • • scikit-learn
  • • OpenCV & PIL

Frontend

  • • Next.js 15
  • • React 19
  • • TypeScript
  • • Tailwind CSS

Deployment

  • • ONNX Runtime
  • • Model Optimization
  • • TFLite Conversion
  • • Web Integration

Model Evaluation & Validation

Rigorous evaluation using multiple metrics ensures model reliability and clinical applicability:

  • Confusion Matrix Analysis - Visualizing classification performance across all seven classes
  • 80/20 Train-Test Split - Ensuring unbiased evaluation on unseen data
  • Macro-averaged F1-Score - Balanced performance across imbalanced classes
  • Visual Prediction Validation - Manual inspection of model predictions

Model Performance Metrics

The model was evaluated on a held-out test set (20% of the data), achieving the following metrics:

72.6%
Accuracy
77.4%
Precision
68.3%
Recall
48.6%
F1-Score (Macro)

Confusion Matrix Analysis

The confusion matrix reveals the model's classification patterns across all seven diagnostic classes:

True \ Prednvbkldfmelvascbccakiec
nv119229599364
bkl79104131067
df12530062
mel8934192037
vasc33021210
bcc2212160439
akiec13120801620

Model Interpretation:

  • Strong Performance on Majority Classes: The model achieves excellent accuracy on Melanocytic Nevi (nv), which represents the most common benign lesion in the dataset.
  • Critical Confusion Pattern: A significant source of error occurs between benign nevi and melanoma (89 melanoma cases misclassified as nevi), reflecting the known visual similarity in dermoscopic images.
  • Limited Melanoma Recall: Only 92 out of 226 melanoma cases were correctly identified (40.7% recall), indicating that many malignant cases are misclassified as benign.
  • Class Imbalance Impact: Minority classes (Dermatofibroma, Vascular Lesions, Actinic Keratoses) show reduced performance due to limited training samples.

Clinical Considerations:

  • False Negatives in Melanoma: From a medical perspective, missing melanoma diagnoses (false negatives) represents the highest clinical risk, as delayed treatment can be life-threatening.
  • Optimization Priority: The model prioritizes overall accuracy, which benefits frequent benign classes but may under-detect critical malignant cases. Future iterations should optimize for melanoma recall.
  • Decision Support Role: Despite limitations, the model demonstrates meaningful pattern recognition capabilities suitable for early-stage screening and clinical decision support, not definitive diagnosis.
  • Professional Verification Required: All predictions should be verified by qualified dermatologists, especially for suspected malignant lesions.

Performance Summary:

The model achieves 336ms/step inference time with a loss of 0.7932. While the overall accuracy of 72.6% is reasonable, the macro F1-score of 48.6% highlights challenges with class imbalance and the need for improved minority class detection, particularly for clinically critical cases like melanoma.

Key Capabilities

🎯

High Accuracy Classification

Multi-class prediction across seven distinct skin lesion types with comprehensive evaluation metrics.

Real-Time Inference

Optimized ONNX model for fast client-side predictions without server dependencies.

🔬

Clinical Decision Support

Assists healthcare professionals by providing a second opinion on dermoscopic images.

📊

Comprehensive Analytics

Detailed performance metrics including precision, recall, F1-score, and confusion matrices.

Project Impact

Skin cancer is one of the most common cancers worldwide, with early detection being critical for successful treatment. This AI-powered solution:

  • • Reduces diagnostic time by providing instant preliminary analysis
  • • Serves as a screening tool in areas with limited dermatological resources
  • • Helps minimize false negatives in melanoma detection
  • • Demonstrates practical application of deep learning in healthcare

Credits & Resources

This project was developed as a demonstration of end-to-end machine learning engineering, from research and development to deployment.

Dataset: Skin Cancer MNIST: HAM10000 by Tschandl et al.