Skin Lesion Classification (Benign vs Malignant)
β οΈ MEDICAL & REGULATORY DISCLAIMER
This model is for educational and research purposes only.
- Must NOT be used in real-world/clinical applications (screening, triage, diagnosis, or treatment).
- Not a medical device and not reviewed/approved by any regulator (e.g., FDA/MHRA).
- Outputs must NOT replace clinical judgment. All suspicious lesions should be evaluated by a qualified clinician.
Model Description
This model classifies dermoscopic images of skin lesions as benign or malignant using a fine-tuned ResNet50 architecture.
- Architecture: ResNet50 (pre-trained on ImageNet) + Custom Classification Head
- Task: Binary Classification (Benign vs Malignant)
- Dataset: HAM10000 (10,015 dermoscopic images)
- Training: 25 epochs, Intel Core i5-12500H (CPU), ~4.5 hours
- Input: 224Γ224Γ3 RGB images
- Parameters: 24.7M total (15.6M trainable, 63.1%)
Performance Metrics (Test Set - 1,505 images)
| Metric | Value |
|---|---|
| Accuracy | 81.59% |
| ROC-AUC | 0.8900 |
| PR-AUC | 0.6602 |
| Precision | 0.5121 |
| Recall | 0.8056 |
| Loss | 0.4426 |
Clinical Interpretation:
- High Recall (80.56%): Catches 80% of malignant lesions (crucial for screening)
- Moderate Precision (51.21%): Some false positives (acceptable for medical screening)
- Strong ROC-AUC (0.89): Excellent discrimination ability
Usage
Installation
pip install tensorflow huggingface_hub pillow numpy
Complete Inference Script
# Import required libraries
from huggingface_hub import hf_hub_download
import tensorflow as tf
import numpy as np
from PIL import Image
# Download model from Hugging Face
print("Downloading model from Hugging Face...")
model_path = hf_hub_download(
repo_id="devatreya/skin-lesion-resnet50",
filename="resnet50_best.h5"
)
# Load model
print("Loading model...")
model = tf.keras.models.load_model(model_path)
# Preprocess image function
def preprocess_image(image_path):
"""Load and preprocess image for ResNet50"""
img = Image.open(image_path).convert('RGB')
img = img.resize((224, 224))
img_array = np.array(img, dtype=np.float32)
# ResNet50 preprocessing (ImageNet/Caffe-style)
img_array = img_array[..., ::-1] # RGB to BGR
mean = [103.939, 116.779, 123.68]
img_array[..., 0] -= mean[0]
img_array[..., 1] -= mean[1]
img_array[..., 2] -= mean[2]
return np.expand_dims(img_array, axis=0)
# Run inference
image_path = "path/to/your/lesion_image.jpg" # Change this
img_array = preprocess_image(image_path)
prediction = model.predict(img_array)[0][0]
# Display result
print(f"\n{'='*50}")
print(f"Prediction: {'MALIGNANT' if prediction >= 0.5 else 'BENIGN'}")
print(f"Confidence: {prediction:.2%}")
print(f"{'='*50}")
Model Architecture
ResNet50 Backbone:
- Pre-trained on ImageNet
- Input: 224Γ224Γ3 RGB images
- Preprocessing: ImageNet normalization (Caffe-style)
Custom Classification Head:
GlobalAveragePooling2D
β
BatchNormalization
β
Dropout (0.5)
β
Dense (512, ReLU)
β
BatchNormalization
β
Dropout (0.5)
β
Dense (256, ReLU)
β
Dropout (0.3)
β
Dense (1, Sigmoid)
Training Configuration
- Loss: Weighted Binary Cross-Entropy (pos_weight=4.12 for class imbalance)
- Optimizer: AdamW (learning_rate=1e-4)
- Batch Size: 16
- Epochs: 25
- Data Split: 70% train / 15% validation / 15% test (lesion-level stratified)
- Callbacks: ModelCheckpoint, EarlyStopping, ReduceLROnPlateau
Educational use only β NOT for real-world or clinical applications.
Medical & Regulatory Disclaimer
This model is for educational and research purposes only. It must not be used in real-world/clinical contexts (including screening, triage, diagnosis, or treatment). It is not a medical device and has not been reviewed or approved by any regulatory authority (e.g., FDA/MHRA). Model outputs must not replace clinical judgment; any suspicious lesions should be evaluated by a qualified clinician.
Scope & Limitations (optional to keep)
- Trained on HAM10000 dermoscopic images; may not generalize to other image types, devices, clinics, or skin tones.
- Binary prediction (malignant vs. benign); chosen threshold strongly affects precision/recall.
Dataset
HAM10000: Human Against Machine with 10,000 training images
- 10,015 dermoscopic images
- 7 lesion types collapsed into binary labels:
- Benign: nv (melanocytic nevi), bkl (benign keratosis), df (dermatofibroma), vasc (vascular lesions)
- Malignant: mel (melanoma), bcc (basal cell carcinoma), akiec (actinic keratoses)
- Source: HAM10000 on Kaggle
Citation
If you use this model, please cite the HAM10000 dataset:
@article{tschandl2018ham10000,
title={The HAM10000 dataset, a large collection of multi-source dermatoscopic images of common pigmented skin lesions},
author={Tschandl, Philipp and Rosendahl, Cliff and Kittler, Harald},
journal={Scientific data},
volume={5},
number={1},
pages={1--9},
year={2018},
publisher={Nature Publishing Group}
}
License
MIT License - See repository for details.
More Information
- GitHub Repository: https://github.com/devatreya/Skin-lesion-classification-using-CNN
- Full Documentation: See GitHub README for complete training details
- Model File:
resnet50_best.h5(214 MB)