Spaces:
Running on Zero
Running on Zero
| """ | |
| Scientifically controlled spatial-scale experiment. | |
| Extract the ORIGINAL 8 DeCoF frames from a 2048x1152 Veo video, | |
| center-crop to square, then test MULTIPLE spatial resolutions through | |
| DeCoF's preprocessing (which resizes each to 224x224). | |
| This isolates spatial downsampling from video transcoding artifacts. | |
| """ | |
| import os | |
| import sys | |
| import cv2 | |
| import numpy as np | |
| import torch | |
| 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( | |
| 'decof_detector', project_root / 'models' / 'video' / 'DeCoF' / 'detector.py' | |
| ) | |
| module = importlib.util.module_from_spec(spec) | |
| sys.modules['decof_detector'] = module | |
| spec.loader.exec_module(module) | |
| # Test videos (2048x1152 originals) | |
| videos = [ | |
| 'D:/veo/veo/veo_example_014_jellyfish.mp4', | |
| 'D:/veo/veo/veo_example_006_northern_lights.mp4', | |
| 'D:/veo/veo/veo_cowboy_sun_1.mp4', | |
| 'D:/veo/veo/veo_example_043_alpacas.mp4', | |
| 'D:/veo/veo/veo_example_011_lighthouse.mp4', | |
| 'D:/veo/veo/veo_example_012_elephant.mp4', | |
| ] | |
| # Spatial scales to test (square side length) | |
| scales = [1152, 960, 720, 576, 448, 336, 224] | |
| print("=" * 70) | |
| print("DeCoF Spatial-Scale Experiment (controlled, no transcoding)") | |
| print("=" * 70) | |
| print("\n[1] Loading detector...") | |
| detector = module.DeCoFDetector() | |
| detector.load() | |
| print("\n[2] Extracting original frames and testing spatial scales...\n") | |
| # For each video | |
| for video_path in videos: | |
| name = os.path.basename(video_path) | |
| print(f"\n--- {name} ---") | |
| # Extract the 8 original DeCoF frames (2048x1152) | |
| frames = detector._extract_decof_frames(video_path) | |
| # Center-crop each to square (1152x1152) - the ORIGINAL pixels | |
| square_frames = [] | |
| for frame in frames: | |
| h, w = frame.shape[:2] | |
| side = min(w, h) | |
| left = (w - side) // 2 | |
| top = (h - side) // 2 | |
| square_frames.append(frame[top:top+side, left:left+side]) | |
| # For each scale, resize the square frames and run DeCoF | |
| print(f" {'Scale':>6s} {'fake_prob':>10s}") | |
| for scale in scales: | |
| # Resize square frames to (scale, scale) | |
| resized_frames = [] | |
| for frame in square_frames: | |
| resized = cv2.resize(frame, (scale, scale), interpolation=cv2.INTER_LINEAR) | |
| resized_frames.append(resized) | |
| # Run DeCoF on these frames (its preprocessing will resize to 224x224) | |
| features = detector.extract_clip_features(resized_frames) | |
| with torch.no_grad(): | |
| logits = detector.small_vit(features) | |
| probs = torch.softmax(logits, dim=-1) | |
| fake_prob = float(probs[0, 1].item()) | |
| print(f" {scale:>6d} {fake_prob:10.4f}") | |
| print("\n" + "=" * 70) | |
| print("Done. If fake_prob increases as scale decreases,") | |
| print("spatial downsampling is driving DeCoF's response.") | |
| print("=" * 70) |