| """Sanity check the MMDFTestDataset wiring: |
| 1. The data config resolves correctly under hydra. |
| 2. The datamodule picks MMDFTestDataset (not the FairTalking test split). |
| 3. The dataset has both real and fake samples in roughly balanced ratio |
| across all three generators. |
| 4. A single sample loads end-to-end (video + audio tensor shapes). |
| |
| Run this with the SAME python that runs `python3 src/train.py`. If the test |
| prints "ALL OK" your batch-test pipeline will see the real MMDF data. |
| |
| Usage: |
| python3 scripts/smoke_test_mmdf.py |
| """ |
| from __future__ import annotations |
|
|
| import os |
| import sys |
| from collections import Counter |
|
|
| |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
|
|
|
|
| def main() -> int: |
| os.environ.setdefault( |
| "MMDF_ROOT", |
| "/apdcephfs_gy4/share_303628665/joywu/dataset/MMDF_test_only", |
| ) |
| os.environ.setdefault( |
| "DATA_ROOT", |
| "/apdcephfs_gy4/share_303628665/joywu/dataset/FairTalking-Bench", |
| ) |
|
|
| from omegaconf import OmegaConf |
|
|
| cfg = OmegaConf.load("configs/data/fairtalking_mmdf.yaml") |
| |
| cfg_resolved = OmegaConf.create(OmegaConf.to_container(cfg, resolve=True)) |
| print("[1/4] Config resolved.") |
| print(f" use_mmdf_test = {cfg_resolved.use_mmdf_test}") |
| print(f" mmdf_root = {cfg_resolved.mmdf_root}") |
| print(f" mmdf_generators = {list(cfg_resolved.mmdf_generators)}") |
| print(f" mmdf_audio_cache = {cfg_resolved.mmdf_audio_cache_dir}") |
| assert cfg_resolved.use_mmdf_test is True, "use_mmdf_test must be True" |
|
|
| from src.data.datamodule import FairTalkingDataModule |
|
|
| dm = FairTalkingDataModule(cfg_resolved) |
| assert dm._is_test_only_cfg(), ( |
| "datamodule didn't recognise this as a test-only cfg " |
| "(setup() would try to load train/val splits)" |
| ) |
| dm.setup(stage="test") |
| test_ds = dm.test_ds |
| print(f"[2/4] datamodule.setup OK; test_ds = {type(test_ds).__name__}") |
| if type(test_ds).__name__ != "MMDFTestDataset": |
| print( |
| f" FAIL: test_ds is {type(test_ds).__name__}, expected MMDFTestDataset.\n" |
| f" This means the datamodule is silently falling through to" |
| f" FairTalking's test split.", |
| file=sys.stderr, |
| ) |
| return 2 |
|
|
| n = len(test_ds) |
| labels = [s["label"] for s in test_ds.samples] |
| gens = [s["generator"] for s in test_ds.samples] |
| print(f"[3/4] dataset size = {n}") |
| print(f" label counts = {dict(Counter(labels))}") |
| print(" per-generator counts:") |
| for g, c in sorted(Counter(gens).items()): |
| print(f" {g:24s} {c}") |
| if n < 1000: |
| print(f" FAIL: dataset too small ({n}); expected ~4876.", file=sys.stderr) |
| return 2 |
| if Counter(labels)[0] == 0 or Counter(labels)[1] == 0: |
| print( |
| " FAIL: missing one class — AUC would be ill-defined. " |
| "Check that test/real/<gen>/ exists.", |
| file=sys.stderr, |
| ) |
| return 2 |
|
|
| sample = test_ds[0] |
| v = sample["video"] |
| a = sample["audio"] |
| print(f"[4/4] first sample loaded:") |
| print(f" video shape = {tuple(v.shape)} dtype = {v.dtype}") |
| print(f" audio shape = {tuple(a.shape)} dtype = {a.dtype}") |
| print(f" label = {sample['label']}") |
| print(f" generator = {sample['meta']['generator']}") |
| print(f" basename = {sample['meta']['basename']}") |
|
|
| |
| if hasattr(a, "abs"): |
| amax = float(a.abs().max()) |
| else: |
| import numpy as np |
| amax = float(np.abs(a).max()) |
| if amax == 0.0: |
| print( |
| "\n WARNING: first sample's audio is all zeros — " |
| "this means the wav cache is missing. Audio-related ablations " |
| "(M2_audio_only / M6_drop_audio_infer / etc.) will be misleading. " |
| "Run scripts/prepare_mmdf_audio.sh first.", |
| file=sys.stderr, |
| ) |
|
|
| print("\nALL OK — mmdf data pipeline is wired correctly.") |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|