Upload folder using huggingface_hub
Browse files- __pycache__/predict.cpython-311.pyc +0 -0
- predict.py +3 -10
__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,11 +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 |
-
# Static background mask (for Sonic/PP only)
|
| 139 |
-
pixel_var = np.var(frames_t, axis=0).mean(axis=0) # [64, 64]
|
| 140 |
-
var_thresh = 2.0 / (255.0 * 255.0)
|
| 141 |
-
static_mask = (pixel_var < var_thresh).astype(np.float32)[:, :, np.newaxis] # [64, 64, 1]
|
| 142 |
-
|
| 143 |
if game == "pong":
|
| 144 |
# Pong: AR+direct ensemble, float32 caching, no TTA
|
| 145 |
if ens.direct_cache is not None and n > CONTEXT_FRAMES and ens.cache_step < PRED_FRAMES:
|
|
@@ -169,9 +164,11 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 169 |
|
| 170 |
ar_pred = torch.stack(ar_preds, dim=1)
|
| 171 |
|
|
|
|
|
|
|
| 172 |
predicted = torch.zeros_like(direct_pred)
|
| 173 |
for step in range(PRED_FRAMES):
|
| 174 |
-
ar_weight =
|
| 175 |
direct_weight = 1.0 - ar_weight
|
| 176 |
predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
|
| 177 |
|
|
@@ -245,8 +242,6 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 245 |
ens.direct_cache = []
|
| 246 |
for i in range(PRED_FRAMES):
|
| 247 |
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
| 248 |
-
# Mild static mask: 10% context blend on static pixels
|
| 249 |
-
frame = frame * (1.0 - 0.1 * static_mask) + last_frame * 0.1 * static_mask
|
| 250 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 251 |
ens.direct_cache.append(frame)
|
| 252 |
|
|
@@ -279,8 +274,6 @@ 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 |
-
# Mild static mask: 10% context blend on static pixels
|
| 283 |
-
frame = frame * (1.0 - 0.1 * static_mask) + last_frame * 0.1 * static_mask
|
| 284 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 285 |
ens.direct_cache.append(frame)
|
| 286 |
|
|
|
|
| 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:
|
|
|
|
| 164 |
|
| 165 |
ar_pred = torch.stack(ar_preds, dim=1)
|
| 166 |
|
| 167 |
+
# U-shaped AR weights: less AR early/late, more in middle
|
| 168 |
+
pong_ar_weights = [0.70, 0.70, 0.85, 0.85, 0.85, 0.60, 0.60, 0.60]
|
| 169 |
predicted = torch.zeros_like(direct_pred)
|
| 170 |
for step in range(PRED_FRAMES):
|
| 171 |
+
ar_weight = pong_ar_weights[step]
|
| 172 |
direct_weight = 1.0 - ar_weight
|
| 173 |
predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
|
| 174 |
|
|
|
|
| 242 |
ens.direct_cache = []
|
| 243 |
for i in range(PRED_FRAMES):
|
| 244 |
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
|
|
|
|
|
|
| 245 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 246 |
ens.direct_cache.append(frame)
|
| 247 |
|
|
|
|
| 274 |
ens.direct_cache = []
|
| 275 |
for i in range(PRED_FRAMES):
|
| 276 |
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
|
|
|
|
|
|
| 277 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 278 |
ens.direct_cache.append(frame)
|
| 279 |
|