Upload folder using huggingface_hub
Browse files- __pycache__/predict.cpython-311.pyc +0 -0
- predict.py +13 -9
__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
|
@@ -191,6 +191,16 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 191 |
return result
|
| 192 |
|
| 193 |
ens.reset_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
with torch.no_grad():
|
| 195 |
context_tensor = torch.from_numpy(context).to(DEVICE)
|
| 196 |
last_tensor = torch.from_numpy(last_frame_t).to(DEVICE)
|
|
@@ -229,18 +239,12 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 229 |
all_ar_runs.append(torch.stack(ar_preds_run, dim=1))
|
| 230 |
|
| 231 |
ar_pred = sum(all_ar_runs) / len(all_ar_runs)
|
| 232 |
-
# Compute per-pixel variance across runs for uncertainty
|
| 233 |
-
ar_stack = torch.stack(all_ar_runs, dim=0) # [3, 1, 8, 3, 64, 64]
|
| 234 |
-
ar_var = ar_stack.var(dim=0) # [1, 8, 3, 64, 64]
|
| 235 |
|
| 236 |
predicted = torch.zeros_like(direct_pred)
|
| 237 |
for step in range(PRED_FRAMES):
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
ar_weight_map = base_ar_weight * (1 - uncertainty)
|
| 242 |
-
direct_weight_map = 1.0 - ar_weight_map
|
| 243 |
-
predicted[:, step] = ar_weight_map * ar_pred[:, step] + direct_weight_map * direct_pred[:, step]
|
| 244 |
|
| 245 |
predicted_np = predicted[0].cpu().numpy()
|
| 246 |
ens.direct_cache = []
|
|
|
|
| 191 |
return result
|
| 192 |
|
| 193 |
ens.reset_cache()
|
| 194 |
+
|
| 195 |
+
# Detect near-static scene: if last two context frames nearly identical, use copy
|
| 196 |
+
last_two_diff = np.abs(frames[-2].astype(np.float32) - frames[-1].astype(np.float32)).mean()
|
| 197 |
+
if last_two_diff < 3.0 / 255.0:
|
| 198 |
+
last_ctx_uint8 = (last_frame * 255).clip(0, 255).astype(np.uint8)
|
| 199 |
+
ens.direct_cache = [last_ctx_uint8.copy() for _ in range(PRED_FRAMES)]
|
| 200 |
+
result = ens.direct_cache[ens.cache_step]
|
| 201 |
+
ens.cache_step += 1
|
| 202 |
+
return result
|
| 203 |
+
|
| 204 |
with torch.no_grad():
|
| 205 |
context_tensor = torch.from_numpy(context).to(DEVICE)
|
| 206 |
last_tensor = torch.from_numpy(last_frame_t).to(DEVICE)
|
|
|
|
| 239 |
all_ar_runs.append(torch.stack(ar_preds_run, dim=1))
|
| 240 |
|
| 241 |
ar_pred = sum(all_ar_runs) / len(all_ar_runs)
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
predicted = torch.zeros_like(direct_pred)
|
| 244 |
for step in range(PRED_FRAMES):
|
| 245 |
+
ar_weight = 0.65 - (step / (PRED_FRAMES - 1)) * 0.3
|
| 246 |
+
direct_weight = 1.0 - ar_weight
|
| 247 |
+
predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
predicted_np = predicted[0].cpu().numpy()
|
| 250 |
ens.direct_cache = []
|