Upload folder using huggingface_hub
Browse files- __pycache__/predict.cpython-311.pyc +0 -0
- predict.py +1 -16
__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
|
@@ -106,18 +106,6 @@ def load_model(model_dir: str):
|
|
| 106 |
return ens
|
| 107 |
|
| 108 |
|
| 109 |
-
def _unsharp_mask(frames_tensor, alpha=0.15):
|
| 110 |
-
"""Apply unsharp mask sharpening. frames_tensor: [1, N, 3, 64, 64]"""
|
| 111 |
-
import torch.nn.functional as F
|
| 112 |
-
kernel = torch.tensor([[1, 2, 1], [2, 4, 2], [1, 2, 1]], dtype=frames_tensor.dtype, device=frames_tensor.device).float() / 16.0
|
| 113 |
-
kernel = kernel.unsqueeze(0).unsqueeze(0).expand(3, 1, 3, 3)
|
| 114 |
-
b, n, c, h, w = frames_tensor.shape
|
| 115 |
-
x = frames_tensor.reshape(b * n, c, h, w)
|
| 116 |
-
blurred = F.conv2d(x, kernel, padding=1, groups=3)
|
| 117 |
-
sharpened = x + alpha * (x - blurred)
|
| 118 |
-
return torch.clamp(sharpened.reshape(b, n, c, h, w), 0, 1)
|
| 119 |
-
|
| 120 |
-
|
| 121 |
def _predict_8frames_direct(model, context_tensor, last_tensor):
|
| 122 |
output = model(context_tensor)
|
| 123 |
residuals = output.reshape(1, PRED_FRAMES, 3, 64, 64)
|
|
@@ -216,7 +204,7 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 216 |
|
| 217 |
# Multi-run AR with noise diversity
|
| 218 |
all_ar_runs = []
|
| 219 |
-
for noise_std in [0.0, 1.0/255.0,
|
| 220 |
ar_preds_run = []
|
| 221 |
ctx = context_tensor.clone()
|
| 222 |
ctx_flip = context_flipped.clone()
|
|
@@ -248,8 +236,6 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 248 |
direct_weight = 1.0 - ar_weight
|
| 249 |
predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
|
| 250 |
|
| 251 |
-
predicted = _unsharp_mask(predicted, alpha=0.15)
|
| 252 |
-
|
| 253 |
predicted_np = predicted[0].cpu().numpy()
|
| 254 |
ens.direct_cache = []
|
| 255 |
for i in range(PRED_FRAMES):
|
|
@@ -281,7 +267,6 @@ def predict_next_frame(ens, context_frames: np.ndarray) -> np.ndarray:
|
|
| 281 |
predicted_flipped = _predict_8frames_direct(ens.models["pole_position"], context_flipped, last_flipped)
|
| 282 |
predicted_flipped = torch.flip(predicted_flipped, dims=[4])
|
| 283 |
predicted = (predicted_orig + predicted_flipped) / 2.0
|
| 284 |
-
predicted = _unsharp_mask(predicted, alpha=0.15)
|
| 285 |
|
| 286 |
predicted_np = predicted[0].cpu().numpy()
|
| 287 |
ens.direct_cache = []
|
|
|
|
| 106 |
return ens
|
| 107 |
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
def _predict_8frames_direct(model, context_tensor, last_tensor):
|
| 110 |
output = model(context_tensor)
|
| 111 |
residuals = output.reshape(1, PRED_FRAMES, 3, 64, 64)
|
|
|
|
| 204 |
|
| 205 |
# Multi-run AR with noise diversity
|
| 206 |
all_ar_runs = []
|
| 207 |
+
for noise_std in [0.0, 0.5/255.0, 1.0/255.0, 1.5/255.0]:
|
| 208 |
ar_preds_run = []
|
| 209 |
ctx = context_tensor.clone()
|
| 210 |
ctx_flip = context_flipped.clone()
|
|
|
|
| 236 |
direct_weight = 1.0 - ar_weight
|
| 237 |
predicted[:, step] = ar_weight * ar_pred[:, step] + direct_weight * direct_pred[:, step]
|
| 238 |
|
|
|
|
|
|
|
| 239 |
predicted_np = predicted[0].cpu().numpy()
|
| 240 |
ens.direct_cache = []
|
| 241 |
for i in range(PRED_FRAMES):
|
|
|
|
| 267 |
predicted_flipped = _predict_8frames_direct(ens.models["pole_position"], context_flipped, last_flipped)
|
| 268 |
predicted_flipped = torch.flip(predicted_flipped, dims=[4])
|
| 269 |
predicted = (predicted_orig + predicted_flipped) / 2.0
|
|
|
|
| 270 |
|
| 271 |
predicted_np = predicted[0].cpu().numpy()
|
| 272 |
ens.direct_cache = []
|