This repository contains a reproducible pipeline for:
- preparing FairFace image data + label tables
- optionally detecting/cropping faces and storing the processed tensors in HDF5
- training a multi-output Keras model (shared backbone + separate heads)
- running subgroup evaluation and exporting metrics artifacts
notebooks/: interactive exploration and training notebooks (kept lightweight; core logic lives insrc/)src/ff_pipeline/: reusable modules (data IO, preprocessing, model, training, evaluation)scripts/: thin CLI wrappersdata/: dataset assets (ignored by git)models/: model checkpoints (ignored by git)
Place FairFace under:
data/
fairface/
train/*.jpg
val/*.jpg
fairface_label_train.csv
fairface_label_val.csv
Label CSV format (minimum):
file: relative path liketrain/1.jpgorval/1.jpg(relative todata/fairface/)age: age bucket stringgender:Male/Femalerace: one of 7 categoriesservice_test:True/False(kept as metadata)
Create a virtual environment, then install dependencies:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e .python scripts/prepare_labels.py \
--train-csv data/fairface_label_train.csv \
--val-csv data/fairface_label_val.csv \
--out-dir data \
--test-size 0.2 \
--seed 42python scripts/preprocess_to_hdf5.py \
--data-dir data \
--train-csv data/fairface_label_train_encoded.csv \
--val-csv data/fairface_label_val_encoded.csv \
--test-csv data/fairface_label_test_encoded.csv \
--out-dir data \
--image-size 224 \
--batch-size 512This produces:
data/train.h5,data/val.h5,data/test.h5data/no_face_detected.log
python scripts/train.py \
--train-h5 data/train.h5 \
--val-h5 data/val.h5 \
--out-dir models \
--batch-size 16 \
--epochs 10 \
--max-train-samples 5000 \
--max-val-samples 5000python scripts/evaluate.py \
--h5 data/test.h5 \
--labels-csv data/fairface_label_test_encoded.csv \
--model models/best_model.keras \
--out-dir reportsOutputs include:
reports/overall_metrics.csvreports/subgroup_metrics.csv(race / gender / intersection)reports/disparity_summary.csv(worst-group + max–min gaps)reports/confusion_matrices_long.csv(overall + per-group)reports/calibration_tables.csv(confidence-binned reliability tables)reports/predictions.csv(per-example predictions + confidence)
- The
data/andmodels/directories are intentionally ignored by git (large artifacts). - If you are on macOS, TensorFlow installation varies by hardware. Use a compatible TensorFlow build for your system.