Upload folder using huggingface_hub
Browse files- __pycache__/predict.cpython-311.pyc +0 -0
- predict.py +45 -30
__pycache__/predict.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/predict.cpython-311.pyc and b/__pycache__/predict.cpython-311.pyc differ
|
|
|
predict.py
CHANGED
|
@@ -202,43 +202,58 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 202 |
direct_flipped = torch.flip(direct_flipped, dims=[4])
|
| 203 |
direct_pred = (direct_orig + direct_flipped) / 2.0
|
| 204 |
|
| 205 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
all_ar_runs = []
|
| 207 |
for noise_std in [0.0, 1.0/255.0, 2.0/255.0]:
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
ctx_frames = torch.cat([ctx_frames[:, 1:], ar_orig.unsqueeze(1)], dim=1)
|
| 223 |
-
ctx = ctx_frames.reshape(1, -1, 64, 64)
|
| 224 |
-
last_t = ar_orig
|
| 225 |
-
ctx_flip_frames = ctx_flip.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
|
| 226 |
-
ctx_flip_frames = torch.cat([ctx_flip_frames[:, 1:], ar_flip.unsqueeze(1)], dim=1)
|
| 227 |
-
ctx_flip = ctx_flip_frames.reshape(1, -1, 64, 64)
|
| 228 |
-
last_f = ar_flip
|
| 229 |
-
all_ar_runs.append(torch.stack(ar_preds_run, dim=1))
|
| 230 |
|
| 231 |
ar_pred = sum(all_ar_runs) / len(all_ar_runs)
|
| 232 |
|
| 233 |
-
# Agreement-based blending: trust AR where models agree
|
| 234 |
predicted = torch.zeros_like(direct_pred)
|
| 235 |
-
low_thresh = 10.0 / 255.0
|
| 236 |
-
high_thresh = 50.0 / 255.0
|
| 237 |
for step in range(PRED_FRAMES):
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
predicted[:, step] = ar_w * ar_pred[:, step] + (1.0 - ar_w) * direct_pred[:, step]
|
| 242 |
|
| 243 |
predicted_np = predicted[0].cpu().numpy()
|
| 244 |
ens.direct_cache = []
|
|
|
|
| 202 |
direct_flipped = torch.flip(direct_flipped, dims=[4])
|
| 203 |
direct_pred = (direct_orig + direct_flipped) / 2.0
|
| 204 |
|
| 205 |
+
# Shift helpers using roll + edge replication
|
| 206 |
+
def shift_right(t):
|
| 207 |
+
shifted = torch.roll(t, 1, dims=-1)
|
| 208 |
+
shifted[:, :, :, 0] = shifted[:, :, :, 1]
|
| 209 |
+
return shifted
|
| 210 |
+
def shift_left(t):
|
| 211 |
+
shifted = torch.roll(t, -1, dims=-1)
|
| 212 |
+
shifted[:, :, :, -1] = shifted[:, :, :, -2]
|
| 213 |
+
return shifted
|
| 214 |
+
def unshift_right(t):
|
| 215 |
+
return shift_left(t)
|
| 216 |
+
def unshift_left(t):
|
| 217 |
+
return shift_right(t)
|
| 218 |
+
|
| 219 |
+
# Build augmentation list: (context_aug, last_aug, undo_fn)
|
| 220 |
+
ctx_sr = shift_right(context_tensor)
|
| 221 |
+
last_sr = shift_right(last_tensor)
|
| 222 |
+
ctx_sl = shift_left(context_tensor)
|
| 223 |
+
last_sl = shift_left(last_tensor)
|
| 224 |
+
|
| 225 |
+
augmentations = [
|
| 226 |
+
(context_tensor, last_tensor, lambda x: x),
|
| 227 |
+
(context_flipped, last_flipped, lambda x: torch.flip(x, dims=[3])),
|
| 228 |
+
(ctx_sr, last_sr, unshift_right),
|
| 229 |
+
(ctx_sl, last_sl, unshift_left),
|
| 230 |
+
]
|
| 231 |
+
|
| 232 |
+
# Multi-run AR with noise diversity x augmentations
|
| 233 |
all_ar_runs = []
|
| 234 |
for noise_std in [0.0, 1.0/255.0, 2.0/255.0]:
|
| 235 |
+
for ctx_aug, last_aug, undo_fn in augmentations:
|
| 236 |
+
ar_preds_run = []
|
| 237 |
+
ctx = ctx_aug.clone()
|
| 238 |
+
last_t = last_aug.clone()
|
| 239 |
+
for step in range(PRED_FRAMES):
|
| 240 |
+
ctx_in = ctx if noise_std == 0 else torch.clamp(ctx + torch.randn_like(ctx) * noise_std, 0, 1)
|
| 241 |
+
ar_out = _predict_ar_frame(ens.sonic_ar, ctx_in, last_t)
|
| 242 |
+
ar_frame = undo_fn(ar_out)
|
| 243 |
+
ar_preds_run.append(ar_frame)
|
| 244 |
+
ctx_frames = ctx.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
|
| 245 |
+
ctx_frames = torch.cat([ctx_frames[:, 1:], ar_out.unsqueeze(1)], dim=1)
|
| 246 |
+
ctx = ctx_frames.reshape(1, -1, 64, 64)
|
| 247 |
+
last_t = ar_out
|
| 248 |
+
all_ar_runs.append(torch.stack(ar_preds_run, dim=1))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
ar_pred = sum(all_ar_runs) / len(all_ar_runs)
|
| 251 |
|
|
|
|
| 252 |
predicted = torch.zeros_like(direct_pred)
|
|
|
|
|
|
|
| 253 |
for step in range(PRED_FRAMES):
|
| 254 |
+
ar_weight = 0.65 - (step / (PRED_FRAMES - 1)) * 0.3
|
| 255 |
+
direct_weight = 1.0 - ar_weight
|
| 256 |
+
predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
|
|
|
|
| 257 |
|
| 258 |
predicted_np = predicted[0].cpu().numpy()
|
| 259 |
ens.direct_cache = []
|