How wrathemperor/skincancerdetection_ham100000 works
Purpose and Entrypoints
This repository trains and serves a seven-class dermatoscopic lesion classifier based on HAM10000. It has three operational entrypoints:
• Dataset organization and imbalance handling: prepare_data.py
• Transfer-learning training, fine-tuning, and evaluation: main.py
• Flask image-upload inference UI: app.py
Data Preparation and Split Boundary
prepare_data.py ingests the externally downloaded HAM10000 metadata and image partitions, performs stratified 70/15/15 train-validation-test splitting, and strategically oversamples underrepresented training classes. Its output is an expected on-disk dataset layout under data/HAM10000/ (not present in this tree), separating immutable validation/test samples from augmented/duplicated training inputs.
• prepare_data.py
• config.py
Training Input Pipeline
data_preprocessing.py constructs image-loading and augmentation pipelines for the prepared splits. Training receives real-time geometric and brightness augmentation; validation and test data are intended as evaluation-only flows. This component bridges directory-organized image data to TensorFlow/Keras model fitting.
• data_preprocessing.py
• config.py
Model Construction
model_architecture.py defines the CNN around ImageNet-pretrained MobileNetV3Small. The architecture adds pooling, normalization, dropout, and dense classification layers for the seven HAM10000 categories. The pretrained backbone creates the principal external-model dependency and supports staged transfer learning/fine-tuning.
• model_architecture.py
• config.py
Training, Checkpointing, and Evaluation
main.py orchestrates model creation, initial transfer-learning training, fine-tuning, cosine-decay scheduling, AdamW optimization, early stopping, and Keras checkpoint persistence. It consumes generators from the preprocessing stage and emits deployable .keras models plus evaluation artifacts. Visualization functions are separated into a source module for training-history, class-distribution, and confusion-matrix outputs.
• main.py
• model_architecture.py
• data_preprocessing.py
• src/visualization.py
• results
Serving and Inference Boundary
app.py is a Flask development-server entrypoint. It loads a trained Keras model, accepts user-uploaded lesion images, preprocesses them into model input, executes inference, and returns predicted class/confidence through the HTML interface. Uploaded files cross a trust boundary and are stored under the static upload directory.
• app.py
• templates/index.html
• static/uploads
Runtime and External Dependencies
The stack is Python 3.9+, TensorFlow/Keras for MobileNetV3 training and inference, Flask for local HTTP/UI serving, and Matplotlib/Seaborn for result plots. External inputs are the Kaggle-hosted HAM10000 dataset and ImageNet pretrained weights; trained model files and dataset directories are runtime artifacts described by the project but absent from the checked-in tree.
• requirements.txt
• config.py
• src/run.sh
• src/run.bat
Main entry points: main.py Training and evaluation · app.py Flask inference app · config.py Shared configuration · prepare_data.py Dataset preparation
Components 16
Data pipeline
- HAM10000 dataset · Kaggle images and metadata.
- Dataset preparation · Stratifies splits and oversamples training classes.
prepare_data.py - Prepared dataset splits · Train, validation, and test directory layout.
- Image pipelines · Loads splits and applies train-only augmentation.
data_preprocessing.py
Training
- ImageNet weights · Pretrained MobileNetV3Small weights.
- MobileNetV3 classifier · Transfer-learning model with seven-class classification head.
model_architecture.py - Training and evaluation · Runs transfer learning, fine-tuning, checkpointing, and evaluation.
main.py - Trained Keras models · Deployable .keras checkpoints.
- Training visualizations · Produces history, distribution, and confusion-matrix plots.
src/visualization.py - Evaluation results
results
Serving
- Flask inference app · Loads a model and serves image-upload inference.
app.py - Uploaded images · Untrusted uploads stored before inference.
static/uploads - Inference interface
templates/index.html
Other components
- Shared configuration
config.py - Run scripts · Platform-specific local launch helpers.
src/run.sh - Python dependencies · TensorFlow/Keras, Flask, Matplotlib, and Seaborn.
requirements.txt
Connections 20
- HAM10000 dataset → Dataset preparation: metadata and images
- Shared configuration → Dataset preparation: split settings
- Dataset preparation → Prepared dataset splits: stratified 70/15/15 splits
- Prepared dataset splits → Image pipelines: organized images
- Shared configuration → Image pipelines: image settings
- Image pipelines → Training and evaluation: augmented train and eval generators
- ImageNet weights → MobileNetV3 classifier: pretrained backbone
- Shared configuration → MobileNetV3 classifier: model settings
- MobileNetV3 classifier → Training and evaluation: model construction
- Training and evaluation → Trained Keras models: checkpoints and final model
- Training and evaluation → Training visualizations: training metrics
- Training visualizations → Evaluation results: plots
- Training and evaluation → Evaluation results: evaluation artifacts
- Trained Keras models → Flask inference app: loads model
- Inference interface → Flask inference app: image upload request
- Flask inference app → Uploaded images: stores uploaded file
- Flask inference app → Inference interface: prediction and confidence
- Run scripts → Flask inference app: launches
- Python dependencies → Training and evaluation: runtime libraries
- Python dependencies → Flask inference app: runtime libraries