Upload folder using huggingface_hub
Browse files- __pycache__/predict.cpython-311.pyc +0 -0
- predict.py +18 -19
__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,12 +202,9 @@ 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 |
-
# Multi-run AR with noise diversity,
|
| 206 |
-
# Get direct model's step 1 prediction for seeding AR context
|
| 207 |
-
direct_step1 = direct_pred[:, 0] # [1, 3, 64, 64]
|
| 208 |
-
direct_step1_flip = torch.flip(direct_step1, dims=[3])
|
| 209 |
-
|
| 210 |
all_ar_runs = []
|
|
|
|
| 211 |
for noise_std in [0.0, 1.0/255.0, 2.0/255.0]:
|
| 212 |
ar_preds_run = []
|
| 213 |
ctx = context_tensor.clone()
|
|
@@ -220,32 +217,34 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 220 |
ar_orig = _predict_ar_frame(ens.sonic_ar, ctx_in, last_t)
|
| 221 |
ar_flip = _predict_ar_frame(ens.sonic_ar, ctx_flip_in, last_f)
|
| 222 |
ar_flip_back = torch.flip(ar_flip, dims=[3])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
ar_frame = (ar_orig + ar_flip_back) / 2.0
|
| 224 |
ar_preds_run.append(ar_frame)
|
| 225 |
-
|
| 226 |
-
# For step 0: use direct model's prediction as context seed
|
| 227 |
-
if step == 0:
|
| 228 |
-
feed_orig = direct_step1
|
| 229 |
-
feed_flip = direct_step1_flip
|
| 230 |
-
else:
|
| 231 |
-
feed_orig = ar_orig
|
| 232 |
-
feed_flip = ar_flip
|
| 233 |
-
|
| 234 |
ctx_frames = ctx.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
|
| 235 |
-
ctx_frames = torch.cat([ctx_frames[:, 1:],
|
| 236 |
ctx = ctx_frames.reshape(1, -1, 64, 64)
|
| 237 |
-
last_t =
|
| 238 |
ctx_flip_frames = ctx_flip.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
|
| 239 |
-
ctx_flip_frames = torch.cat([ctx_flip_frames[:, 1:],
|
| 240 |
ctx_flip = ctx_flip_frames.reshape(1, -1, 64, 64)
|
| 241 |
-
last_f =
|
| 242 |
all_ar_runs.append(torch.stack(ar_preds_run, dim=1))
|
| 243 |
|
| 244 |
ar_pred = sum(all_ar_runs) / len(all_ar_runs)
|
| 245 |
|
| 246 |
predicted = torch.zeros_like(direct_pred)
|
| 247 |
for step in range(PRED_FRAMES):
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
direct_weight = 1.0 - ar_weight
|
| 250 |
predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
|
| 251 |
|
|
|
|
| 202 |
direct_flipped = torch.flip(direct_flipped, dims=[4])
|
| 203 |
direct_pred = (direct_orig + direct_flipped) / 2.0
|
| 204 |
|
| 205 |
+
# Multi-run AR with noise diversity, track TTA disagreement
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
all_ar_runs = []
|
| 207 |
+
tta_disagreements = [] # per-step disagreement from clean run
|
| 208 |
for noise_std in [0.0, 1.0/255.0, 2.0/255.0]:
|
| 209 |
ar_preds_run = []
|
| 210 |
ctx = context_tensor.clone()
|
|
|
|
| 217 |
ar_orig = _predict_ar_frame(ens.sonic_ar, ctx_in, last_t)
|
| 218 |
ar_flip = _predict_ar_frame(ens.sonic_ar, ctx_flip_in, last_f)
|
| 219 |
ar_flip_back = torch.flip(ar_flip, dims=[3])
|
| 220 |
+
# Track TTA disagreement for clean run
|
| 221 |
+
if noise_std == 0:
|
| 222 |
+
disagreement = torch.abs(ar_orig - ar_flip_back).mean().item()
|
| 223 |
+
tta_disagreements.append(disagreement)
|
| 224 |
ar_frame = (ar_orig + ar_flip_back) / 2.0
|
| 225 |
ar_preds_run.append(ar_frame)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
ctx_frames = ctx.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
|
| 227 |
+
ctx_frames = torch.cat([ctx_frames[:, 1:], ar_orig.unsqueeze(1)], dim=1)
|
| 228 |
ctx = ctx_frames.reshape(1, -1, 64, 64)
|
| 229 |
+
last_t = ar_orig
|
| 230 |
ctx_flip_frames = ctx_flip.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
|
| 231 |
+
ctx_flip_frames = torch.cat([ctx_flip_frames[:, 1:], ar_flip.unsqueeze(1)], dim=1)
|
| 232 |
ctx_flip = ctx_flip_frames.reshape(1, -1, 64, 64)
|
| 233 |
+
last_f = ar_flip
|
| 234 |
all_ar_runs.append(torch.stack(ar_preds_run, dim=1))
|
| 235 |
|
| 236 |
ar_pred = sum(all_ar_runs) / len(all_ar_runs)
|
| 237 |
|
| 238 |
predicted = torch.zeros_like(direct_pred)
|
| 239 |
for step in range(PRED_FRAMES):
|
| 240 |
+
base_ar_weight = 0.65 - (step / (PRED_FRAMES - 1)) * 0.3
|
| 241 |
+
# Adjust based on TTA disagreement
|
| 242 |
+
disagreement = tta_disagreements[step]
|
| 243 |
+
if disagreement < 5.0 / 255.0:
|
| 244 |
+
base_ar_weight += 0.1 # AR confident
|
| 245 |
+
elif disagreement > 15.0 / 255.0:
|
| 246 |
+
base_ar_weight -= 0.1 # AR uncertain
|
| 247 |
+
ar_weight = max(0.15, min(0.85, base_ar_weight))
|
| 248 |
direct_weight = 1.0 - ar_weight
|
| 249 |
predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
|
| 250 |
|