AMK, Ali Mehdi Khan, home

A skin lesion classifier built to be honest about its accuracy

The Skin Lesion Classifier sorts a dermoscopic photo of a mole or spot into one of the seven HAM10000 lesion types, melanoma and basal cell carcinoma among them, with a calibrated confidence and a plain-language risk level.

I rebuilt it from a Keras notebook into three parts: a PyTorch training pipeline, a FastAPI service that runs the model with ONNX Runtime, and a React app. It is a research and teaching tool, not a diagnosis.

lesion types, learned from 10,015 dermoscopic images
model time per image on a CPU
for an image it has seen before, from the cache
train, validation and test split, made by lesion

What was wrong with the first version

The project started as a Keras notebook: a frozen MobileNetV2 with a small head on top. Going back to it, I found its numbers could not be trusted.

So I treated the rebuild as a chance to get one number I could defend, rather than a bigger one.

Splitting by lesion, not by photo

The new pipeline splits with StratifiedGroupKFold on the lesion ID: 70% for training, 15% for validation and 15% for testing, stratified by diagnosis. No lesion appears in two splits, the split files are saved so any run can be reproduced, and the test set is touched once, at the end.

Training for the rare cancers

About 67% of the images are benign moles, so a model can look accurate while missing melanoma. Three choices push back on that:

The backbone is an ImageNet-pretrained EfficientNet-B2 at 256 px, fine-tuned end to end with AdamW, a warm-up then cosine decay, mixed precision, gradient clipping, an exponential moving average of the weights and early stopping. At inference, predictions are averaged over flipped views.

Confidence that means something

A medical interface should not say 95% when it means 70%. After training, temperature scaling is fitted on the validation set, so a reported 80% is right about 80% of the time.

The API adds up the probabilities of melanoma, basal cell carcinoma and actinic keratosis into one malignant probability and turns it into a risk level. When the top class is under 50%, the app says the model is unsure instead of naming a type.

Fast on an old CPU

I wanted it to run without a GPU, so I benchmarked backbones in ONNX Runtime on my development machine, a 2015 quad-core Intel Core i5-6500T throttled to about 0.8 GHz during the tests. The numbers moved with the machine’s load, so treat them as rough.

Backbone, one 224 px image, 4 threadsMedian
ConvNeXt-Tiny
ResNet-50
EfficientNet-B2 (chosen)
EfficientNet-B0

Through the whole API, with decoding and preprocessing, one view takes about 55 ms and the default two flipped views about 140 ms. A repeat upload comes back from the cache in about 5 ms. ONNX Runtime also keeps the runtime near 50 MB, where PyTorch would need about 2 GB.

Built to be served

Its limits, stated plainly

Hiring for work like this?

I'm open to entry-level software engineering and AI/ML roles, in India or abroad, and I can join immediately. Email is the quickest way to reach me.