Upload folder using huggingface_hub
Browse files- __pycache__/predict.cpython-311.pyc +0 -0
- predict.py +17 -22
__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
|
@@ -135,9 +135,6 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 135 |
last_frame = frames_norm[-1]
|
| 136 |
last_frame_t = np.transpose(last_frame, (2, 0, 1))[np.newaxis]
|
| 137 |
|
| 138 |
-
# Per-channel means from last 4 context frames for color correction
|
| 139 |
-
ctx_channel_means = frames_norm[-4:].mean(axis=(0, 1, 2)) # [3]
|
| 140 |
-
|
| 141 |
if game == "pong":
|
| 142 |
# Pong: AR+direct ensemble, float32 caching, no TTA
|
| 143 |
if ens.direct_cache is not None and n > CONTEXT_FRAMES and ens.cache_step < PRED_FRAMES:
|
|
@@ -206,6 +203,10 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 206 |
direct_pred = (direct_orig + direct_flipped) / 2.0
|
| 207 |
|
| 208 |
# Multi-run AR with noise diversity
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
all_ar_runs = []
|
| 210 |
for noise_std in [0.0, 1.0/255.0, 2.0/255.0]:
|
| 211 |
ar_preds_run = []
|
|
@@ -221,14 +222,22 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 221 |
ar_flip_back = torch.flip(ar_flip, dims=[3])
|
| 222 |
ar_frame = (ar_orig + ar_flip_back) / 2.0
|
| 223 |
ar_preds_run.append(ar_frame)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
ctx_frames = ctx.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
|
| 225 |
-
ctx_frames = torch.cat([ctx_frames[:, 1:],
|
| 226 |
ctx = ctx_frames.reshape(1, -1, 64, 64)
|
| 227 |
-
last_t =
|
| 228 |
ctx_flip_frames = ctx_flip.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
|
| 229 |
-
ctx_flip_frames = torch.cat([ctx_flip_frames[:, 1:],
|
| 230 |
ctx_flip = ctx_flip_frames.reshape(1, -1, 64, 64)
|
| 231 |
-
last_f =
|
| 232 |
all_ar_runs.append(torch.stack(ar_preds_run, dim=1))
|
| 233 |
|
| 234 |
ar_pred = sum(all_ar_runs) / len(all_ar_runs)
|
|
@@ -242,14 +251,7 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 242 |
predicted_np = predicted[0].cpu().numpy()
|
| 243 |
ens.direct_cache = []
|
| 244 |
for i in range(PRED_FRAMES):
|
| 245 |
-
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
| 246 |
-
# Color correction: nudge channel means toward context
|
| 247 |
-
pred_means = frame.mean(axis=(0, 1)) # [3]
|
| 248 |
-
diff = ctx_channel_means - pred_means
|
| 249 |
-
thresh = 3.0 / 255.0
|
| 250 |
-
correction = np.where(np.abs(diff) > thresh, 0.1 * diff, 0.0)
|
| 251 |
-
frame = frame + correction[np.newaxis, np.newaxis, :]
|
| 252 |
-
frame = frame.clip(0, 1)
|
| 253 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 254 |
ens.direct_cache.append(frame)
|
| 255 |
|
|
@@ -282,13 +284,6 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 282 |
ens.direct_cache = []
|
| 283 |
for i in range(PRED_FRAMES):
|
| 284 |
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
| 285 |
-
# Color correction
|
| 286 |
-
pred_means = frame.mean(axis=(0, 1))
|
| 287 |
-
diff = ctx_channel_means - pred_means
|
| 288 |
-
thresh = 3.0 / 255.0
|
| 289 |
-
correction = np.where(np.abs(diff) > thresh, 0.1 * diff, 0.0)
|
| 290 |
-
frame = frame + correction[np.newaxis, np.newaxis, :]
|
| 291 |
-
frame = frame.clip(0, 1)
|
| 292 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 293 |
ens.direct_cache.append(frame)
|
| 294 |
|
|
|
|
| 135 |
last_frame = frames_norm[-1]
|
| 136 |
last_frame_t = np.transpose(last_frame, (2, 0, 1))[np.newaxis]
|
| 137 |
|
|
|
|
|
|
|
|
|
|
| 138 |
if game == "pong":
|
| 139 |
# Pong: AR+direct ensemble, float32 caching, no TTA
|
| 140 |
if ens.direct_cache is not None and n > CONTEXT_FRAMES and ens.cache_step < PRED_FRAMES:
|
|
|
|
| 203 |
direct_pred = (direct_orig + direct_flipped) / 2.0
|
| 204 |
|
| 205 |
# Multi-run AR with noise diversity
|
| 206 |
+
# For no-noise run: feed blended AR+direct as context
|
| 207 |
+
direct_frames = direct_pred.reshape(1, PRED_FRAMES, 3, 64, 64)
|
| 208 |
+
direct_frames_flip = torch.flip(direct_frames, dims=[4])
|
| 209 |
+
|
| 210 |
all_ar_runs = []
|
| 211 |
for noise_std in [0.0, 1.0/255.0, 2.0/255.0]:
|
| 212 |
ar_preds_run = []
|
|
|
|
| 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 |
+
# For no-noise run: blend with direct before feeding back
|
| 226 |
+
if noise_std == 0:
|
| 227 |
+
w = 0.65 - (step / (PRED_FRAMES - 1)) * 0.3
|
| 228 |
+
feedback_orig = w * ar_orig + (1.0 - w) * direct_frames[:, step]
|
| 229 |
+
feedback_flip = w * ar_flip + (1.0 - w) * direct_frames_flip[:, step]
|
| 230 |
+
else:
|
| 231 |
+
feedback_orig = ar_orig
|
| 232 |
+
feedback_flip = ar_flip
|
| 233 |
ctx_frames = ctx.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
|
| 234 |
+
ctx_frames = torch.cat([ctx_frames[:, 1:], feedback_orig.unsqueeze(1)], dim=1)
|
| 235 |
ctx = ctx_frames.reshape(1, -1, 64, 64)
|
| 236 |
+
last_t = feedback_orig
|
| 237 |
ctx_flip_frames = ctx_flip.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
|
| 238 |
+
ctx_flip_frames = torch.cat([ctx_flip_frames[:, 1:], feedback_flip.unsqueeze(1)], dim=1)
|
| 239 |
ctx_flip = ctx_flip_frames.reshape(1, -1, 64, 64)
|
| 240 |
+
last_f = feedback_flip
|
| 241 |
all_ar_runs.append(torch.stack(ar_preds_run, dim=1))
|
| 242 |
|
| 243 |
ar_pred = sum(all_ar_runs) / len(all_ar_runs)
|
|
|
|
| 251 |
predicted_np = predicted[0].cpu().numpy()
|
| 252 |
ens.direct_cache = []
|
| 253 |
for i in range(PRED_FRAMES):
|
| 254 |
+
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 256 |
ens.direct_cache.append(frame)
|
| 257 |
|
|
|
|
| 284 |
ens.direct_cache = []
|
| 285 |
for i in range(PRED_FRAMES):
|
| 286 |
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 288 |
ens.direct_cache.append(frame)
|
| 289 |
|