← back

Frame-Aware Corrupt for Drift Simulation

#459 · Computer Vision · Medium

⊣ Solve on deep-ml.com

Problem

Implement a frame-aware corruption function for drift simulation in video diffusion models. Given a batch of video frames, add noise that increases over the temporal dimension to simulate temporal drift. The noise level for each frame should follow a specified schedule.

Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
import random, math

def frame_aware_corrupt(
    frames: list[list[float]], noise_schedule: list[float], seed: int = 42
) -> list[list[float]]:
    rng = random.Random(seed)
    T = len(frames)
    corrupted = [row[:] for row in frames]
    for t in range(T):
        nl = noise_schedule[t]
        scale = math.sqrt(1 - nl ** 2)
        corrupted[t] = [scale * v + nl * rng.gauss(0, 1) for v in frames[t]]
    return corrupted

Explanation

  1. Each frame t gets a noise level sigma_t from the schedule. Later frames typically get higher noise to simulate accumulated drift.
  2. The corruption follows the standard diffusion interpolation: x_corrupted = sqrt(1 - sigma^2) * x_clean + sigma * noise, which preserves the signal variance.
  3. By using increasing sigma values across the temporal axis, we simulate the model's decreasing certainty about frames further from the conditioning anchor.

Complexity

  • Time: O(T H W * C) where T is frames and H, W, C are spatial/channel dimensions
  • Space: O(T H W * C) for the corrupted output and noise