| """ |
| Generate train/val/test splits for the SoloFace2 dataset. |
| |
| Uses the same stratified split logic as the training pipeline: |
| - 80% train, 10% val, 10% test |
| - Stratified by column 'p' |
| - random_state = 42 |
| |
| Output: splits.csv (image, split) |
| """ |
| import pandas as pd |
| from sklearn.model_selection import train_test_split |
| from pathlib import Path |
|
|
| LABELS_CSV = Path(r"C:\Users\Bidyut\Desktop\codebase\face-reg\fd-dataset\fd-dataset\labels.csv") |
| OUT_DIR = Path(r"C:\Users\Bidyut\Desktop\codebase\soloface2") |
| SEED = 42 |
| TEST_SPLIT = 0.1 |
| VAL_SPLIT = 0.1 |
|
|
| print(f"Loading {LABELS_CSV}...") |
| df = pd.read_csv(LABELS_CSV) |
| print(f" Total: {len(df):,} images") |
| print(f" Face (p=1): {df['p'].sum():,}") |
| print(f" No-face (p=0): {(df['p'] == 0).sum():,}") |
|
|
| |
| train_val, test = train_test_split( |
| df, test_size=TEST_SPLIT, random_state=SEED, stratify=df['p'], |
| ) |
| val_frac = VAL_SPLIT / (1.0 - TEST_SPLIT) |
| train, val = train_test_split( |
| train_val, test_size=val_frac, random_state=SEED, stratify=train_val['p'], |
| ) |
|
|
| |
| df['split'] = 'train' |
| df.loc[val.index, 'split'] = 'val' |
| df.loc[test.index, 'split'] = 'test' |
|
|
| |
| splits_path = OUT_DIR / "splits.csv" |
| df[['image', 'split']].to_csv(splits_path, index=False) |
|
|
| |
| print(f"\n{'='*50}") |
| print(f"SPLIT DISTRIBUTION") |
| print(f"{'='*50}") |
| for split in ['train', 'val', 'test']: |
| sdf = df[df['split'] == split] |
| face = (sdf['p'] == 1).sum() |
| noface = (sdf['p'] == 0).sum() |
| print(f" {split:5s}: {len(sdf):>8,} face={face:>8,} no-face={noface:>8,} ({len(sdf)/len(df)*100:.1f}%)") |
|
|
| print(f"\n Total: {len(df):>8,}") |
|
|
| |
| print(f"\n{'='*50}") |
| print(f"SOURCE DISTRIBUTION") |
| print(f"{'='*50}") |
| for src_prefix, src_name in [ |
| ('vgg_', 'VGGFace2'), |
| ('sf_train_', 'SoloFace train'), |
| ('sf_test_', 'SoloFace test'), |
| ('sf_val_', 'SoloFace val'), |
| ('wf_train_', 'WIDER FACE train'), |
| ('wf_val_', 'WIDER FACE val'), |
| ('coco_', 'COCO'), |
| ]: |
| sdf = df[df['image'].str.startswith(src_prefix)] |
| if len(sdf): |
| face = (sdf['p'] == 1).sum() |
| noface = (sdf['p'] == 0).sum() |
| print(f" {src_name:<20s}: {len(sdf):>8,} face={face:>8,} no-face={noface:>8,}") |
|
|
| print(f"\nSplits saved to: {splits_path}") |
|
|