Skip to content

About

Leakage-safe skin-lesion classification using HAM10000, TensorFlow/Keras, and Flask.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Deep Lesion

Leakage-safe skin-lesion classification using HAM10000, TensorFlow/Keras, and Flask.

Deep Lesion is a research-oriented image-classification project for seven common dermoscopic lesion categories. It includes dataset auditing, lesion-level splitting, GPU training, calibrated evaluation, and a small web demonstration API.

Important: This project is not a medical device and must not be used to diagnose, triage, or treat patients. Predictions are research estimates only and require review by a qualified clinician.

Results

The included EfficientNetV2-B2 artifact was evaluated once on a held-out, lesion-grouped test split after validation-only calibration:

Metric Result Gate
Accuracy 0.803 ≥ 0.800
Balanced accuracy 0.730 ≥ 0.650
Macro-F1 0.694 ≥ 0.650
Melanoma recall 0.635 ≥ 0.600

Full metrics are available in reports/test_metrics.json. The model artifact and its preprocessing/calibration contract are stored in artifacts/.

Classification categories

Code Category
akiec Actinic keratoses / intraepithelial carcinoma
bcc Basal cell carcinoma
bkl Benign keratosis-like lesions
df Dermatofibroma
mel Melanoma
nv Melanocytic nevi
vasc Vascular lesions

Highlights

  • Leakage-safe evaluation: images are split by lesion_id, preventing multiple views of one lesion from crossing train, validation, and test folds.
  • Dataset validation: metadata-to-image mapping, class coverage, image readability, and split integrity are checked before training.
  • Transfer learning: EfficientNetV2-B0/B2 candidates with weighted cross-entropy or focal loss.
  • Calibration: temperature scaling and a validation-only melanoma decision bias are persisted with the model.
  • Production-shaped inference: raw RGB input, embedded resizing/preprocessing, in-memory upload validation, top-3 predictions, uncertainty flag, and safety disclaimer.
  • Reproducible tooling: configuration, deterministic split manifest, CLI commands, tests, and a GPU launcher are included.

Dataset

Download HAM10000 separately and place the image folders and metadata file under dataset/:

dataset/
├── HAM10000_metadata.csv
├── HAM10000_images_part_1/
│   └── *.jpg
└── HAM10000_images_part_2/
    └── *.jpg

The audit expects 10,015 metadata rows mapped to readable JPEG files. The derived hmnist_*.csv files are not used by the training pipeline. HAM10000 licensing and usage terms apply; do not redistribute the dataset without checking its license.

Installation

Python 3.13 is required. uv is used for environment and lockfile management.

uv sync --extra gpu --extra dev

For CPU-only inference or development, omit --extra gpu.

Verify TensorFlow and the GPU before training:

uv run python -c "import tensorflow as tf; print(tf.__version__); print(tf.config.list_physical_devices('GPU'))"

Training and evaluation

Run these commands from the repository root after the dataset and GPU are available:

uv run deep-lesion audit --data-dir dataset
uv run deep-lesion split --data-dir dataset --output artifacts/splits.csv
./scripts/train_gpu.sh
uv run deep-lesion evaluate \
  --checkpoint artifacts/skin_lesion_classifier.keras \
  --metadata artifacts/model_metadata.json \
  --split artifacts/splits.csv \
  --output reports/test_metrics.json

The training configuration is in configs/train.yaml. Training never uses the test fold for model selection or calibration. The evaluation command exits with status 0 only when every quality-gate requirement passes.

Web demo and API

Start the local Flask application after a model artifact exists:

uv run deep-lesion serve

Then open http://127.0.0.1:5000.

Method Endpoint Description
GET / Upload interface
POST /api/predict Multipart field image; returns top-three estimates and calibrated probabilities
GET /health Model readiness and artifact path

Uploads are decoded in memory, limited to 10 MiB, rejected when unreadable or unsafe, and never persisted by the application.

Model contract

The exported model accepts RGB float32 pixels in [0, 255], performs resizing and EfficientNetV2 preprocessing internally, and emits logits in this fixed order:

akiec, bcc, bkl, df, mel, nv, vasc

artifacts/model_metadata.json records the model version, class order, split digest, input contract, temperature, melanoma calibration bias, and uncertainty threshold.

Project layout

deep_lesion/       Core data, model, training, evaluation, inference, and CLI code
configs/           Versioned training configuration
scripts/           GPU-safe training launcher
templates/         Flask web interface
tests/             Fast unit and contract tests
artifacts/         Split manifest, trained model, and model metadata
reports/           Evaluation reports

Development

uv run ruff check .
uv run pytest

The test suite uses small fixtures and does not require the full dataset or a GPU. Full training is intentionally excluded from automated tests.

Limitations

HAM10000 is a curated dermoscopic research dataset. Performance may not generalize to phone photographs, different cameras, new clinical sites, other populations, or any individual patient. Class imbalance remains substantial, and aggregate metrics do not replace external validation, clinical review, or prospective safety testing.

About

Leakage-safe skin-lesion classification using HAM10000, TensorFlow/Keras, and Flask.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages