Upload folder using huggingface_hub
Browse files- __pycache__/predict.cpython-311.pyc +0 -0
- predict.py +18 -8
__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,6 +135,9 @@ 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 |
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:
|
|
@@ -236,17 +239,17 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 236 |
direct_weight = 1.0 - ar_weight
|
| 237 |
predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
|
| 238 |
|
| 239 |
-
# Motion correction from context
|
| 240 |
-
ctx_reshaped = context_tensor.reshape(1, CONTEXT_FRAMES, 3, 64, 64)
|
| 241 |
-
motion = ctx_reshaped[:, -1] - ctx_reshaped[:, -2] # [1, 3, 64, 64]
|
| 242 |
-
for step in range(PRED_FRAMES):
|
| 243 |
-
alpha = 0.05 * (step + 1)
|
| 244 |
-
predicted[:, step] = torch.clamp(predicted[:, step] + alpha * motion, 0, 1)
|
| 245 |
-
|
| 246 |
predicted_np = predicted[0].cpu().numpy()
|
| 247 |
ens.direct_cache = []
|
| 248 |
for i in range(PRED_FRAMES):
|
| 249 |
-
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 251 |
ens.direct_cache.append(frame)
|
| 252 |
|
|
@@ -279,6 +282,13 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 279 |
ens.direct_cache = []
|
| 280 |
for i in range(PRED_FRAMES):
|
| 281 |
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 283 |
ens.direct_cache.append(frame)
|
| 284 |
|
|
|
|
| 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:
|
|
|
|
| 239 |
direct_weight = 1.0 - ar_weight
|
| 240 |
predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)) # [64,64,3]
|
| 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 |
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 |
|