A fine-tuned ResNet-18 classifier trained on the HAM10000 dermoscopy dataset. Given a skin lesion image, the model predicts Melanoma vs. Non-Melanoma and produces a visual analysis report with confidence percentages, a Grad-CAM heatmap, and a lesion bounding box.
Melanoma-Skin-Classifier/
├── Training_Model.py # Full training pipeline
├── Inference.py # Single-image analysis with visual report
├── Augmentation.py # Transform definitions (train + val)
├── Load_Image.py # Dataset class with subfolder support
├── Load_PreTrained.py # Model loading utility
├── requirements.txt # Python dependencies
├── checkpoints/ # Saved during training (not tracked by git)
│ ├── resnet18_best.pth # Best checkpoint (lowest val loss)
│ ├── resnet18_final.pth # Final epoch checkpoint
│ └── training_history.json # Per-epoch metrics
├── results/ # Inference reports (not tracked by git)
│ └── <image>_analysis.png
└── data/ # Dataset (not tracked by git)
└── images/
├── HAM10000_metadata.csv
├── HAM10000_images_part_1/
└── HAM10000_images_part_2/
pip install -r requirements.txt| Feature | Detail |
|---|---|
| Base model | ResNet-18 (ImageNet pretrained) |
| Classes | Melanoma (mel) · Non-Melanoma (all other dx) |
| Dataset split | 80 % train / 20 % validation (stratified) |
| Class imbalance | WeightedRandomSampler (inverse class frequency) |
| Augmentation | Flip, rotation ±20°, colour jitter |
| Optimiser | Adam — lr 1e-4 |
| Loss | CrossEntropyLoss |
| Early stopping | Patience = 3 epochs (monitors val loss) |
| Metrics | Accuracy, AUC-ROC, Precision, Recall, F1 |
| GPU support | Auto-detects CUDA, falls back to CPU |
Default run (expects data at data/images/):
python Training_Model.pyCustom paths:
python Training_Model.py \
--img-dir /path/to/HAM10000/images \
--csv /path/to/HAM10000_metadata.csv \
--ckpt-dir /path/to/save/checkpoints \
--epochs 20 \
--patience 5All arguments:
--img-dir Root directory of HAM10000 images (default: data/images)
--csv Path to HAM10000_metadata.csv (default: data/images/HAM10000_metadata.csv)
--ckpt-dir Directory to save checkpoints (default: checkpoints)
--epochs Max training epochs (default: 10)
--patience Early-stopping patience (default: 3)
--batch-size Batch size (default: 32)
--lr Adam learning rate (default: 1e-4)
python Inference.py --image path/to/lesion.jpgOptional arguments:
--checkpoint Path to .pth model file (default: checkpoints/resnet18_best.pth)
--output Path to save report PNG (default: results/<name>_analysis.png)
The output is a 4-panel PNG report:
| Panel | Description |
|---|---|
| Original Image | Input lesion resized to 224×224 |
| Grad-CAM Heatmap | Jet-coloured overlay — red/yellow regions most influenced the prediction |
| Lesion Detection | Original image with a bounding box drawn around the highest-activation region, labelled with prediction + % |
| Diagnosis | Prediction verdict · Melanoma % bar · Non-Melanoma % bar · Confidence score |
══════════════════════════════════════════════
Skin Lesion Analysis Report
══════════════════════════════════════════════
Image : ISIC_0024306.jpg
Prediction : Melanoma
Melanoma : 87.3%
Non-Melanoma : 12.7%
Confidence : 87.3% (High Confidence)
Bounding Box : x1=48 y1=52 x2=178 y2=191
Report saved : results/ISIC_0024306_analysis.png
══════════════════════════════════════════════
⚕ Results are for medical reference only.
The bounding box is derived from the Grad-CAM activation map: the heatmap is thresholded at 45 %, the largest contour is found with OpenCV, and cv2.boundingRect returns [x1, y1, x2, y2] coordinates on the 224×224 image space.
HAM10000 — Human Against Machine with 10000 training images
Tschandl, P. et al. (2018). The HAM10000 dataset. Scientific Data.
Download: https://www.kaggle.com/datasets/kmader/skin-lesion-analysis-toward-melanoma-detection
⚕ This tool is intended for research and educational purposes only and does not constitute medical advice.