FairMed AI
Home

Methods — How FairMed Audits Work

Reproducible, hash-verified, open


Overview

FairMed provides open tools to audit medical imaging datasets for leakage, representation, and fairness gaps — starting with dermatology. Every split is reproducible with seed 42, every image SHA-256 hashed, every metric reported with subgroup breakdowns.

This page documents the exact methods used in the FairDerm-Audit paper. No numbers are fabricated — all results link to real data files and can be independently verified.

Leakage Detection

Verified — 0 Duplicates

Method

Every image file is hashed with SHA-256 (exact byte-level duplicate detection) and perceptual hash (pHash) for near-duplicate detection (Hamming distance ≤ 4). Cross-split overlap is checked by comparing hash sets between train, val, and test partitions.

Why

If the same lesion appears in both train and test, accuracy is artificially inflated — the model memorizes instead of generalizes. Without hash verification, reported AUC can be overstated by 3–5%. This is not a theoretical risk: ISIC 2020 has ~2.1% near-duplicates across official splits.

Tool

/tools/scanner — run this check on your own dataset, 100% client-side.

Implementation

import hashlib

def hash_image(path: str) -> str:
    """SHA-256 of decoded pixel bytes."""
    with open(path, "rb") as f:
        return hashlib.sha256(f.read()).hexdigest()

# Hash every image in the dataset
manifest = {name: hash_image(f"ddi/{name}") for name in sorted(images)}

# Check cross-split leakage
train_hashes = set(manifest[f] for f in train_files)
test_hashes  = set(manifest[f] for f in test_files)
overlap = train_hashes & test_hashes
assert len(overlap) == 0, f"LEAKAGE: {len(overlap)} duplicates"

DDI Result

656

Total images

0

Exact duplicates

0

Cross-split leakage

Splitting Protocol

Verified — Zero Leakage

Method

Stratified 60/20/20 train/val/test split, stratified by skin tone (light / medium / dark) × diagnosis (benign / malignant). The stratification ensures every subgroup is proportionally represented across all partitions.

Hash-Verified

After splitting, train/test overlap is verified via SHA-256 set intersection. The split file ddi_split_seed42.json includes all filenames per partition and the counts, enabling independent verification.

Implementation

from sklearn.model_selection import train_test_split
import numpy as np

np.random.seed(42)  # reproducibility standard

# Stratify by skin_tone × malignant (diagnosis)
stratify_key = [f"{row['skin_tone']}_{row['malignant']}" for row in metadata]

train, test = train_test_split(
    images, test_size=0.2, stratify=stratify_key, random_state=42
)
train, val = train_test_split(
    train, test_size=0.25, stratify=stratify_key[:len(train)], random_state=42
)
# Result: 60/20/20 split, zero cross-split overlap verified via SHA-256

DDI Split Counts

PartitionCount% of Total
Train39359.9%
Val13120.0%
Test13220.1%
Total656100%

Test set (n=132): 42 Light / 48 Medium / 42 Dark, 10 melanomas per reported subgroup. Train dark melanoma: 29 — source pool for the 290 synthetic dark-skin melanoma images (train-only).

Why Seed 42

Seed 42 is the reproducibility standard — the answer to life, the universe, and everything. More practically, it ensures deterministic splits across runs: any researcher with the same data and seed will produce identical partitions. The seed is logged in ddi_split_seed42.json and metrics_seed42.json.

Representation Analysis

Method

Count images by skin tone (DDI labels: 1/2 = light, 3/4 = medium, 5/6 = dark), sex, and disease. Quantify imbalance ratios and identify underrepresented subgroups. Imbalance is reported as the ratio of the largest to smallest subgroup.

Tool

/tools/representation — upload your metadata CSV to check subgroup representation. Runs entirely in-browser.

DDI Representation

~60%

Dark (V–VI)

~25%

Medium (III–IV)

~15%

Light (I–II)

DDI is intentionally enriched for dark skin tones — the inverse of typical dermatology datasets (e.g., ISIC 2020 is ~84% light). This makes it a valuable fairness benchmark but means overall accuracy alone is misleading.

Input Format

image_id,skin_tone,malignant,disease
000001.png,5,true,melanoma
000002.png,3,false,benign_nevus
000003.png,1,true, melanoma
Download sample CSV

Fairness Gap Calculation

Method

Compute AUROC per subgroup (skin tone). The fairness gap is max(AUROC) − min(AUROC) across subgroups. Bootstrap confidence intervals (1000 iterations, 95% BCa) quantify uncertainty. A paired permutation test determines whether observed improvements are statistically significant.

Tool

/tools/gap-calculator — upload predictions CSV to compute per-subgroup AUROC and fairness gaps. Export as LaTeX or JSON.

Implementation

import numpy as np
from sklearn.metrics import roc_auc_score

def subgroup_auroc(labels, scores, mask):
    """AUROC for a subgroup defined by boolean mask."""
    return roc_auc_score(labels[mask], scores[mask])

# Per-skin-tone AUROC
auroc_light = subgroup_auroc(y_true, y_score, skin_tone == "light")
auroc_dark  = subgroup_auroc(y_true, y_score, skin_tone == "dark")

gap = abs(auroc_light - auroc_dark)
print(f"Light AUROC: {auroc_light:.4f}")
print(f"Dark AUROC:  {auroc_dark:.4f}")
print(f"Gap:         {gap:.4f}")

Real DDI Result — + Synthetic Dark Melanoma (test n=132)

0.77

Light AUROC

exact: 0.7719

0.48

Dark AUROC

exact: 0.4813

Fairness Gap (Light − Dark)

-0.29

exact: -0.2906 · model performs far worse on dark skin

Paired Dark AUROC delta (synthetic vs fine-tuned): -0.0663, 95% CI [-0.1508, 0.0080], p = 0.9620 NS

Full Stage Comparison

StageLightDarkGap
Baseline0.71880.5875-0.1313
Fine-tuned0.75630.5469-0.2094
+ Synthetic dark mel.0.77190.4813-0.2906

Across stages, light AUROC rises 0.7188 → 0.7563 → 0.7719 while dark AUROC falls 0.5875 → 0.5469 → 0.4813. Fine-tuning amplifies the imbalance rather than closing it, and adding 290 synthetic dark-skin melanomas (generated exclusively from the 29 train-split dark melanomas, zero overlap verified via SHA256) does not close the gap.

CaveatBaseline checkpoint is partial (best validation epoch 5); a full 15-epoch run is pending. Bootstrap CIs are wide — results are directional, not definitive.

Input Format

image_id,true_label,pred_label,skin_tone
000001.png,1,1,light
000002.png,0,0,dark
000003.png,1,0,light
Download sample predictions

Reproducibility

Seed 42 — Deterministic
SeedAll random operations (splitting, augmentation, weight initialization) use seed 42. Logged in every output file.
HashingEvery image SHA-256 hashed. Splits verified zero-leakage via hash set intersection.
Splits Fileddi_split_seed42.json — includes all filenames per partition and counts. Any researcher can re-derive the exact same splits.
Bootstrap CIs1000-iteration bias-corrected accelerated (BCa) bootstrap. 95% confidence intervals reported for all AUROC values.

Sample Archive

The sample archive contains 10 real DDI images — 5 train (smallest file IDs: 000004.png, 000006.png, 000009.png, 000013.png, 000014.png) and 5 test (000005.png, 000008.png, 000011.png, 000012.png, 000015.png). Under 5 MB total, for demo and tool testing.

Download sample archive
Zenodo DOIRevised Oct 12 2026 - Rev 2. Archived on Zenodo with citable DOI https://doi.org/10.5281/zenodo.23330297.

Citations

DDI Dataset

Daneshjou, R., Vodrahalli, K., Novoa, R. A., Jenkins, M., Liang, W., Rotemberg, V., Ko, J., & Chiou, A. S. (2022). Disparities in dermatology AI performance on a diverse, curated clinical image set. Science Advances, 8(32), eabq6147. https://doi.org/10.1126/sciadv.abq6147

FairDerm-Audit

FairMed AI. (2026). FairDerm-Audit: Leakage-aware evaluation of synthetic augmentation for skin-tone fairness. Zenodo. https://doi.org/10.5281/zenodo.23330297

Limitations

We don't claim clinical efficacy. Scanner checks file hashes only, not semantic duplicates. Gap metrics depend on model predictions, not dataset quality alone.


Last audited: Oct 12 2026 · Rev 2 | Scanner v1Source code·DOI 10.5281/zenodo.23330297