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
π¬ 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