A Deep Learning-based Medical Application for Classifying Skin Lesions using a Custom Mini-ResNet and Grad-CAM Explainable AI.
Watch the Artificial Intelligence diagnose skin lesions and generate real-time activation heatmaps in our deployed web application:
https://github.com/AnandkumarMall/Smart-Dermatology/raw/main/Readme_images/demo.mp4
- Overview & Motivation
- Dataset Details
- Model Architecture
- Explainable AI (Grad-CAM)
- Web Application & UI
- Cloud Deployment
- Getting Started (Local Setup)
Smart Dermatology is an end-to-end medical machine learning pipeline designed to assist in the early detection of skin diseases, such as Melanoma and Basal Cell Carcinoma.
In the medical field, a standard "black box" neural network prediction is not enough—doctors and patients need to understand why the AI made its decision. To solve this, our system heavily focuses on Explainable AI, generating thermal-style heatmaps that highlight the exact visual features of the skin lesion that triggered the neural network's diagnosis.
This repository encompasses the entire lifecycle: from raw data exploration and model training (in Jupyter Notebooks/Kaggle), to building a production FastAPI backend, and finally deploying a Scandinavian-styled Frontend to the cloud.
The neural network was trained on high-resolution dermoscopy images sourced from the ISIC (International Skin Imaging Collaboration) archive. The model is capable of classifying 8 distinct dermatological classes:
- Actinic Keratosis
- Basal Cell Carcinoma
- Pigmented Benign Keratosis
- Dermatofibroma
- Melanoma
- Nevus
- Squamous Cell Carcinoma
- Vascular Lesion
Handling this dataset was incredibly challenging due to extreme Class Imbalance and limited sample sizes for rare diseases. We utilized extensive offline Data Augmentation (rotations, zooming, flipping) exclusively on the training set to prevent data leakage and balance the class distributions.
Instead of fine-tuning massive pre-trained models (which often overfit on small medical datasets), we engineered a Custom Mini-ResNet architecture entirely from scratch using TensorFlow/Keras.
- Residual Connections (Skip Connections): Allows gradients to flow easily through the network, preventing the vanishing gradient problem in our deeper layers.
- Global Average Pooling (GAP): Replaced traditional dense flattening layers with GAP to massively reduce parameter count and prevent overfitting.
- Loss Function: Utilized specialized loss calculations and class weights to heavily penalize the model for misclassifying rare, dangerous lesions (like Melanoma) compared to common benign lesions.
- Learning Rate Scheduling: Implemented ReduceLROnPlateau and Cosine Annealing to smoothly converge to the global minimum.
To provide transparency, the backend uses Gradient-weighted Class Activation Mapping (Grad-CAM).
When an image is passed through the network, the API captures the gradients of the predicted class flowing into the final convolutional layer. By mathematically pooling these gradients and multiplying them by the layer's feature maps, we generate a 2D spatial heatmap.
- Red/Hot Zones: Indicate high activation (the AI looked heavily at this region to make its decision).
- Blue/Cool Zones: Indicate areas the AI deemed medically irrelevant to the specific diagnosis.
The frontend was meticulously built using a custom "Nordic Yellow" Design System, prioritizing Scandinavian minimalism, function, and accessibility.
- Tech Stack: Vanilla JavaScript, HTML5, CSS3.
- Design Guidelines: Utilizes IKEA Blue (
#003399) and IKEA Yellow (#FFDA1A) with strict 4px border radiuses, clean Level 1 box-shadows, and a highly structured flexbox grid. - Typography:
Noto Sansfor body and headers, andJetBrains Monofor highly legible monospace readouts. - Features: Includes drag-and-drop file uploading, animated loading spinners, and dynamic layout switching without relying on heavy frameworks like React.
The application is unified into a single repository and designed for instant Serverless/Containerized Deployment on platforms like Railway.
- Unified API: The FastAPI server not only handles heavy TensorFlow inference but also mounts and serves the static frontend (
/web_app/frontend/) to bypass CORS issues entirely. - Git LFS Auto-Fallback: The
best_skin_model.kerasfile is 134 MB and tracked via Git LFS. If the cloud deployment provider (like Nixpacks) fails to pull the LFS binary and only downloads the tiny pointer file, the Python backend intercepts the startup process and automatically downloads the real 134 MB model directly from the GitHub raw endpoint into memory. - Configuration: Includes a
railway.jsonto explicitly configure the Nixpacks builder and define the Uvicorn start command.
Want to run the AI model on your own machine? Follow these steps:
Make sure you have Python 3.10+ installed and Git LFS enabled.
git lfs installgit clone https://github.com/AnandkumarMall/Smart-Dermatology.git
cd Smart-Dermatologypython -m venv .venv
# Activate on Windows:
.venv\Scripts\activate
# Activate on macOS/Linux:
source .venv/bin/activatepip install -r requirements.txtWithout this step, your machine only holds a text pointer, not the 134MB binary model.
git lfs pulluvicorn web_app.api:app --host 127.0.0.1 --port 8000 --reloadNavigate to http://127.0.0.1:8000 in your browser, upload a skin lesion image, and watch the AI generate the Grad-CAM heatmap!