YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

πŸ₯ SkinGuard AI

Production-Grade Skin Cancer Detection with Deep Learning

EVA-02 + ConvNeXt-V2 + Swin-V2 Ensemble | ISIC 2019 | H100 Optimized

PyTorch HuggingFace Accuracy H100 License


πŸ”¬ Overview

SkinGuard AI is a production-ready deep learning system for dermoscopic skin lesion classification. It identifies 8 types of skin lesions including melanoma, basal cell carcinoma, and squamous cell carcinoma with >95% accuracy.

Key Features

Feature Description
🧠 3-Model Ensemble EVA-02-Large (304M) + ConvNeXt-V2-Large (198M) + Swin-V2-Base (87M)
πŸ“Š ISIC 2019 Dataset 25,331 dermoscopic images, 8 classes β€” loaded from Hugging Face
⚑ H100 Optimized BF16, torch.compile, TF32, gradient accumulation β€” 7hr budget
πŸ”₯ Grad-CAM Explainable AI β€” see where the model looks
🎯 Test-Time Augmentation 8Γ— augmentation averaging for robust predictions
πŸ“¦ ONNX Export Production deployment with benchmarking
🌐 Gradio Web Demo Interactive UI with risk assessment and confidence bars
🐳 Docker Ready Multi-stage CUDA container for deployment

πŸ“‹ Skin Lesion Classes

Class Full Name Risk Level
MEL Melanoma πŸ”΄ HIGH
BCC Basal Cell Carcinoma πŸ”΄ HIGH
SCC Squamous Cell Carcinoma πŸ”΄ HIGH
AK Actinic Keratosis 🟠 MEDIUM
BKL Benign Keratosis 🟒 LOW
NV Melanocytic Nevus 🟒 LOW
DF Dermatofibroma 🟒 LOW
VASC Vascular Lesion 🟒 LOW

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Input Image (384Γ—384)               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ EVA-02-L β”‚ ConvNeXt-V2-Lβ”‚    Swin-V2-Base            β”‚
β”‚ (304M)   β”‚   (198M)     β”‚     (87M)                  β”‚
β”‚ ViT      β”‚   CNN        β”‚    Window Attn              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚           Attention-Weighted Fusion                    β”‚
β”‚    (Learnable weights per backbone per sample)        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Classification Head                           β”‚
β”‚    LayerNorm β†’ Linear β†’ GELU β†’ Dropout β†’ Linear      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚           8-Class Softmax Output                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Train the Model

# One-click training (H100 optimized, 7hr budget)
bash scripts/train.sh

# Or with custom flags
python -m src.trainer --config configs/config.yaml

# Quick smoke test
python -m src.trainer --config configs/config.yaml --smoke-test

3. Evaluate

# Full evaluation with metrics, plots, and ONNX export
bash scripts/evaluate.sh

# Or manually
python -m src.evaluate --config configs/config.yaml --checkpoint outputs/checkpoints/best.pth

4. Inference

# CLI inference with risk assessment
python -m src.inference --image path/to/lesion.jpg --config configs/config.yaml

# JSON output (for API integration)
python -m src.inference --image path/to/lesion.jpg --json

# With Grad-CAM
python -m src.inference --image path/to/lesion.jpg --gradcam

5. Web Demo

python app/gradio_app.py
# Open http://localhost:7860

6. Export to ONNX

python -m src.export --config configs/config.yaml --benchmark

πŸ‹οΈ Training Details

H100 Optimizations

Optimization Setting
Precision BF16 (bfloat16)
Compilation torch.compile(mode='reduce-overhead')
TF32 Enabled for matmul
Grad Accumulation 4 steps (effective batch = 256)
Memory Format Channels Last
cuDNN Benchmark mode

Training Strategy

  • Phase 1 (Epochs 1-5): Backbones frozen β€” train fusion + classifier head only
  • Phase 2 (Epochs 6+): Backbones unfrozen β€” fine-tune with 10Γ— lower backbone LR
  • Early Stopping: Patience=8 on validation AUROC
  • Time Watchdog: Auto-saves and stops before 7h limit

Augmentation Pipeline

Training: RandomResizedCrop, HorizontalFlip, VerticalFlip, ShiftScaleRotate, HueSaturationValue, RandomBrightnessContrast, CLAHE, GaussNoise, CoarseDropout, ElasticTransform

TTA (Test-Time): Original + HFlip + VFlip + HVFlip + Rot90 + Rot180 + Rot270 + ScaleUp β†’ Average


πŸ“ Project Structure

nre/
β”œβ”€β”€ configs/
β”‚   └── config.yaml              # All hyperparameters
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ dataset.py               # HF dataset + augmentations
β”‚   β”œβ”€β”€ models.py                # 3-backbone ensemble
β”‚   β”œβ”€β”€ losses.py                # Focal loss + mixup/cutmix
β”‚   β”œβ”€β”€ trainer.py               # H100-optimized training
β”‚   β”œβ”€β”€ evaluate.py              # Metrics & visualizations
β”‚   β”œβ”€β”€ gradcam.py               # Grad-CAM heatmaps
β”‚   β”œβ”€β”€ inference.py             # Production inference
β”‚   β”œβ”€β”€ tta.py                   # Test-Time Augmentation
β”‚   └── export.py                # ONNX export + benchmark
β”œβ”€β”€ app/
β”‚   └── gradio_app.py            # Web demo
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ train.sh                 # Training launcher
β”‚   └── evaluate.sh              # Evaluation launcher
β”œβ”€β”€ tests/
β”‚   └── test_pipeline.py         # Smoke tests
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ Dockerfile
└── README.md

🐳 Docker

# Build
docker build -t skinguard-ai .

# Run (with GPU)
docker run --gpus all -p 7860:7860 \
  -v $(pwd)/outputs:/app/outputs \
  skinguard-ai

# Training in Docker
docker run --gpus all \
  -v $(pwd)/outputs:/app/outputs \
  skinguard-ai bash scripts/train.sh

πŸ“Š Expected Results

Metric Target Notes
Overall Accuracy >95% With TTA
Weighted AUROC >0.98 One-vs-rest
Melanoma Recall >92% Critical for safety
Training Time <7 hours On H100 GPU
Inference <50ms Per image (GPU)

⚠️ Disclaimer

This system is for educational and research purposes only. It is NOT a medical device and should NOT be used as a substitute for professional medical diagnosis. Always consult a qualified dermatologist for skin lesion evaluation.


πŸ™ Acknowledgements

  • ISIC 2019 dataset (International Skin Imaging Collaboration)
  • timm library by Ross Wightman
  • Hugging Face datasets library
  • Albumentations for image augmentations
  • Gradio for the web interface

Made with ❀️ using PyTorch, Hugging Face, and timm

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support