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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- medical
|
| 6 |
+
- dermatology
|
| 7 |
+
- melanoma
|
| 8 |
+
- skin-lesion
|
| 9 |
+
- vision-transformer
|
| 10 |
+
- eva02
|
| 11 |
+
- dermoscopy
|
| 12 |
+
language:
|
| 13 |
+
- en
|
| 14 |
+
datasets:
|
| 15 |
+
- marmal88/skin_cancer
|
| 16 |
+
library_name: timm
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# EVA-02 Small β Melanoma / Skin Lesion Classifier
|
| 20 |
+
|
| 21 |
+
**Checkpoint:** `model_0001.pt` Β· **Author:** Fabian Wolz Β· **Date:** March 2026
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## 1. Introduction
|
| 26 |
+
|
| 27 |
+
This model performs **binary classification of dermoscopic skin lesion images** β malignant vs. benign β trained on a curated multi-source ISIC dataset. It is intended as a research tool for early-stage screening assistance and to support AI research in dermatology.
|
| 28 |
+
|
| 29 |
+
> β οΈ **This model is not validated for clinical use and must not replace a qualified dermatologist.**
|
| 30 |
+
|
| 31 |
+
The classifier is built on **EVA-02 Small**, a vision transformer pre-trained with Masked Image Modeling on ImageNet-22K. The model was fine-tuned end-to-end on labelled dermoscopy images with layer-wise learning rate decay (LLRD), stochastic depth regularisation, and Exponential Moving Average (EMA) weight smoothing.
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## 2. Model Overview
|
| 36 |
+
|
| 37 |
+
| Parameter | Value |
|
| 38 |
+
|---|---|
|
| 39 |
+
| Architecture | EVA-02 Small (Vision Transformer) |
|
| 40 |
+
| Checkpoint ID | `eva02_small_patch14_336.mim_in22k_ft_in1k` |
|
| 41 |
+
| Pre-training | Masked Image Modeling on ImageNet-22K (~14M images) |
|
| 42 |
+
| Patch size | 14 Γ 14 px Β· Input resolution: 336 Γ 336 px |
|
| 43 |
+
| Position encoding | Rotary Position Embeddings (RoPE) |
|
| 44 |
+
| Activation | SwiGLU |
|
| 45 |
+
| Pooling | Mean pooling of patch tokens |
|
| 46 |
+
| Classification head | Linear layer (binary output) |
|
| 47 |
+
| Drop path rate | 0.1 (stochastic depth regularisation) |
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
## 3. Dataset
|
| 52 |
+
|
| 53 |
+
### 3.1 Training, Validation and Test Sets
|
| 54 |
+
|
| 55 |
+
- **HAM10000** β Human Against Machine with 10000 training images (ISIC)
|
| 56 |
+
- **BCN20000** β Barcelona dermoscopy collection
|
| 57 |
+
- **ISIC 2018, ISIC 2019** β International Skin Imaging Collaboration challenge datasets
|
| 58 |
+
|
| 59 |
+
All images with ambiguous or missing malignancy labels were removed. Only binary labels (malignant / benign) were retained. Images are sourced from the ISIC Archive under **CC-BY-NC 4.0**.
|
| 60 |
+
|
| 61 |
+
| Split | Details |
|
| 62 |
+
|---|---|
|
| 63 |
+
| Training | Stratified by label and source dataset |
|
| 64 |
+
| Validation | Hold-out set used for model selection (AUROC-based) |
|
| 65 |
+
| Test | Final evaluation Β· 6,384 images Β· 1,305 positive / 5,079 negative |
|
| 66 |
+
|
| 67 |
+
### 3.2 Preprocessing
|
| 68 |
+
|
| 69 |
+
- U-Net segmentation: applied to images with significant non-lesion background
|
| 70 |
+
- Resize to 336 Γ 336 px with ImageNet-standard normalisation
|
| 71 |
+
- GPU-accelerated augmentation pipeline during training
|
| 72 |
+
|
| 73 |
+
---
|
| 74 |
+
|
| 75 |
+
## 4. Training Configuration
|
| 76 |
+
|
| 77 |
+
| Parameter | Value |
|
| 78 |
+
|---|---|
|
| 79 |
+
| Optimizer | AdamW with layer-wise learning rate decay (LLRD) |
|
| 80 |
+
| LR schedule | 10-epoch linear warmup β CosineAnnealingLR |
|
| 81 |
+
| Loss function | Weighted binary cross-entropy (class imbalance correction) |
|
| 82 |
+
| Epochs | 30 |
|
| 83 |
+
| Mixed precision | AMP float16 |
|
| 84 |
+
| EMA | Exponential Moving Average (used for validation and model selection) |
|
| 85 |
+
| TTA | Test-Time Augmentation: 4 transforms |
|
| 86 |
+
| Hardware | NVIDIA RTX 5070 Ti |
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## 5. Evaluation Results
|
| 91 |
+
|
| 92 |
+
**Test set:** 6,384 images Β· 1,305 malignant Β· 5,079 benign
|
| 93 |
+
**Validation AUROC (epoch 30):** ~0.9795
|
| 94 |
+
|
| 95 |
+
### Threshold Operating Points
|
| 96 |
+
|
| 97 |
+
| Metric | Crossover (0.860) | Youden's J (0.770) | 95% Sensitivity (0.640) | 97% Sensitivity (0.430) | 99% Sensitivity (0.300) | 80% Specificity (0.395) |
|
| 98 |
+
|---|---|---|---|---|---|---|
|
| 99 |
+
| Accuracy (%) | 91.95 | 91.31 | 89.80 | 85.51 | 66.54 | 83.57 |
|
| 100 |
+
| Sensitivity (%) | 91.80 | 93.72 | 95.02 | 97.01 | 99.00 | 97.55 |
|
| 101 |
+
| Specificity (%) | 91.99 | 90.69 | 88.46 | 82.56 | 58.20 | 79.98 |
|
| 102 |
+
| F1 Score (%) | 82.34 | 81.51 | 79.21 | 73.24 | 54.75 | 70.82 |
|
| 103 |
+
| PPV (%) | 74.64 | 72.11 | 67.91 | 58.83 | 37.83 | 55.59 |
|
| 104 |
+
| NPV (%) | 97.76 | 98.25 | 98.57 | 99.08 | 99.56 | 99.22 |
|
| 105 |
+
| TP | 1198 | 1223 | 1240 | 1266 | 1292 | 1273 |
|
| 106 |
+
| TN | 4672 | 4606 | 4493 | 4193 | 2956 | 4062 |
|
| 107 |
+
| FP | 407 | 473 | 586 | 886 | 2123 | 1017 |
|
| 108 |
+
| FN | 107 | 82 | 65 | 39 | 13 | 32 |
|
| 109 |
+
|
| 110 |
+
### Clinical Operating Points β Interpretation
|
| 111 |
+
|
| 112 |
+
| Threshold | Use Case |
|
| 113 |
+
|---|---|
|
| 114 |
+
| 0.300 (99% sensitivity) | Population screening β minimise missed cancers |
|
| 115 |
+
| 0.430 (97% sensitivity) | **Default β recommended general screening** |
|
| 116 |
+
| 0.640 (95% sensitivity) | Balanced screening with higher specificity |
|
| 117 |
+
| 0.770 (Youden's J) | Maximises sensitivity + specificity jointly |
|
| 118 |
+
| 0.860 (Crossover) | Sensitivity β Specificity β 91.9% |
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
## 6. How to Use
|
| 123 |
+
|
| 124 |
+
### Installation
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128
|
| 128 |
+
pip install timm pillow numpy
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
### Download the model
|
| 132 |
+
|
| 133 |
+
```python
|
| 134 |
+
from huggingface_hub import hf_hub_download
|
| 135 |
+
ckpt_path = hf_hub_download(repo_id="fawo/eva02-small-melanoma-classifier", filename="model_0001.pt")
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
### Inference
|
| 139 |
+
|
| 140 |
+
```python
|
| 141 |
+
import torch
|
| 142 |
+
import torch.nn as nn
|
| 143 |
+
import timm
|
| 144 |
+
from timm.data import resolve_data_config
|
| 145 |
+
from timm.data.transforms_factory import create_transform
|
| 146 |
+
from PIL import Image
|
| 147 |
+
|
| 148 |
+
MODEL_NAME = "eva02_small_patch14_336.mim_in22k_ft_in1k"
|
| 149 |
+
|
| 150 |
+
class ISICModel(nn.Module):
|
| 151 |
+
def __init__(self, model_name):
|
| 152 |
+
super().__init__()
|
| 153 |
+
self.model = timm.create_model(model_name, pretrained=False, drop_path_rate=0.1)
|
| 154 |
+
self.model.head = nn.Linear(self.model.head.in_features, 1)
|
| 155 |
+
def forward(self, x):
|
| 156 |
+
return self.model(x)
|
| 157 |
+
|
| 158 |
+
# Load model
|
| 159 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 160 |
+
model = ISICModel(MODEL_NAME)
|
| 161 |
+
ckpt = torch.load(ckpt_path, map_location=device)
|
| 162 |
+
model.load_state_dict(ckpt["model_state_dict"])
|
| 163 |
+
model.to(device).eval()
|
| 164 |
+
|
| 165 |
+
# Build transform from model config
|
| 166 |
+
transform = create_transform(**resolve_data_config({}, model=model.model), is_training=False)
|
| 167 |
+
|
| 168 |
+
# Run inference
|
| 169 |
+
img = transform(Image.open("lesion.jpg").convert("RGB")).unsqueeze(0).to(device)
|
| 170 |
+
with torch.no_grad():
|
| 171 |
+
prob = torch.sigmoid(model(img)).item()
|
| 172 |
+
|
| 173 |
+
# Apply threshold (default: 0.430 = 97% sensitivity)
|
| 174 |
+
label = "MALIGNANT" if prob >= 0.430 else "benign"
|
| 175 |
+
print(f"Probability: {prob:.4f} β {label}")
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
### Standalone inference script
|
| 179 |
+
|
| 180 |
+
A ready-to-run `predict.py` with folder batch mode, CSV output, and all threshold options is available in the GitHub repository:
|
| 181 |
+
π [github.com/FaGit99/melanoma-classifier-eva02](https://github.com/FaGit99/melanoma-classifier-eva02)
|
| 182 |
+
|
| 183 |
+
---
|
| 184 |
+
|
| 185 |
+
## 7. Intended Use and Limitations
|
| 186 |
+
|
| 187 |
+
### Intended Use
|
| 188 |
+
- Research and development in AI-assisted dermatology
|
| 189 |
+
- Prototype screening tool β requires clinical validation before any patient-facing deployment
|
| 190 |
+
- Benchmark baseline for EVA-02-based dermoscopy classifiers
|
| 191 |
+
|
| 192 |
+
### Known Limitations
|
| 193 |
+
- **Not for clinical diagnosis.** Must not replace a qualified dermatologist.
|
| 194 |
+
- Trained predominantly on lighter skin tone images (HAM10000, ISIC). Performance on darker skin tones is not validated and likely degraded.
|
| 195 |
+
- Spurious correlations detected via GradCAM analysis: vignette borders, ink markers, and hair artifacts can influence predictions.
|
| 196 |
+
- Epoch 30 of the training run β edge of overfitting.
|
| 197 |
+
- Domain shift expected on images captured outside dermoscopy conditions.
|
| 198 |
+
|
| 199 |
+
---
|
| 200 |
+
|
| 201 |
+
## 8. License
|
| 202 |
+
|
| 203 |
+
**CC-BY-NC 4.0** β Non-commercial use only.
|
| 204 |
+
|
| 205 |
+
This restriction is inherited from the upstream training datasets (HAM10000, BCN20000, ISIC 2018/2019), all of which are licensed CC-BY-NC 4.0. Commercial use requires separate licensing of all source datasets.
|
| 206 |
+
|
| 207 |
+
---
|
| 208 |
+
|
| 209 |
+
## 9. Citation
|
| 210 |
+
|
| 211 |
+
```bibtex
|
| 212 |
+
@misc{wolz2026melanoma,
|
| 213 |
+
title = {EVA-02 Small Melanoma Classifier},
|
| 214 |
+
author = {Wolz, Fabian},
|
| 215 |
+
year = {2026},
|
| 216 |
+
url = {https://huggingface.co/fawo/eva02-small-melanoma-classifier},
|
| 217 |
+
note = {Checkpoint model\_0001, validation AUROC 0.9795}
|
| 218 |
+
}
|
| 219 |
+
```
|
| 220 |
+
|
| 221 |
+
---
|
| 222 |
+
|
| 223 |
+
## 10. Acknowledgements
|
| 224 |
+
|
| 225 |
+
This work was conducted by **Fabian Wolz** ([github.com/FaGit99](https://github.com/FaGit99)) as an independent research project. Machine learning strategy guidance and algorithm implementation support were provided by **Claude** (Anthropic). The intellectual direction, experimental design, clinical framing, and all scientific judgements are the author's own.
|
| 226 |
+
|
| 227 |
+
Model architecture and pretrained weights provided via the **timm** library (Wightman, R., 2019, [github.com/huggingface/pytorch-image-models](https://github.com/huggingface/pytorch-image-models)). Training infrastructure relies on **PyTorch** (Paszke et al., 2019) and **torcheval**.
|
| 228 |
+
|
| 229 |
+
Training data sourced from the [ISIC Archive](https://isic-archive.com): HAM10000 (Tschandl et al., 2018), BCN20000 (Combalia et al., 2019), and the ISIC 2018 and 2019 challenge datasets. The authors of these datasets are gratefully acknowledged for making their work publicly available to the research community.
|