Upload folder using huggingface_hub
Browse files- __pycache__/predict.cpython-311.pyc +0 -0
- predict.py +11 -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
|
@@ -135,13 +135,10 @@ 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 |
-
#
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
# Static mask: 1.0 for static pixels (low variance), 0.0 for dynamic
|
| 143 |
-
var_thresh = 5.0 / (255.0 * 255.0) # variance in [0,1] scale (5/255^2)
|
| 144 |
-
static_mask = (pixel_var_mean < var_thresh).astype(np.float32) # [64, 64]
|
| 145 |
|
| 146 |
if game == "pong":
|
| 147 |
# Pong: AR+direct ensemble, float32 caching, no TTA
|
|
@@ -181,10 +178,7 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 181 |
predicted_np = predicted[0].cpu().numpy()
|
| 182 |
ens.direct_cache = []
|
| 183 |
for i in range(PRED_FRAMES):
|
| 184 |
-
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
| 185 |
-
# Apply motion mask: static pixels blend 80% context / 20% prediction
|
| 186 |
-
mask_3d = static_mask[:, :, np.newaxis] # [64, 64, 1]
|
| 187 |
-
frame = frame * (1.0 - 0.8 * mask_3d) + last_frame * 0.8 * mask_3d
|
| 188 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 189 |
ens.direct_cache.append(frame)
|
| 190 |
|
|
@@ -250,10 +244,9 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 250 |
predicted_np = predicted[0].cpu().numpy()
|
| 251 |
ens.direct_cache = []
|
| 252 |
for i in range(PRED_FRAMES):
|
| 253 |
-
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
| 254 |
-
#
|
| 255 |
-
|
| 256 |
-
frame = frame * (1.0 - 0.8 * mask_3d) + last_frame * 0.8 * mask_3d
|
| 257 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 258 |
ens.direct_cache.append(frame)
|
| 259 |
|
|
@@ -285,10 +278,9 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 285 |
predicted_np = predicted[0].cpu().numpy()
|
| 286 |
ens.direct_cache = []
|
| 287 |
for i in range(PRED_FRAMES):
|
| 288 |
-
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
| 289 |
-
#
|
| 290 |
-
|
| 291 |
-
frame = frame * (1.0 - 0.8 * mask_3d) + last_frame * 0.8 * mask_3d
|
| 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 |
+
# 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
|
|
|
|
| 178 |
predicted_np = predicted[0].cpu().numpy()
|
| 179 |
ens.direct_cache = []
|
| 180 |
for i in range(PRED_FRAMES):
|
| 181 |
+
frame = np.transpose(predicted_np[i], (1, 2, 0))
|
|
|
|
|
|
|
|
|
|
| 182 |
frame = (frame * 255).clip(0, 255).astype(np.uint8)
|
| 183 |
ens.direct_cache.append(frame)
|
| 184 |
|
|
|
|
| 244 |
predicted_np = predicted[0].cpu().numpy()
|
| 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 |
|
|
|
|
| 278 |
predicted_np = predicted[0].cpu().numpy()
|
| 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 |
|