media-authenticity / test_waverep_wrapper.py
cryptomathematician
added different video detector
634e783
Raw
History Blame Contribute Delete
1.99 kB
"""Validate the WaveRepDetector wrapper against known results."""
import os
import sys
from pathlib import Path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
sys.path.insert(0, str(project_root / 'sdk'))
import importlib.util
spec = importlib.util.spec_from_file_location(
'waverep_detector', project_root / 'models' / 'video' / 'waverep' / 'detector.py'
)
module = importlib.util.module_from_spec(spec)
sys.modules['waverep_detector'] = module
spec.loader.exec_module(module)
print("=" * 70)
print("WaveRep Detector Wrapper Validation")
print("=" * 70)
detector = module.WaveRepDetector(model_dir=str(project_root / 'models' / 'video' / 'waverep'))
detector.load()
print(f" Model name: {detector._model_name}")
print(f" fake_threshold: {detector.fake_threshold}")
test_videos = [
("REAL video_2026-07-10", "real_videos/video_2026-07-10_12-23-49.mp4", "REAL"),
("REAL glasses", "real_videos/glasses.mp4", "REAL"),
("FAKE Pika -_hbPLsZvvo_19_25", "D:/pika/pika/-_hbPLsZvvo_19_25.mp4", "FAKE"),
("FAKE Veo sunflower", "D:/veo/veo/veo_example_041_sunflower.mp4", "FAKE"),
("FAKE Veo cowboy", "D:/veo/veo/veo_cowboy_sun_1.mp4", "FAKE"),
]
print(f"\n{'Test':<35s} {'prob':>8s} {'verdict':>10s} {'expected':>8s} {'OK':>4s}")
print("-" * 75)
results = []
for name, path, expected in test_videos:
if not path.startswith(('D:', 'C:')):
path = str(project_root / path)
if not os.path.exists(path):
print(f"{name:<35s} MISSING: {path}")
continue
r = detector.predict_from_video_path(path, detector.fake_threshold)
prob = r.probability
actual = "FAKE" if prob >= 0.5 else "REAL"
ok = actual == expected
results.append((name, prob, actual, expected, ok))
print(f"{name:<35s} {prob:8.4f} {actual:>10s} {expected:>8s} {'OK' if ok else 'FAIL':>4s}")
print("\n" + "=" * 70)
passed = sum(1 for _, _, _, _, ok in results if ok)
print(f"Passed: {passed}/{len(results)}")
print("=" * 70)